Object Detection with ModelArts

Muhammet Berke OZTURK
Huawei Developers
Published in
8 min readAug 31, 2023

Hello everyone! In this article, I will try to explain how to use Huawei Cloud ModelArts Service for Object Detection and make a demonstration about it. Let’s hop on to it.

Introduction

Object Detection is a AI modeling type that you can use for detecting objects in an image or video. Most of the Object detection models using CNN algorithms for training the model. Huawei Cloud provides automatic ExeML training algortihm for Object Detection models. Today we are going to use that algorithm to train our model. Let’s hop on to it!

Object Detection with ModelArts Demonstration

At the below there is the lifecycle of a AI Development lifecycle. We are going to follow that cycle. First we are going to find or create a dataset for ourselves. After that we are going to prepare the data for training. Like cutting the nonsense datas from dataset. After we will start the training from Object Detection ExeML service on ModelArts. If we have a good training results and metrics we can deploy and try that model for our purposes.

AI Development Lifecycle

First we need a dataset to teach our model how to predict. So we can use some websites like Kaggle.com. If you want a unique dataset, you can create your own dataset of course. But for this example we are going to use a public dataset of game cards from kaggle.com. This is the dataset we are going to use it for our Object detection model. There is about 600 card images we can use. With these datas, model is going to predict which card we have in our hands.

Kaggle homepage
Search for dataset on kaggle
Downloading dataset

After we download the dataset from kaggle.com, we just unzip it and check the images we are going to use for training.

Checking dataset
Checking dataset(2)
Checking dataset(3)

For using these images for our model training, we need to upload them to OBS system on Huawei Cloud. OBS is a cloud block storage service which Huawei Cloud provides. There are three ways we can upload our dataset to OBS system. obsutil, ObsBrowser+ and Huawei cloud console. Huawei Cloud console is not a great way to upload large folders to OBS system so we are going to create our OBS Bucket from console then we will upload our dataset with obsutil and ObsBrowser+ application. First let’s see how we can create our bucket with OBS Console.

Creating bucket with OBS Console.

OBS Console
Creating OBS Bucket
Creating OBS Bucket(2)
OBS Bucket created

Now we have our bucket to upload our dataset. Let’s upload it!

Uploading dataset with ObsBrowser+

For downloading ObsBrowser+, you can use this link.

Downloading OBSBroswer+

After you log in to your Huawei Cloud account with ObsBrowser+. We can upload our dataset to our bucket for using it in ModelArts service.

LogIn to OBSBrowser+
Find the bucket
Uploading dataset through OBSBrowser+
Uploading dataset through OBSBrowser+(2)
Uploading dataset through OBSBrowser+(3)
Uploading dataset through OBSBrowser+(4)

Uploading dataset with obsutil

For downloading obsutil you can follow this article.

After downloading obsutil to your work environment, we can upload our dataset with these CLI commands.

obsutil cp [dataset path] [obs bucket path] -r -f
obsutil cp archive obs://bucket-dtt-training -r -f
Uploading dataset through obsutil

We can see our dataset on our huawei cloud console, ObsBrowser+ or obsutil with

obsutil ls -a obs://bucket-dtt-training

command.

Checking OBS Bucket

After we upload our dataset to bucket we create two folders besides to the dataset folder. One for output and one for empty input. We will use these empty folders for creating dataset on ModelArts service.

Creating folders for output and empty-input
Creating folders for output and empty-input(2)
Creating folders for output and empty-input(3)

After we completed all of this, we can hop on to ModelArts service to create our ExeML project.

We click to the Service list from the home page of Huawei Cloud console and write ModelArts to search bar. Click the related link for ModelArts service. Then we click to the ExeML section and find the Object Detection model training part. Click to Create Project

ModelArts console
Creatine ExeML project

We name our ExeML project and starting to create a dataset. We didnt upload our images to ModelArts service thats why we need to create a new dataset for our Model training. We name our dataset and giving the paths of empty input for input section and output for output section.

Creatine ExeML project(2)
Creatine ExeML project(3)
Creatine ExeML project(4)
Creatine ExeML project(5)

When the ExeML project is created, our dataset is created with it. So we come back to the ModelArts console and click Data Management > Datasets.

Creating dataset on ModelArts
Creating dataset on ModelArts(2)

Then we find the labeling job section and click the labeling job created automaticly.

Creating dataset on ModelArts(3)

As you know, we use a empty input folder when we were creating a dataset for ModelArts service. So we need to upload our real dataset to the system. So we click Add data > Add Data

Creating dataset on ModelArts(4)

In the opening window we select these configurations and select the folder(dataset) we uploaded from our local pc.

Creating dataset on ModelArts(5)
Creating dataset on ModelArts(6)
Creating dataset on ModelArts(7)

As you can see, we have 536 labeled images and one unlabeled image. So we label that unlabeled image ourselves.

Labeling the unlabelled image
Labeling the unlabelled image(2)
Labeling the unlabelled image(3)
Labeling the unlabelled image(4)
Dataset preview

Then we realise there is a miss spelling label in the dataset. Seven of seven. We remove that label and label the image which has been unlabeled after we remove the unnecessary label tag.

Delete the unwanted label
Delete the unwanted label(2)
Label the unlabelled image
Label the unlabelled image(2)

Now, we are ready to train our model. Come back to ModelArts console and go to ExeML section. Find our project and click it.

Back to the ExeML console

We can see our dataset in here either. If we are ready to train the model we can click Train button at top right corner.

Start the training process

We can choose a version name and training, validation set ratio. Training ratio is the ratio that ModelArts going to use the amount of image for training. Same for validation. We select none for incremental version because this is the first time we train this dataset. If we want to train this model incremently we can select the version we want to write on. Select the other configurations and start the training by clicking next.

Start the training process(2)
Start the training process(3)

We wait until the training process is over.

When the process is over we can see the metrics of our model.

ModelArts supports every stage of an AI development. So we can deploy our model and try it. Click deploy top left corner and select your spesifications. Select auto stop after 1 hour so you don’t forget and charged more than you want to.

View the metrics and deploying the model
Deploying the model(2)

After deployment is over, we can try our model with the instructions below.

Deploying the model(3)
Testing the Model
Testing the Model(2)
Testing the Model(3)

Final thoughts and Summary

As you can see our model works even though we only train around 10 images for each class we have. If you try some other test values you can see that the model doesn’t work perfect and this is very normal. We only find out a dataset from kaggle.com and try to create an Object Detection model with it. It can be improved by many other ways. That is a new article topic i guess.

References

  1. https://www.kaggle.com/
  2. https://support.huaweicloud.com/intl/en-us/browsertg-obs/obs_03_1003.html
  3. https://www.huaweicloud.com/intl/en-us/product/modelarts.html
  4. https://medium.com/huawei-developers/how-to-upload-a-file-to-bucket-with-bash-codes-using-obsutil-a47fdd3146d1

--

--