【发布时间】:2018-09-26 01:09:48
【问题描述】:
我正在尝试更改我的初始网络(用 keras 编码)以将 base64 图像字符串作为预测的输入。之后,我想将其保存为 tensorflow(.pb - 文件)网络,因为这是 Google ml 引擎所需要的。
正常的预测方式是这样的:
img = "image.jpg"
image = image.load_img(img)
x = image.img_to_array(image)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
score = model.predict(x)
所以我正在尝试实现它,然后像这样保存它:
input_images = tf.placeholder(dtype=tf.string, shape=[])
decoded = tf.image.decode_image(input_images, channels=3)
image = tf.cast(decoded, dtype=tf.uint8)
afbeelding = Image.open(io.BytesIO(image))
x = image.img_to_array(afbeelding)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
scores = model.predict(decoded)
signature = predict_signature_def(inputs={'image_bytes': input_images},
outputs={'predictions': scores})
with K.get_session() as sess:
builder.add_meta_graph_and_variables(sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature})
builder.save()
但图像是张量,而不是实际图像。 老实说,我不知道如何完全实现它。没有办法获得张量的实际值,对吗?真的希望有人可以帮助我。
【问题讨论】:
标签: python tensorflow keras