How to Build ML Model Using Tensor Flow Object Detection API With AzureML Service

Lavanya P
The Startup
Published in
5 min readSep 13, 2020

Tensor Flow Object Detection API is the framework for creating a deep learning network that solves object detection problems.

There are pre-trained models in TF framework known as Model Zoo , which are trained with various architectures such as Resnet-50, Resnet -101 and Inception. These models trained on various datasets such as COCO, KITTI and Open Images. These models can be directly consumed for prediction to detect categories available in those datasets.

To develop model with custom data, we can leverage the existing pre-trained models and their configuration in TF Object Detection API, all we have to do is select the algorithm from the model zoo -> transform the input data to required TF format-> train & evaluate model.

Once the model is built, operationalization is also equally important. We will see how to orchestrate the model into Azure MLS.

What is Azure MLS?

Azure Machine Learning service (AMLS) helps to automate the model build, train, and tracking in an Azure Machine Learning Workspace. It helps to keep a track of various model experiments and metrics in one place.

Once the baseline model is built in VM / local computer, next step is to automate the model training process ,below are the steps to get started with AMLS:

  1. Copy the input data (images and its annotations file) into Azure Blob
  2. Create Azure ML pipelines: An Azure Machine Learning pipeline can be as simple as one that calls a Python script, which reads the input from source, processes and writes output results. we need to prepare Azure ML pipeline for data preparation, model training and deployment.
  3. To start building pipeline, we can use the local computer with Jupyter notebook, the prerequisites is to install azure ml libraries.
Basic flow of Azure ML pipeline creation from local computer

4. The data in Azure blob can be accessed from Azure ML pipeline using Data store mounts.

5.Sample explanation of the Azure ML Pipeline step creation is placed below.

How to Orchestrate TF OD API model in Azure MLS

Now, lets see how we can automate the model training using Tensor Flow Object Detection API in Azure MLS. We will see the process of Orchestrating TensorFlow Object Detection API model in Azure Machine Learning Service (AMLS).

Lets break the process into 3 parts.

1. Setup TensorFlow Object Detection API with custom data in AMLS

2. Orchestration of TF OD API model in the AMLS

3. Logging TensorBoard Graphs in AMLS Experiment

Setup TensorFlow Object Detection API with custom data in AMLS:

TensorFlow object detection API can be installed using the tutorial link here. Then follow the below steps to configure with custom data.

Step 1: Training Dateset Preparation:

TensorFlow Object Detection API reads data using the ‘TFRecord’(TensorFlow record) format. For training the object detection API, model needs the following information.

a) Data

Input Images: Images to be trained

Labels: Object location co-ordinates for locating it in the image.

For Labeling there are few tools which helps to perform the labeling.

b) Number of classes/objects to be detected. Create a label file, which specifies the label ID and name. Labels are number of objects to be trained. Below is the sample.

item {
id: 1
name: ‘Class_1’
}

item {
id: 2
name: ‘Class_2’
}

c) Based on the use case, choose the relevant pre-trained model from the model zoo as TensorFlow Object Detection API uses Transfer Learning.

d) Model Configuration file for training. (this is used for tuning the model).

For each image, object co-ordinates need to be passed along with input image. object coordinates are known as Annotations.

Image annotations should be in csv format. Placed the sample data below:

sample input data (image name + annotations + label [classid is label id])

Step 2: Model Training:

TF OD API Model Training Flow (image source is from web)

a. Split the Input data set (Images + Annotations) to train,test and validation sets.

b. Convert the input data to TFRecord for each train and test datasets.

d. Run the model training on train data set with modified config file on multi GPU for better performance.

e. Evaluate the model on test set.

After configuring Tensor Flow Object Detection API, following python files are needed to train, evaluate, and to save model.

Orchestration of TF OD API model in the Azure MLS

After preparing the model with custom data using TF OD API, the next step is to operationalize the process in AMLS for better tracking of the model results/experiments.

3- step process

The code for creating training pipeline is available in the Github repository here.

Azure ML Training Pipeline Flow

Once the model is automated in Azure MLS, we can view and track the model evaluation in the Azure MLS experiments.

Logging TensorBoard Graphs in AMLS Experiment

TensorBoard is used to view the model graphs such as loss in runtime to monitor the model performance. Along with the model evaluation metrics, we can read the TensorBoard graphs by reading values from .tfevents file and log in the Azure experiments for better tracking of model results and performance.

Below image shows the Azure experiment with model evaluation metrics and TensorBoard graphs.

AMLS Experiment — Model Eval results & TensorBoard Graphs

The code for creating training pipeline is available in the Github repository here.

--

--