我有上序列化(TFRecord
)输入操作训练有素的TF模型。图像数据具有可变的形状,并通过tf.image.resize_images(...)
转换为229x229x3形状。我想用gcloud ml-engine predict
platform类似this,确保接受任何尺寸的图像作为输入。Tensorflow:调整图像占位符
我从下面的函数得到我features
张量(其传递给预测图):
def jpeg_serving_input_fn():
"""
Serve single jpeg feature to the prediction graph
:return: Image as a tensor
"""
input_features = tf.placeholder(dtype=tf.float32, shape=[None, None, 3],
name="PREDICT_PLACEHOLDER")
features_normalized = tf.image.resize_images(input_features, [229, 229])
image = tf.reshape(features_normalized, [1, 229, 229, 3], name="RESHAPE_PREDICT")
inputs = {
'image': image
}
的tf.reshape
在端部是因为我的预测图形期望形状[batch_size, 229, 229, 3]
的张量。当我通过
gcloud ml-engine local predict \
--model-dir=trained_model/export/ \
--json-instances=img.json
运行此通过发动机,我收到了PredictionError
:
predict_lib_beta.PredictionError: (4, "Exception during running the graph: Cannot feed value of shape (1, 1600, 2400, 3) for Tensor u'RESHAPE_PREDICT:0', which has shape '(1, 229, 229, 3)'")
它看起来对我来说,tf.reshape
被馈送的tf.image.resize_images
输出应该有正确的形状。有什么想法,我在做什么错在这里?提前致谢!
的Tensorflow位看起来是正确的给我; features_normalized应包含输出(229,229,3)形张量。你可以在你的函数中添加一些调试来验证它是否使用了你认为用于预测的模型?几个星期前我刚开始使用Google Cloud ML,所以我很想看看这里有什么问题。 – SuperTetelman
添加'tf.logging.debug(features_normalized.get_shape())'打印出我所期望的:'229x229x3'。但是,它在保存模型之前在训练期间构建图形时执行此操作。在恢复预测模型时,形状不会重复。这显然是有道理的,但奇怪的是,当我看着'tensorboard'中的图时,'RESHAPE_PREDICT'无处可寻。 – fenkerbb