Search code examples
google-cloud-mlgoogle-cloud-ml-engine

Job not generating /export directory


I'm following the guide to deploy a model having previously generated the job:

$ gcloud ml-engine jobs submit training testX 
    --job-dir="gs://testxxx/run1"
    --package-path=trainer
    --module-name=trainer.task
    --region us-central1
    --runtime-version=1.0

When I see the contents of the output path, I don't see the "export" dir, only this:

$ gsutil ls -r $OUTPUT_PATH
gs://testxxx/run1/:
gs://testxxx/run1/
gs://testxxx/run1/packages/:
gs://testxxx/run1/packages/fcd2eee0ae2b155ccb3b644c26cf75d6cf81b2dd068122690c9a4baf8ff8e8f5/:
gs://testxxx/run1/packages/fcd2eee0ae2b155ccb3b644c26cf75d6cf81b2dd068122690c9a4baf8ff8e8f5/trainer-0.1.tar.gz

Am I forgetting any step?


Solution

  • The code that you submit is responsible for exporting the model. You can find an example on this post; please reference SavedModel docs.

    The inputs and outputs of your model will of course be specific to your model, but for convenience (and slightly modified), here's the code from that post:

    ### BUILD THE PREDICTION GRAPH
    in_image = tf.placeholder(tf.uint8, shape=(None,))
    out_classes = build_prediction_graph(in_image)
    
    ### DEFINE SAVED MODEL SIGNATURE
    inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}
    outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out_classes)}
    signature = tf.saved_model.signature_def_utils.build_signature_def(
        inputs=inputs,
        outputs=outputs,
        method_name='tensorflow/serving/predict'
    )
    
    ### SAVE OUT THE MODEL
    b = saved_model_builder.SavedModelBuilder('new_export_dir')
    b.add_meta_graph_and_variables(sess,
                                   [tf.saved_model.tag_constants.SERVING],
                                   signature_def_map={'serving_default': signature})
    b.save()