How to make correct forecasts jpeg images in cloud-ml

I want to predict jpeg image in cloud-ml.

My training model is the initial model, and I would like to send the entrance to the first level of the chart: 'DecodeJpeg/contents:0'(where I need to send a jpeg image). I set this layer as a possible input by adding to retrain.py :

inputs = {'image_bytes': 'DecodeJpeg/contents:0'}
tf.add_to_collection('inputs', json.dumps(inputs))

Then I save the training results in two files (export and export.meta) with:

saver.save(sess, os.path.join(output_directory,'export'))

and I create a model in cloud-ml using these files.

As suggested in some posts ( here , here and here from the official Google cloud blog) I'm trying to make a forecast using

gcloud beta ml predict --json-instances=request.json --model=MODEL

where the instance is a jpeg image decoded in base64 format with:

python -c 'import base64, sys, json; img = base64.b64encode(open(sys.argv[1], "rb").read()); print json.dumps({"key":"0", "image_bytes": {"b64": img}})' image.jpg &> request.json

:

error: 'Prediction failed: '

? ? this post , cloud-ml base64 jpeg image_bytes. ? , ?

+1
3

CloudML , .

, retrain.py. . sess.run; . jpeg .

0

, TF: , . . . , . Inception .

- . .

():

def build_prediction_graph(self):
   """Builds prediction graph and registers appropriate endpoints."""
   tensors = self.build_graph(None, 1, GraphMod.PREDICT)
   keys_placeholder = tf.placeholder(tf.string, shape=[None])
   inputs = {
      'key': keys_placeholder.name,
      'image_bytes': tensors.input_jpeg.name
   }

   tf.add_to_collection('inputs', json.dumps(inputs))

   # To extract the id, we need to add the identity function.
   keys = tf.identity(keys_placeholder)
   outputs = {
       'key': keys.name,
       'prediction': tensors.predictions[0].name,
       'scores': tensors.predictions[1].name
   }
   tf.add_to_collection('outputs', json.dumps(outputs))

:

def export(self, last_checkpoint, output_dir):
  # Build and save prediction meta graph and trained variable values.
  with tf.Session(graph=tf.Graph()) as sess:        
    self.build_prediction_graph()
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    self.restore_from_checkpoint(sess, self.inception_checkpoint_file,
                                 last_checkpoint)
    saver = tf.train.Saver()
    saver.export_meta_graph(filename=os.path.join(output_dir, 'export.meta'))
    saver.save(sess, os.path.join(output_dir, 'export'), write_meta_graph=False)

last_checkpoint :

self.model.export(tf.train.latest_checkpoint(self.train_path), self.model_path)
0

, image_bytes. , , 2 : - "" , - "image_bytes". , , "" "" .

The second problem is that the form DecodeJpeg / contents: 0 ', is (). For Cloud ML, you need to have a form like (No,) so that you can submit it.

There are several suggestions in other answers to your question here about how you can follow public posts to change your schedule, but on hand I can talk about these two issues.

Let us know if you have any additional problems.

0
source

Source: https://habr.com/ru/post/1662165/


All Articles