필자는 직렬화 된 (TFRecord
) 입력에서 작동하는 훈련 된 TF 모델을 가지고 있습니다. 이미지 데이터는 다양한 모양을 가지며 tf.image.resize_images(...)
을 통해 229x229x3 모양으로 변환됩니다. this과 비슷한 gcloud ml-engine predict
platform을 사용하고 모든 크기의 이미지를 입력으로 허용하고 싶습니다.Tensorflow : 크기 조정 이미지 자리 표시 자
난 다음 함수에서 (예측 그래프에 전달된다) 내 features
텐서를 얻을 내 예측 그래프 형상 [batch_size, 229, 229, 3]
의 텐서 예상하므로 끝
tf.reshape
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
가 올바른 형태를 가져야한다 tf.image.resize_images
의 출력을 공급하고있는 것처럼
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)'")
그것은 나에게 보이는 : 나는
gcloud ml-engine local predict \
--model-dir=trained_model/export/ \
--json-instances=img.json
를 통해 엔진을 통해이 프로그램을 실행할 때 나는 PredictionError
얻을. 내가 여기서 잘못하고있는 것에 대한 어떤 생각? 미리 감사드립니다! 오류가 "RESHAPE_PREDICT:0"
텐서를 공급하는 코드합니다 (tf.reshape()
OP의 즉 출력 image
)보다는 "PREDICT_PLACEHOLDER:0"
텐서합니다 (tf.image.resize_images()
영업 이익 즉 입력 input_features
)에 의한 것처럼
Tensorflow 비트가 나에게 맞아 보인다. features_normalized는 a (229, 229, 3) 모양의 텐서를 포함해야합니다. 함수에 일부 디버그를 추가하여 예측 모델이라고 생각하는 모델을 사용하고 있는지 확인할 수 있습니까? 몇 주 전에 Google Cloud ML을 사용하기 시작 했으므로이 문제가 무엇인지 궁금합니다. – SuperTetelman
'tf.logging.debug (features_normalized.get_shape())를 추가하면'229x229x3'을 출력합니다. 그러나 모델을 저장하기 전에 트레이닝 중에 그래프를 작성하는 동안이 작업을 수행합니다. 예측을 위해 모델을 복원 할 때 모양은 반복되지 않습니다. 이것은 분명히 이해가되지만,'tensorboard'에서 그래프를 볼 때'RESHAPE_PREDICT'는 어디에도 없습니다. – fenkerbb