Tensorflow:尝试使用经过重新训练的Inception-Resnet-v2模型时出错

时间:2018-08-15 17:13:06

标签: python python-3.x tensorflow neural-network

我使用了重新训练脚本来重新训练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]))

0 个答案:

没有答案