Training Models using Supervisely

Source: https://leightley.com/what-is-deep-learning-and-why-should-you-care/

Machine Learning, Artificial Intelligence, and Deep Learning are some of the most complex, yet highly demanded fields of expertise today. There are innumerable resources and tools to work in these fields, and one such popular tool is Supervisely.

Supervisely is a web platform where we can build Deep Learning solutions. It is a service meant for dataset management, annotation, and preparation for Deep Learning. Supervisely is used by students, researchers, and businessmen to manage large-scale datasets and even preserve privacy by working with Supervisely on their servers.

In this article, we will be looking at how to train models using Transfer Learning in Supervisely. To work with Supervisely, we first need to create an account. For non-commercial purposes, the account is created for free.

When the account is first created, we are logged in as the admin user. There is a default workspace that is created. We can continue with this workspace or create our own. A sample of a custom workspace is shown below with the name MLOps_Task 6.

Figure 1: Creation of new workspace

Inside the new workspace, we can start a new project by importing the required dataset.

Figure 2: Importing the dataset (Part 1)

The dataset can be imported by a simple drag-and-drop operation from the local system onto the given space.

Figure 3: Importing the dataset (Part 2)

The dataset being used has been taken from Kaggle and it is a dataset that is used to design models to predict brain tumors from the MRI images. The link to the dataset is given in the References section. The data used is only of all the images where a brain tumor is found.

Once the images have been uploaded, the important parts (tumors) must be highlighted, which is also called an annotation. The annotation must be done for each image so that the existing dataset can be expanded further for model training. An example of an annotated image is given below. The large black-lined red-filled dots are the points manually placed to mark the regions of the tumor’s existence.

Figure 4: Sample of annotated image

Once all the images have been annotated, we expand the dataset for training the model. In our attempt to train the model, we will be working with Instance Segmentation offered by Mask R-CNN.

Figure 5: Creating a training dataset
Figure 6: Running DTL Script

Once the instance segmentation is completed, we see a new project added to the workspace.

Figure 7: Workspace after Instance Segmentation

Now, we finally proceed with the creation of the train/validation set, by running a DTL script once again, which results in the creation of the third project in the workspace.

Figure 8: After Train/Validation dataset development

With the final project, we can train our model. In Supervisely, we can train neural networks from scratch or implement transfer learning. But in both cases, the computer system being used to train the model has specific requirements it must fulfill as seen in the image below.

Figure 9: System requirements of Agent for NN model training

To use an existing NN model, we can import pre-trained models from the Neural Networks section. Once the model is cloned, we can train the model by choosing the desired dataset (project).

The addition of agents is done in the Clusters section, where detailed instructions are given as shown in Figure 9 to add the agent for training. A suitable agent can be found by launching an EC2 instance provided by AWS. By creating an account in AWS, we can use a suitable AMI (which works much like a container image in Docker Hub) to train the NN model. However, the AMIs with GPUs are not provided free of charge. I used the Deep Learning AMI (Amazon Linux 2) Version 30.0, with p2.xlarge flavor.

Once the EC2 instance has been launched, we can log in to the instance using the SSH and execute the command mentioned in the Clusters section of Supervisely on the command line of the instance. Once the agent has been successfully added, we can train the model we have imported using Transfer Learning.

To observe the progress of the training, we can use the tasks bar. It provides charts to observe the loss while training the model, logs of the model being trained, etc.

Figure 10: Charts from the Tasks section of the model being trained.

We can also see the checkpoints based on the number of epochs for which the model has been trained in the Tasks section.

Figure 11: Checkpoints of the model being trained.

Once the model has been trained, we can either test it using the same agent or even download the trained weights as a .zip file. The downloaded model weights are in the .h5 file format.

Figure 12: Downloading the trained model weights

This work has been done as a part of the MLOps Training program conducted by Mr. Vimal Daga from LinuxWorld Informatics Pvt. Ltd.

Check out more of my work in this program below!

  1. Working with Jenkins — An Introduction: https://medium.com/@akshayavb99/working-with-jenkins-an-introduction-48ecf3de3c25
  2. Working with Jenkins, Docker, Git, and GitHub — Part II: https://medium.com/@akshayavb99/working-with-jenkins-docker-git-and-github-part-ii-d74b6e47140c
  3. An Introduction to Transfer Learning: https://medium.com/@akshayavb99/an-introduction-to-transfer-learning-6b54696fb405
  4. Integrating ML/DL with DevOps: https://medium.com/@akshayavb99/integrating-ml-dl-with-devops-258dde42e220

ECE Undergrad | ML, AI and Data Science Enthusiast | Avid Reader | Keen to explore different domains in Computer Science