首页 文章

在tensorflow元图中重置输入占位符的形状

提问于
浏览
2

我在tensorflow中训练了一个神经网络 . 在培训时,我明确定义了输入占位符的形状,批量大小为20,如 [20,224,224,3] . 我明确定义了批量大小,因为它是网络中的 split 层,并且作为批量大小传递 None 会导致错误 . 有没有什么办法可以在推理时更改输入占位符的形状,以便我可以在单个图像上进行推理?

1 回答

  • 3

    如果您有已保存检查点的* .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)
    

相关问题