张量模型输入 - nvalidArgumentError(参见上面的回溯):shape_and_slice规范中的形状

时间:2017-04-17 19:30:29

标签: python tensorflow tensorflow-serving

嘿我正在尝试为我在tensorflow中编写的模型设置输入点 这是分类的代码

n_dim = training_features.shape[1]
x = tf.placeholder(tf.float32, [None,n_dim])

classifier = (...)
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
    sess.run(init_op)
    classifier.fit(training_features, training_labels, steps=100)
    accuracy_score = classifier.evaluate(testing_features, testing_labels, steps=100)["accuracy"]
    print('Accuracy', accuracy_score)

    pred_a = np.asarray([x])
    prediction = format(list(classifier.predict(pred_a)))
    prediction_result = np.array(prediction)
    output = tf.convert_to_tensor(prediction_result,dtype=None,name="output", preferred_dtype=None)

这是我的建筑代码

export_path_base = sys.argv[-1]
export_path = os.path.join(
    compat.as_bytes(export_path_base),
    compat.as_bytes(str(FLAGS.model_version)))
print('Exporting trained model to', export_path)
builder = saved_model_builder.SavedModelBuilder(export_path)

classification_inputs = utils.build_tensor_info(y)
classification_outputs_classes = utils.build_tensor_info(output)

print('classification_signature...')
classification_signature = signature_def_utils.build_signature_def(
    inputs={signature_constants.CLASSIFY_INPUTS: classification_inputs},
    outputs={
        signature_constants.CLASSIFY_OUTPUT_CLASSES:
            classification_outputs_classes
    },
    method_name=signature_constants.CLASSIFY_METHOD_NAME)
tensor_info_x = utils.build_tensor_info(x)

print('prediction_signature...')
prediction_signature = signature_def_utils.build_signature_def(
    inputs={'input': tensor_info_x},
    outputs={
        'classes' : classification_outputs_classes
    },
    method_name=signature_constants.PREDICT_METHOD_NAME)
print('Exporting...')
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
builder.add_meta_graph_and_variables(
    sess, [tag_constants.SERVING],
    signature_def_map={
        'predict_sound':
            prediction_signature,
        signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
            classification_signature,
    },
    legacy_init_op=legacy_init_op)
builder.save()
print('Saved...')

我尝试在构建之前手动传递虚拟数据,但是我正在尝试让客户端存根动态地将数据传递到模型中。 当我尝试运行该代码来构建我得到此错误

  

InvalidArgumentError(参见上面的回溯):Shape in   shape_and_slice spec [1,280]与存储的形状不匹配   检查点:[193,280] [[节点:save / RestoreV2_1 =   RestoreV2 [dtypes = [DT_FLOAT]   _device =" / job:localhost / replica:0 / task:0 / cpu:0"](_ recv_save / Const_0,save / RestoreV2_1 / tensor_names,save / RestoreV2_1 / shape_and_slices)]]

可能主要目标是让x作为输入和输出返回结果,输出工作但不能让输入工作。

0 个答案:

没有答案