how to use model after trained in tensorflow (save/load graph)

前端 未结 1 620
予麋鹿
予麋鹿 2021-02-10 10:02

My tensorflow version is 0.11. I want to save a graph after training or save something else which tensorflow can load it.

I/ Using Exporting and Importing a Met

相关标签:
1条回答
  • 2021-02-10 10:25

    Your first solution (using the MetaGraph) almost works, but the error arises because you are feeding a batch of flattened MNIST training examples to a tf.placeholder() that expects a batch of MNIST training examples as a 4-D tensor with shape batch_size x height (= 28) x width (= 28) x channels (= 1). The easiest way to solve this is to reshape your input data. Instead of this statement:

    print(i, np.mean(np.argmax(teY[test_indices], axis=1) ==
                     sess.run(predict_op, feed_dict={
                         "X:0": teX[test_indices],
                         "p_keep_conv:0": 1.0,
                         "p_keep_hidden:0": 1.0})))
    

    ...try the following statement, which reshapes your input data appropriately, instead:

    print(i, np.mean(np.argmax(teY[test_indices], axis=1) ==
                     sess.run(predict_op, feed_dict={
                         "X:0": teX[test_indices].reshape(-1, 28, 28, 1),
                         "p_keep_conv:0": 1.0,
                         "p_keep_hidden:0": 1.0})))
    
    0 讨论(0)
提交回复
热议问题