2

I used TF Hub to retrain a model for image classification. Now I would like to serve it in the cloud. For that i need a SavedModel. The retrain.py script from TF Hub uses tf.saved_model.simple_save to generate the SavedModel after the training is done.

What confuses me is the .pb file inside the SavedModel folder that I get from that method is much smaller than the final .pb saved after the training.

simple_save is also now deprecated and I tried to get my SavedModel after the training is done following this SO issue.

But my variables folder is empty. How can I incorporate that building of SavedModel inside the retrain.py to replace the simple_save method ? Tips would be much appreciated.

llompalles
  • 3,072
  • 11
  • 20
user 007
  • 821
  • 10
  • 31
  • Hi, did you train the model in Cloud ML Engine? – kww Feb 28 '19 at 23:24
  • no ! i trained locally and i would like to use the cloud only for prediction – user 007 Mar 01 '19 at 09:36
  • I am not very familiar with your question details. But this doc might help you: https://cloud.google.com/ml-engine/docs/tensorflow/deploying-models – kww Mar 01 '19 at 18:00
  • Also those posts might be helpful too: stackoverflow.com/a/44292448/1399222 https://stackoverflow.com/questions/44329185/convert-a-graph-proto-pb-pbtxt-to-a-savedmodel-for-use-in-tensorflow-serving-o – kww Mar 01 '19 at 18:09

1 Answers1

0

To deploy your model to Google Cloud ML, you need a SavedModel which can be produced from tf.saved_model api.

Below are the steps for hosting your trained models in cloud with Cloud ML Engine.

  1. Upload your saved model to a Cloud Storage bucket by setting up a cloud storage bucket using BUCKET_NAME="your_bucket_name"

  2. Select a region for your bucket and set a REGION environment variable. EGION=us-central1

  3. Create a new bucket gsutil mb -l $REGION gs://$BUCKET_NAME

  4. Upload using SAVED_MODEL_DIR=$(ls ./your-export-dir-base | tail -1) gsutil cp -r $SAVED_MODEL_DIR gs://your-bucket

  5. Create a Cloud ML Engine model resource and model version.

Also for your question on incorporating savedmodel inside retrain.py, you need to pass saved model as an argument to the tfhub_module line as below.

python retrain.py --image_dir C: ...\\code\\give the path here --tfhub_module C:

...give the path to saved model directory

morgan121
  • 2,213
  • 1
  • 15
  • 33
gadige
  • 11
  • 1
  • in SO it is best to summarise the content of any link that you include in your answer in case the link stops working. – morgan121 Mar 26 '19 at 01:13
  • 1
    Thanks for the advise. I removed the links(which I mentioned before) and added useful content. This would be more helpful. – gadige Apr 05 '19 at 21:52