Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow:freeze_graph-Tensorflow.python.framework.errors_impl.DataLossError_Python_Tensorflow - Fatal编程技术网

Tensorflow:freeze_graph-Tensorflow.python.framework.errors_impl.DataLossError

Tensorflow:freeze_graph-Tensorflow.python.framework.errors_impl.DataLossError,python,tensorflow,Python,Tensorflow,我正在使用Tensorflow-1.13创建一个deep-q模型,并使用以下代码保存它 tf.global_variables_initializer() tf.local_variables_initializer() saver = tf.train.Saver() saver.save(tf.get_default_session(), 'deepq_0519') 我得到了以下文件: checkpoint deepq_0519.data-00000-of-00001 deepq_

我正在使用Tensorflow-1.13创建一个deep-q模型,并使用以下代码保存它

tf.global_variables_initializer()    
tf.local_variables_initializer()
saver = tf.train.Saver()
saver.save(tf.get_default_session(), 'deepq_0519')
我得到了以下文件:

checkpoint
deepq_0519.data-00000-of-00001
deepq_0519.index
deepq_0519.meta
我还使用下面的代码保存图形:

tf.train.write_graph(sess.graph_def, '.', 'deepq_0519.pbtxt')
得到:

deepq_0519.pbtxt
最后,我尝试使用保存的文件创建冻结图:

from tensorflow.python.tools import freeze_graph
freeze_graph.freeze_graph('deepq_0519.pbtxt', "", False,
                              'deepq_0519.data-00000-of-00001',"deepq/cond/Merge", 
                              "", "",
                              'deepq_0519_frozen.pb', True, ""
                              )
但是得到了以下错误。知道我做错了什么吗?谢谢

WARNING:tensorflow:From /Users/edamame/workspace/git/my_proj/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:249: FastGFile.__init__ (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
WARNING:tensorflow:From /Users/edamame/workspace/git/my_project/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:127: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
2019-05-19 16:00:06.642801: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-05-19 16:00:06.646182: W tensorflow/core/util/tensor_slice_reader.cc:95] Could not open ./deepq_0519.data-00000-of-00001: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
Traceback (most recent call last):
  File "my_freeze.py", line 6, in <module>
    'deepq_0519_frozen.pb', True, ""
  File "/Users/edamame/workspace/git/my_proj/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py", line 363, in freeze_graph
    checkpoint_version=checkpoint_version)
  File "/Users/edamame/workspace/git/my_proj/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py", line 164, in freeze_graph_with_def_protos
    reader = pywrap_tensorflow.NewCheckpointReader(input_checkpoint)
  File "/Users/edamame/workspace/git/my_proj/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 326, in NewCheckpointReader
    return CheckpointReader(compat.as_bytes(filepattern), status)
  File "/Users/edamame/workspace/git/my_proj/venv/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.DataLossError: Unable to open table file ./deepq_0519.data-00000-of-00001: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
我将代码更改为:

from tensorflow.python.tools import freeze_graph
freeze_graph.freeze_graph('deepq_0519.pbtxt', "", False,
                              'deepq_0519',"deepq/cond/Merge", 
                              "", "",
                              'deepq_0519_frozen.pb', True, ""
                              )
基本上删除了.data-00000-of-00001零件,它就工作了