【发布时间】:2019-09-16 00:01:30
【问题描述】:
我正在尝试导出我的 TensorFlow 图像分类模型,以便它接受 base64 字符串作为输入。
我已尝试实施this question 提供的解决方案,但出现以下错误:
"InvalidArgumentError: Shape 必须为 0 级,但为 1 级 'DecodeJpeg_1'(操作:'DecodeJpeg'),输入形状:[?]。”
由于第 4 行的代码出现错误。
export_dir = '~/models/1'
builder = saved_model_builder.SavedModelBuilder(export_dir)
image = tf.placeholder(dtype=tf.string, shape=[None], name='source')
decoded = tf.image.decode_jpeg(image)
scores = build_model(decoded)
signature = predict_signature_def(inputs={'image_bytes': image},
outputs={'output': scores})
with K.get_session() as sess:
builder.add_meta_graph_and_variables(sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={'predict': signature})
builder.save()
sess.close()
还有,
我看到在第 5 行,“scores”提供了基于 build_model 函数的模型输出。但是,我在原始问题的答案或 TensorFlow 文档中找不到该函数的来源。
【问题讨论】:
-
你可以试试第 4 行的
shape=[1]吗? -
不幸的是不起作用。引发类似的错误,即:
InvalidArgumentError: Shape must be rank 0 but is rank 1 for 'DecodeJpeg' (op: 'DecodeJpeg') with input shapes: [1]. -
你可以试试
shape=[]吗? -
shape[] 有效,谢谢,现在没有出现错误。但是,现在我收到一个错误,说“build_model”(第 5 行)没有定义,我很害怕。你知道这个函数是从哪里来的吗?
-
不,可能来自一些示例代码?
标签: python rest tensorflow-serving