CS663 | computer vision
  • outline
  • projects
  • syllabus
  • links

Deploying a Model on Google AI Platform

 

 

 

STEP 1: Setup your Google Cloud Account

Assumes: you have google cloud account and billing credits setup. You create a new project and then enable the
AI platform API

 

 

 

 

STEP 2: In your project enable the AI platform and then go to Storage and create S3 (storage) Bucket --give it a meaningful name and upload the directory of your Tensorflow SavedModel : fill out name, region in cloud,

 

 

 

 

 

STEP 3: in newly created bucket upload the SavedModel you previously created --here is a tensorflow 1.14 python 3.5 CatDog CNN model

 

 

 

STEP 4: in your created project go back to AI Platform and choose create new model--you may choose
to enable logging for additional costs
>>then click on model and create a version and associate it with the model stored in your S3 bucket from previous step
>>>NOTE: it seems that AI Platform does not necessarily support the latest Tensorflow version!!!

 

 

 

 

 

HERE you can see this version of the model is correctly deployed

 

 

 

 

 

 

 

 

STEP 5: Connect on your local machine with gcloud command line sdk tools and send
a REST api call to test if your model is working
>> assumes you have already installed them
>> step 5.1: get some input data and make sure it is formatted correctly.

  • Example for CNN: If your input is a raw image, resize it and then use the pyton script (image-to-json.py which you must copy to your machine) to convert any image you want to pass to the CNN model created above for classification to a json file called request.json

>> step 5.2: use glcould tool to call prediction on the image

 

 

STEP 5.1 INPUT Data Format -- HERE are 2 files you can use that have been processed: requestDogSize.json and requestCatSize.json

IMPORTANT: you must understand the input needed for your Network you deployed.

>> If a CNN you will most probably be passing an image as input, but MUST MAKE sure it is the CORRECT SIZE (see example below).

 

>>IF an LSTM, the output will again be a json file but, represent the input to the LSTM which is typically a series of feature vectors --each representing the output of a feature extraction stage on an image in the video sequence you will input to

 

 

Call the code to create json file to represent your input image dog.jpg (assumes in same directory as the python image-to-json.py script)

 

python image-to-json.py --input dog.jpg  --output request.json  --scale 1


IMPORTANT: make sure your image size is correct for input into in this case our Cat/Dog CNN which must be 150x150

 

 

BUT, we need to rescale our input for our Cat/Dog CNN image so it is divided by 255 so
run the converter again with --scale 255

 

python image-to-json.py --input dog.jpg --output request.json --scale 1

NEW OUTPUT

 

STEP 5.1-part A: In command prompt launch the Google Cloud console

NOTE: your model name and version name may be different --see the ones I created above are used here
Also: request.json represents the image you are passing wrapped in json




> gcloud init



AND YOU WILL SPECIFY your project id (e.g. catdogcnn-mlengine)


You can always set your project in your console via:

> gcloud config set project catdogcnn-mlengine


STEP 5.2: TO MAKE a REQEST to your deployed Google Cloud Model


(ASSUMES: you have input correctly formatted -see step 5.1-- in a json file)


> gcloud ai-platform predict --model cat_dog_cnn --version v1 --json-instances request.json
 

                 


OUTPUT: below is a vector [0.000039, 0.99996] meaning a dog

 

 

cs663:computer vision

  • home
  • outline
  • projects
  • syllabus
  • links