Training and Predicting with instance keys

前端 未结 2 1410
甜味超标
甜味超标 2020-12-08 16:59

I am able to train my model and use ML Engine for prediction but my results don\'t include any identifying information. This works fine when submitting one row at a time for

2条回答
  •  独厮守ぢ
    2020-12-08 17:26

    Great question. The Cloud ML Engine flowers sample does this, by using the tf.identity operation to pass a string straight through from input to output. Here are the relevant lines during graph construction.

    keys_placeholder = tf.placeholder(tf.string, shape=[None])
    inputs = {
        'key': keys_placeholder,
        'image_bytes': tensors.input_jpeg
    }
    
    # To extract the id, we need to add the identity function.
    keys = tf.identity(keys_placeholder)
    outputs = {
       'key': keys,
       'prediction': tensors.predictions[0],
       'scores': tensors.predictions[1]
    }
    

    For batch prediction you need to insert "key": "some_key_value" into your instance records. For online prediction you would query the above graph with a JSON request like:

    {'instances' : [
        {'key': 'first_key', 'image_bytes' : {'b64': ...}}, 
        {'key': 'second_key', 'image_bytes': {'b64': ...}}
        ]
    }
    

提交回复
热议问题