【发布时间】:2017-07-12 10:10:13
【问题描述】:
我已经使用 (Tensorflow) Python API 重新训练了 Inception-v3 模型,并通过修改 tensorflow/tensorflow/examples/image_retraining/retrain.py 并在分类前添加了一个 drop out 层,在 .pb 中保存了一个独立的 Graph层:
def nn_layer(input_tensor, input_dim, output_dim, layer_name, activation_name='activation', act=tf.nn.softmax):
# Adding a name scope ensures logical grouping of the layers in the graph.
with tf.name_scope(layer_name):
# This Variable will hold the state of the weights for the layer
with tf.name_scope('weights'):
weights = weight_variable([input_dim, output_dim])
variable_summaries(weights, layer_name + '/weights')
with tf.name_scope('dropout'):
keep_prob = tf.placeholder(tf.float32)
tf.scalar_summary('dropout_keep_probability', keep_prob)
drop = tf.nn.dropout(input_tensor, keep_prob)
variable_summaries(drop, layer_name + '/dropout')
with tf.name_scope('biases'):
biases = bias_variable([output_dim])
variable_summaries(biases, layer_name + '/biases')
preactivate = tf.matmul(drop, weights) + biases
tf.histogram_summary(layer_name + '/pre_activations', preactivate)
with tf.name_scope(activation_name):
activations = act(preactivate)
tf.histogram_summary(layer_name + '/activations', activations)
return preactivate, activations, keep_prob
python中生成预测的代码如下:
softmax_tensor = sess.graph.get_tensor_by_name('final_layer/final_result/Softmax:0')
predictions = sess.run(softmax_tensor, { 'DecodeJpeg/contents:0':image_data, 'final_layer/dropout/Placeholder:0': 1.})
C++对应的python代码如下:
string input_layer = "Mul";
string output_layer = "final_layer/dropout/Placeholder:0";
Status run_status = session->Run({{input_layer, resized_tensor}}, {output_layer}, {}, &outputs);
C++ 代码以以下错误消息结束:
Running model failed: Invalid argument: You must feed a value for placeholder tensor 'final_layer/dropout/Placeholder'
我应该在上面的 C++ 代码中进行哪些更改以消除此错误?换句话说,如何像在 python 代码中一样更改 C++ 代码中的占位符值。很多天以来,我都陷入了这个问题。任何帮助将不胜感激。
【问题讨论】:
标签: python c++ machine-learning tensorflow deep-learning