[英]Problems restoring a saved model in tensorflow, how to debug?
After training a model in tensorflow, it is saved as following: 在tensorflow中训练模型后,将其保存如下:
saver = tf.train.Saver()
saver.save(sess,'myModel/Path/Model_1')
Generating files called: 生成名为:
Now to restore the model after creating a new session, and initializing the tensorflow graph in exactly the same way as originally created, I restore it as follows: 现在要在创建新会话后还原模型,并以与最初创建的方式完全相同的方式初始化tensorflow图,我将其还原如下:
sess = tf.Session()
# Initialize the variables (i.e. assign their default value)
init = tf.global_variables_initializer()
sess.run(init)
imported_meta = tf.train.Saver()
imported_meta.restore(sess,'myModel/Path/Model_1.meta')
Which throws the following error: 这将引发以下错误:
InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [6152,32] rhs shape= [6164,80]
[[Node: save_2/Assign_3 = Assign[T=DT_FLOAT, _class=["loc:@DGNS/bidirectional_rnn/bw/basic_lstm_cell/kernel"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](DGNS/bidirectional_rnn/bw/basic_lstm_cell/kernel, save_2/RestoreV2/_111)]]
Caused by op u'save_2/Assign_3', defined at:
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets /externalshell/start_ipython_kernel.py", line 205, in <module>
__ipythonkernel__.start()
"/usr/lib/python2.7/dist-packages/IPython/kernel/zmq/kernelapp.py", line 459, in start
ioloop.IOLoop.instance().start()
File "/usr/lib/python2.7/dist-packages/zmq/eventloop/ioloop.py", line 162, in start
super(ZMQIOLoop, self).start()
File "/usr/lib/python2.7/dist-packages/zmq/eventloop/minitornado/ioloop.py", line 830, in start
self._run_callback(callback)
File "/usr/lib/python2.7/dist-packages/zmq/eventloop/minitornado/ioloop.py", line 603, in _run_callback
ret = callback()
... ... etc ……等等
I need help understanding what is happening here. 我需要帮助来了解这里发生的事情。 The error hints to some shape mismatch issue. 该错误提示某些形状不匹配的问题。 But I do not understand how this can be as I have used exactly the same code for generating the model and initializing a new graph. 但是我不知道这是怎么回事,因为我使用了完全相同的代码来生成模型和初始化新图。 The only difference in the code is the model loading part. 代码中的唯一区别是模型加载部分。
How can I start debugging this error in order to get a hint on how to load my model correclty? 我如何开始调试此错误,以获取有关如何加载模型正确性的提示?
I'm pretty sure you are not supposed to load the .meta file. 我很确定您不应该加载.meta文件。 It's tricky to understand since it outputs 3 different files for the checkpoints. 理解起来很棘手,因为它会为检查点输出3个不同的文件。 Try this: 尝试这个:
with tf.Session() as sess:
new_saver = tf.train.import_meta_graph(
'myModel/Path/Model_1.meta', clear_devices=True)
new_saver.restore(sess, 'myModel/Path/Model_1')
Also, just for clarification, are you storing your full model in a .pb file as well, or just generating these checkpoints? 另外,为澄清起见,您是否也将完整模型存储在.pb文件中,还是仅生成这些检查点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.