【问题标题】:Resetting the shape of input placeholder in a tensorflow meta graph在张量流元图中重置输入占位符的形状
【发布时间】:2017-08-10 07:50:35
【问题描述】:
我在 tensorflow 中训练了一个神经网络。在训练时,我明确定义了输入占位符的形状,批量大小为 20,例如 [20,224,224,3]。我明确定义了批量大小,因为你是网络中的 split 层,并且将 None 作为批量大小传递会引发错误。有什么方法可以在推理时更改输入占位符的形状,以便对单个图像进行推理?
【问题讨论】:
标签:
machine-learning
tensorflow
neural-network
deep-learning
conv-neural-network
【解决方案1】:
如果你有保存检查点的 *.meta 文件,你可以重置图表的输入。
# Set the correct data type and shape; shape can be (None, 224, 224, 3) also
new_placeholder = tf.placeholder(tf.float32, shape=(1, 224, 224, 3), name='inputs_new_name')
# here you need to state the name of the placeholder you used in your original input placeholder
saver = tf.import_graph_def(path/to/.meta, input_map={"original_inputs_placeholder_name:0": new_placeholder})
saver.restore(/path/to/your_checkpoint)