恢复和继续训练张量流模型时出错

时间:2019-08-15 22:53:22

标签: python tensorflow

恢复了模型和元数据后,它会停止在此代码行

`summary_str_Train = sess.run(summaries_merged, feed_dict = Feed_Dict_Train) # gets plot points for Tensorboard Graph (No weight updating)

并显示以下错误消息

tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须使用dtype float和形状[?,256,256,3]的占位符张量'Placeholder_1'输入值。 [[{{node Placeholder_1}}]] [[{{node conv7 / weights_1 / read}}]]

我在图中打印了张量列表:-

for tensor in tf.get_default_graph().get_operations(): # list all the 
tensors in the graph
  print(tensor.name)

这给了我一堆张量:-

占位符

Placeholder_1

const

split / split_dim

分割

Const_1

split_1 / split_dim

split_1

...

代码是此代码的更长版本:-


sess = tf.Session()
newest_meta_filename = newest_meta(preTrained_checkpoint_path)
new_saver = tf.train.import_meta_graph(newest_meta_filename) # restores the graph structure
#Latest_Checkpoint_Path = os.path.join(preTrained_checkpoint_path, 'model.ckpt')
new_saver.restore(sess, tf.train.latest_checkpoint(preTrained_checkpoint_path))
for tensor in tf.get_default_graph().get_operations(): # list all the tensors in the graph
  print(tensor.name)

Input_Placeholder = tf.placeholder(tf.float, shape=(None, Ih,Iw, 6))
Target_Placeholder = tf.placeholder(tf.float, shape=(None, Ih, Iw, 3))

# ... build graph either 1 gpu or many

summaries = tf.get_collection(tf.GraphKeys.SUMMARIES)
summaries.append(tf.summary.scalar('Training_loss', Reproduction_Loss))
validation_loss = tf.summary.scalar('validation_loss', Reproduction_Loss)

print("Reproduction_Loss " +str(Reproduction_Loss))
summaries.append(tf.summary.image('Synthesized', Synthesized_Images, 3))
summaries.append(tf.summary.image('Ground Truth', Target_Placeholder, 3))

saver = tf.train.Saver(tf.global_variables())
summaries_merged = tf.summary.merge_all()

init = tf.global_variables_initializer()
sess = tf.Session(config=tf.ConfigProto( allow_soft_placement=True))
sess.run(init)
writer = tf.summary.FileWriter(FLAGS.log_dir)
writer.add_graph(sess.graph)


# ... batch some data

Frame1And2_Concatenated = np.concatenate((batch_data_frame1, batch_data_frame3), 3)
Feed_Dict_Train = {Input_Placeholder: (Frame1And2_Concatenated), Target_Placeholder: (batch_data_frame2)} # np.split 4, axis=0
Feed_Dict_Validation = {Input_Placeholder: np.concatenate((valid_batch_data_frame1, valid_batch_data_frame3), 3), Target_Placeholder: valid_batch_data_frame2}

_, Loss_Value = sess.run([Update_Op, Reproduction_Loss], feed_dict = Feed_Dict_Train) # update the weights of the model

summary_str_Train = sess.run(summaries_merged, feed_dict = Feed_Dict_Train)

给出此完整错误

File "...\ms-python.python-2019.6.24221\pythonFiles\ptvsd_launcher
main(ptvsdArgs)
File "...\vscode\extensions\ms-python.python-2019.6.24221\pythonFiles\lib\python\ptvn main
run()
File "...\python\ptvn run_file 
runpy.run_path(target, run_name='__main__')
File "...\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "...\Python37\lib\runpy.py", line 96, in _run_modu
mod_name, mod_spec, pkg_name, script_name)
File "...\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "...\voxel_flow_train_multi_gpu.py", line 6
new_saver = tf.train.import_meta_graph(newest_meta_filename) # restores the graph structure
File "...\Python37\lib\site-packages\tensorflow\python\5, in import_meta_graph
meta_graph_or_file, clear_devices, import_scope, **kwargs)[0]
File "...\Python37\lib\site-packages\tensorflow\python\7, in _import_meta_graph_with_return_elements
**kwargs))
File "...\Python37\lib\site-packages\tensorflow\python\ne 806, in import_scoped_meta_graph_with_return_elements
return_elements=return_elements)
File "...n\Python37\lib\site-packages\tensorflow\python\07, in new_func
return func(*args, **kwargs)
File "...\Python37\lib\site-packages\tensorflow\python\ 442, in import_graph_def_ProcessNewOps(graph)
File "...\Python37\lib\site-packages\tensorflow\python\ 235, in _ProcessNewOps
for new_op in graph._add_new_tf_operations(compute_devices=False):  # pylint: disable=protec
File "...\Python37\lib\site-packages\tensorflow\python\, in _add_new_tf_operations
for c_op in c_api_util.new_tf_operations(self)
File "...\Python37\lib\site-packages\tensorflow\python\, in <listcomp>
for c_op in c_api_util.new_tf_operations(self)
File "...n\Python37\lib\site-packages\tensorflow\python\, in _create_op_from_tf_operation
ret = Operation(c_op, self)
File "...n\Python37\lib\site-packages\tensorflow\python\, in __init__
self._traceback = tf_stack.extract_stack()
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,256,256,3]
[[{{node Placeholder_1}}]]
[[{{node GroupCrossDeviceControlEdges_0/conv2_1/Relu}}]]

当我训练时不先恢复就可以了。只有当我恢复时才会发生错误

0 个答案:

没有答案