0

I'm working on an image classifier with tensorflow estimator + keras retraining the last layer of a pretrained application inception_v3 on GCP ML engine.

The keras model is exported with tf.keras.estimator.model_to_estimator and the input function receive the path of the image stored on GCP cloud storage open the image with tf.image.decode_jpeg and return a dataset with the following format dict(zip(['inception_v3_input'], [image])), label

I'm trying to define the tf.estimator.export.ServingInputReceiver but I'm having some trouble defining it.

The model is serving correctly the prediction with the predict method using the input function without the labels. My idea was to reuse the input_function to decode the image passing only the path of the image on cloud storage to the prediction also for the google endpoint, but I can't understand how to do it.

Thank's for your help

Paolo Fusari
  • 105
  • 12
  • Might this help? https://www.tensorflow.org/programmers_guide/datasets#decoding_image_data_and_resizing_it – dizcology Jun 14 '18 at 22:59

1 Answers1

0

If I'm understanding correctly, your question is how to get the file from Cloud Storage, considering that you want to decode the image this way:

image_decoded = tf.image.decode_jpeg(image_string)

So, in this case, you can use:

image_string = file_io.FileIO(filename, mode='r')

By importing file_io first:

from tensorflow.python.lib.io import file_io

According to the comments on this question about reading input data from GCS, using the file_read function should provide the same results since " there was a bunch of work done to abstract file io and file systems, so there all the io functionality works consistently". So you can try also with read_file function.

Héctor Neri
  • 1,384
  • 9
  • 13