我尝试在本地计算机上运行与以下代码完全相同的代码(在具有注意的神经机器翻译上): https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/nmt_with_attention/nmt_with_attention.ipynb
训练模型并尝试保存检查点时出现以下错误:
Epoch 1 Batch 0 Loss 0.3238
---------------------------------------------------------------------------
_FallbackException Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_io_ops.py in save_v2(prefix, tensor_names, shape_and_slices, tensors, name)
1809 _ctx._post_execution_callbacks, prefix, tensor_names,
-> 1810 shape_and_slices, tensors)
1811 return _result
_FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-28-bb3738bfb3d8> in <module>()
43 # saving (checkpoint) the model every 2 epochs
44 if epoch % 2 == 0:
---> 45 checkpoint.save(file_prefix = checkpoint_prefix)
46
47 print('Epoch {} Loss {:.4f}'.format(epoch + 1,
C:\Anaconda3\lib\site-packages\tensorflow\python\training\checkpointable\util.py in save(self, file_prefix, session)
1485 file_prefix=file_prefix,
1486 checkpoint_number=self.save_counter,
-> 1487 session=session)
1488
1489 def restore(self, save_path):
C:\Anaconda3\lib\site-packages\tensorflow\python\training\checkpointable\util.py in save(self, file_prefix, checkpoint_number, session)
1184 save_path=file_prefix,
1185 write_meta_graph=False,
-> 1186 global_step=checkpoint_number)
1187 return save_path
1188
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in save(self, sess, save_path, global_step, latest_filename, meta_graph_suffix, write_meta_graph, write_state, strip_default_attrs)
1613 if context.executing_eagerly():
1614 self._build_eager(
-> 1615 checkpoint_file, build_save=True, build_restore=False)
1616 model_checkpoint_path = self.saver_def.save_tensor_name
1617 else:
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in _build_eager(self, checkpoint_path, build_save, build_restore)
1295 def _build_eager(self, checkpoint_path, build_save, build_restore):
1296 self._build(
-> 1297 checkpoint_path, build_save=build_save, build_restore=build_restore)
1298
1299 def _build(self, checkpoint_path, build_save, build_restore):
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in _build(self, checkpoint_path, build_save, build_restore)
1328 restore_sequentially=self._restore_sequentially,
1329 filename=checkpoint_path,
-> 1330 build_save=build_save, build_restore=build_restore)
1331 elif self.saver_def and self._name:
1332 # Since self._name is used as a name_scope by builder(), we are
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in _build_internal(self, names_to_saveables, reshape, sharded, max_to_keep, keep_checkpoint_every_n_hours, name, restore_sequentially, filename, build_save, build_restore)
773 else:
774 if build_save:
--> 775 save_tensor = self._AddSaveOps(filename_tensor, saveables)
776 if build_restore:
777 restore_op = self._AddRestoreOps(filename_tensor, saveables,
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in _AddSaveOps(self, filename_tensor, saveables)
273 A tensor with the filename used to save.
274 """
--> 275 save = self.save_op(filename_tensor, saveables)
276 return control_flow_ops.with_dependencies([save], filename_tensor)
277
C:\Anaconda3\lib\site-packages\tensorflow\python\training\saver.py in save_op(self, filename_tensor, saveables)
191 # of a V2 checkpoint: e.g. "/fs/train/ckpt-<step>/tmp/worker<i>-<step>".
192 return io_ops.save_v2(filename_tensor, tensor_names, tensor_slices,
--> 193 tensors)
194 else:
195 raise RuntimeError("Unexpected write_version: " + self._write_version)
C:\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_io_ops.py in save_v2(prefix, tensor_names, shape_and_slices, tensors, name)
1813 return save_v2_eager_fallback(
1814 prefix, tensor_names, shape_and_slices, tensors, name=name,
-> 1815 ctx=_ctx)
1816 except _core._NotOkStatusException as e:
1817 if name is not None:
C:\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_io_ops.py in save_v2_eager_fallback(prefix, tensor_names, shape_and_slices, tensors, name, ctx)
1834 _attrs = ("dtypes", _attr_dtypes)
1835 _result = _execute.execute(b"SaveV2", 0, inputs=_inputs_flat, attrs=_attrs,
-> 1836 ctx=_ctx, name=name)
1837 _result = None
1838 return _result
C:\Anaconda3\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 tensors = pywrap_tensorflow.TFE_Py_Execute(ctx._handle, device_name,
59 op_name, inputs, attrs,
---> 60 num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
TypeError: __init__() missing 2 required positional arguments: 'message' and 'code'