由于某种原因,在Linux上加载保存的模型时出现错误。例如,我在Windows的anaconda环境中的Python 3.5.4和tensorflow 1.10.0上运行了它,并且可以运行,但是随后我在python和tensorflow的相同版本上以及在Linux mint的相同的conda版本上运行了它,工作!它给了我这个错误信息:
File "<ipython-input-16-0689e9fe4aab>",line 4,in <module>
path_to_model
File "/home/anaconda3/envs/test3/lib/python3.5/site-packages/tensorflow/python/saved_model/loader_impl.py",line 212,in load
return loader.load(sess,tags,import_scope,**saver_kwargs)
File "/home/anaconda3/envs/test3/lib/python3.5/site-packages/tensorflow/python/saved_model/loader_impl.py",line 366,in load
self.restore_variables(sess,saver,import_scope)
File "/home/anaconda3/envs/test3/lib/python3.5/site-packages/tensorflow/python/saved_model/loader_impl.py",line 318,in restore_variables
saver.restore(sess,self._variables_path)
File "/home/anaconda3/envs/test3/lib/python3.5/site-packages/tensorflow/python/training/saver.py",line 1717,in restore
+ compat.as_text(save_path))
"ValueError: The passed save_path is not a valid checkpoint: model/a/test1/variables/variables'"
代码:
path_to_model = 'model/a/test1/'
current_graph = tf.Graph()
current_session = tf.Session(graph = current_graph)
curr_meta_graph_definition = tf.saved_model.loader.load(
current_session,[tf.saved_model.tag_constants.SERVING],path_to_model
)
更新:我认为这个问题实际上可能是由于Linux与Windows。我注意到我实际上是在像这样保存模型:
export_path = os.path.join(
tf.compat.as_bytes(self.path),tf.compat.as_bytes(str(iteration_val))
)
self.builder = tf.saved_model.builder.SavedmodelBuilder(export_path)
.....
有人知道tf.compat.as_bytes在Linux和Windows上的行为是否不同?我注意到在Windows中保存的模型无法在Linux中重新加载,但是如果在同一OS中完成,则可以保存和加载模型。