Reader small image

You're reading from  Hands-On Computer Vision with Detectron2

Product typeBook
Published inApr 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781800561625
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Van Vung Pham
Van Vung Pham
author image
Van Vung Pham

Van Vung Pham is a passionate research scientist in machine learning, deep learning, data science, and data visualization. He has years of experience and numerous publications in these areas. He is currently working on projects that use deep learning to predict road damage from pictures or videos taken from roads. One of the projects uses Detectron2 and Faster R-CNN to predict and classify road damage and achieve state-of-the-art results for this task. Dr. Pham obtained his PhD from the Computer Science Department, at Texas Tech University, Lubbock, Texas, USA. He is currently an assistant professor at the Computer Science Department, Sam Houston State University, Huntsville, Texas, USA.
Read more about Van Vung Pham

Right arrow

Training Instance Segmentation Models

This chapter provides you with common tools for collecting and labeling images for object instance segmentation tasks. Additionally, it covers the steps to extract data from different sources and reconstruct a dataset in the format supported by Detectron2. Before training an object segmentation model, this chapter also utilizes the code and visualizations approach to explain the architecture of an object segmentation application developed using Detectron2.

By the end of this chapter, you will understand different techniques to collect and label data for training models with object instance segmentation tasks. You will have hands-on experience constructing a custom dataset by extracting data from a nonstandard format and reconstructing it in the format supported by Detectron2 for object detection. Additionally, you will have profound knowledge about the architecture and hands-on experience of training an object instance segmentation application...

Technical requirements

You should have completed Chapter 1 to have an appropriate development environment for Detectron2. All the code, datasets, and results are available on the GitHub repo of the book at https://github.com/PacktPublishing/Hands-On-Computer-Vision-with-Detectron2.

Preparing data for training segmentation models

This section introduces several scenarios about data preparation steps that may be necessary for your cases. Specifically, this section first introduces the common tasks to prepare a dataset, including getting images, labeling images, and converting annotations. Additionally, in practice, data may come in various formats that might not be standard, and in this case, we may need to perform the data preparation steps from scratch. Therefore, this section also introduces the steps to prepare the brain tumor dataset for training custom segmentation models using Detectron2.

Getting images, labeling images, and converting annotations

If you do not have a dataset, Chapter 3 introduces common places to obtain data for computer vision applications in general. It would help if you also went to these sources for object instance segmentation data. Also, you can use the same Python script (Detectron2_Chapter03_Download_Images.ipynb) introduced...

The architecture of the segmentation models

Chapter 4 dived deep into the architecture of Faster R-CNN implemented in Detectron2 for object detection tasks in computer vision. Detectron2 implements Mask R-CNN for object segmentation tasks. It has the same components as Faster R-CNN architecture and one other head for the segmentation task. Figure 10.1 shows the Faster R-CNN architecture as listed in Chapter 4.

Figure 10.1: The architecture of the Detectron2 object detection application

Figure 10.1: The architecture of the Detectron2 object detection application

The code to explore the architecture of Detectron2 implementation for object segmentation tasks remains the same as that for the object detection tasks. Therefore, this section only covers some discrepancies between the two. The first difference is that we must select a pre-trained model with configuration for the object segmentation task instead of the detection task. Therefore, we change the corresponding paths for the configuration and model weights as follows:

config_file...

Training custom segmentation models

The previous section described the architecture of an object segmentation application that extends the object detection application. Therefore, the training steps and configurations of these two applications are similar. This section utilizes the source code provided in the Putting it all together section in swswswswswswswswsw. Ideally, we should perform all the steps in that chapter to get a better set of hyperparameters for this specific dataset. However, for simplicity, this section reuses all the source code as it is and focuses on the differences for training object segmentation applications. The following code snippet downloads the dataset prepared in the previous steps with train and test sets:

!wget -q <url_to/segbraintumors_coco.zip>
!unzip -q segbraintumors_coco.zip

Once the dataset is extracted, the source code for Detectron2 installation, registering datasets, getting a training configuration, building a custom trainer with...

Summary

This chapter described the common places to acquire data for object instance segmentation tasks, and the steps to extract data from a non-standard annotation format and create a custom dataset in the format supported by Detectron2. Furthermore, it utilized the code and visualizations approach to illustrate the architecture of the object instance segmentation application implemented in Detectron2 as an extension of the architecture of an object detection application. Finally, it provided the steps to train a custom model for object instance segmentation tasks and visualize the prediction results for qualitative evaluations.

The next chapter describes techniques for fine-tuning the object instance segmentation application and improving segmentation quality using Detectron2.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Computer Vision with Detectron2
Published in: Apr 2023Publisher: PacktISBN-13: 9781800561625
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Van Vung Pham

Van Vung Pham is a passionate research scientist in machine learning, deep learning, data science, and data visualization. He has years of experience and numerous publications in these areas. He is currently working on projects that use deep learning to predict road damage from pictures or videos taken from roads. One of the projects uses Detectron2 and Faster R-CNN to predict and classify road damage and achieve state-of-the-art results for this task. Dr. Pham obtained his PhD from the Computer Science Department, at Texas Tech University, Lubbock, Texas, USA. He is currently an assistant professor at the Computer Science Department, Sam Houston State University, Huntsville, Texas, USA.
Read more about Van Vung Pham