IMAGE CLASSIFICATION USING GOOGLE AUTOML TUTORIAL — Part 2
Before entering into this part, it is expected that the steps in part 1 are complete.
Requirements
- Trained model in the Google Auto ML account
- JSON credentials for the service account in Google cloud
- Python
The Google Auto ML UI can be used to classify images on the go. But Google has taken things to the next level that the output can be fetched in python/REST API’s. All that is needed is the project id, model id and the JSON credential key file for the Google cloud service account.
The python code is in this repository
https://github.com/sriram10792/Image-Classification---AutoML
pip install google cloud, google cloud AutoML

Import necessary packages
Provide the path for the JSON for the Google cloud account. In this case, automl_json is the JSON file

This function requires the image file, the project id and the model id as the arguments. “response” fetches the results from the AutoML using API call. “response” will have the confidence score and the classification for that image. The contents are loaded into labels. The label is a list with multiple classifications and the corresponding confidence scores
labels will have “daisy: 0.99”
The remaining part of the function is just formatting the result. The idea is to split the contents of labels so that if it is not required show the confidence score, only the class can be shown. Or if the contents of labels are unpacked, they can be formatted however the user wants.
The classification of that image is stored in “display_name” in labels and the score is stored in classification score.

This function fetches the result from the previous function. This is the function which will be called by the user. The results can be formatted however the user wants

label_image is the python file which contains the other functions. This file is to make the program modular and change the type of argument/input passing however required. The codes are available in the above mentioned repository

The contents of “labels” is shown in the image below. The user can extract whatever is required

This code can be packed as a deployment package and deployed in AWS lambda as a service which runs automatically upon a trigger. The detailed explanation on how to deploy in AWS is discussed in next article