我使用了重新训练脚本来重新训练inception-resnet-v2模型。尝试使用它后,出现以下错误:
无法为Tensor'import / Mul:0'输入形状(1、2、229、229、3)的值, 形状为'(1,299,299,3)
。
代码是:
for img in warped:
model_file = "retrain_cnn/tf_files/retrained_graph.pb"
label_file = "retrain_cnn/tf_files/retrained_labels.txt"
input_height = 229
input_width = 229
input_mean = 128
input_std = 128
input_layer = "Mul"
output_layer = "final_result"
graph = li.load_graph(model_file)
t = tf.convert_to_tensor(img)
float_caster = tf.cast(t, tf.float32)
dims_expander = tf.expand_dims(float_caster, 0);
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
sess = tf.Session()
t = sess.run(normalized)
input_name = "import/" + input_layer
output_name = "import/" + output_layer
input_operation = graph.get_operation_by_name(input_name);
output_operation = graph.get_operation_by_name(output_name);
with tf.Session(graph=graph) as sess:
results = sess.run(output_operation.outputs[0],
{input_operation.outputs[0]: t})
results = np.squeeze(results)
top_k = results.argsort()[-5:][::-1]
labels = load_labels(label_file)
print('\nEvaluation time (1-image): {:.3f}s\n'.format(end-start))
template = "{} (score={:0.5f})"
for i in top_k:
print(template.format(labels[i], results[i]))