|
| 1 | +# Semi-automatic Object Detection Annotation with MMRotate and Label-Studio |
| 2 | + |
| 3 | +Annotation data is a time-consuming and laborious task. This article introduces how to perform semi-automatic annotation using the RTMDet-R algorithm in MMRotate in conjunction with Label-Studio software. Specifically, using RTMDet-R to predict image annotations and then refining the annotations with Label-Studio. Community users can refer to this process and methodology and apply it to other fields. |
| 4 | + |
| 5 | +- RTMDet-R: RTMDet-R is a high-precision single-stage object detection algorithm developed by OpenMMLab, open-sourced in the MMRotate rotated object detection toolbox. Its open-source license is Apache 2.0, and it can be used freely without restrictions by industrial users. |
| 6 | + |
| 7 | +- [Label Studio](https://github.com/heartexlabs/label-studio) is an excellent annotation software covering the functionality of dataset annotation in areas such as image classification, object detection, and segmentation. |
| 8 | + |
| 9 | +In this article, we will use [DOTA](https://captain-whu.github.io/DOTA/index.html) images for semi-automatic annotation. |
| 10 | + |
| 11 | +## Environment Configuration |
| 12 | + |
| 13 | +To begin with, you need to create a virtual environment and then install PyTorch and MMCV. In this article, we will specify the versions of PyTorch and MMCV. Next, you can install MMDetection, MMRotate, Label-Studio, and label-studio-ml-backend using the following steps: |
| 14 | + |
| 15 | +Create a virtual environment: |
| 16 | + |
| 17 | +```shell |
| 18 | +conda create -n rtmdet python=3.9 -y |
| 19 | +conda activate rtmdet |
| 20 | +``` |
| 21 | + |
| 22 | +Install PyTorch: |
| 23 | + |
| 24 | +```shell |
| 25 | +# Linux and Windows CPU only |
| 26 | +pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html |
| 27 | +# Linux and Windows CUDA 11.3 |
| 28 | +pip install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu113/torch_stable.html |
| 29 | +# OSX |
| 30 | +pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 |
| 31 | +``` |
| 32 | + |
| 33 | +Install MMCV: |
| 34 | + |
| 35 | +```shell |
| 36 | +pip install -U openmim |
| 37 | +mim install "mmcv>=2.0.0rc0" |
| 38 | +# Installing mmcv will automatically install mmengine |
| 39 | +``` |
| 40 | + |
| 41 | +Install MMDetection: |
| 42 | + |
| 43 | +```shell |
| 44 | +git clone https://github.com/open-mmlab/mmdetection -b dev-3.x |
| 45 | +cd mmdetection |
| 46 | +pip install -v -e . |
| 47 | +``` |
| 48 | + |
| 49 | +Install MMRotate: |
| 50 | + |
| 51 | +```shell |
| 52 | +git clone https://github.com/open-mmlab/mmrotate/ -b dev-1.x |
| 53 | +cd mmrotate |
| 54 | +pip install -v -e . |
| 55 | +``` |
| 56 | + |
| 57 | +Install Label-Studio and label-studio-ml-backend: |
| 58 | + |
| 59 | +```shell |
| 60 | +# Installing Label-Studio may take some time, if the version is not found, please use the official source |
| 61 | +pip install label-studio==1.7.2 |
| 62 | +pip install label-studio-ml==1.0.9 |
| 63 | +``` |
| 64 | + |
| 65 | +Download the RTMDet-R weights: |
| 66 | + |
| 67 | +```shell |
| 68 | +cd path/to/mmrotate |
| 69 | +mkdir work_dirs |
| 70 | +cd work_dirs |
| 71 | +wget https://download.openmmlab.com/mmrotate/v1.0/rotated_rtmdet/rotated_rtmdet_m-3x-dota/rotated_rtmdet_m-3x-dota-beeadda6.pth |
| 72 | +``` |
| 73 | + |
| 74 | +## Start the Service |
| 75 | + |
| 76 | +Start the RTMDet-R backend inference service: |
| 77 | + |
| 78 | +```shell |
| 79 | +cd path/to/mmrotate |
| 80 | +label-studio-ml start projects/LabelStudio/backend_template --with \ |
| 81 | +config_file=configs/rotated_rtmdet/rotated_rtmdet_m-3x-dota.py \ |
| 82 | +checkpoint_file=./work_dirs/rotated_rtmdet_m-3x-dota-beeadda6.pth \ |
| 83 | +device=cpu \ |
| 84 | +--port 8003 |
| 85 | +# Set device=cpu to use CPU inference, and replace cpu with cuda:0 to use GPU inference. |
| 86 | +``` |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +The RTMDet-R backend inference service has now been started. To configure it in the Label-Studio web system, use http://localhost:8003 as the backend inference service. |
| 91 | + |
| 92 | +Now, start the Label-Studio web service: |
| 93 | + |
| 94 | +```shell |
| 95 | +label-studio start |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +Open your web browser and go to http://localhost:8080/ to see the Label-Studio interface. |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +Register a user and then create an RTMDet-R-Semiautomatic-Label project. |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +Download the example DOTA images by following [MMRotate Preparing DOTA Dataset](https://github.com/open-mmlab/mmrotate/blob/main/tools/data/dota/README.md) and import them using the Data Import button. |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +Then, select the Object Detection With Bounding Boxes template. |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +```shell |
| 119 | +plane |
| 120 | +ship |
| 121 | +storage-tank |
| 122 | +baseball-diamond |
| 123 | +tennis-court |
| 124 | +basketball-court |
| 125 | +ground-track-field |
| 126 | +harbor |
| 127 | +bridge |
| 128 | +large-vehicle |
| 129 | +small-vehicle |
| 130 | +helicopter |
| 131 | +roundabout |
| 132 | +soccer-ball-field |
| 133 | +swimming-pool |
| 134 | +``` |
| 135 | + |
| 136 | +Then, copy and add the above categories to Label-Studio and click Save. |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | +In the Settings, click Add Model to add the RTMDet-R backend inference service. |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +Click Validate and Save, and then click Start Labeling. |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | +If you see Connected as shown below, the backend inference service has been successfully added. |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +## Start Semi-Automatic Labeling |
| 153 | + |
| 154 | +Click on Label to start labeling. |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +We can see that the RTMDet-R backend inference service has successfully returned the predicted results and displayed them on the image. However, we noticed that there are some missed predicted bounding boxes. |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +We manually add some annotation boxes, adjust the position of the boxes to get the following corrected annotation, and then click Submit to complete the annotation of this image. |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | +After submitting all images, click export to export the labeled dataset in COCO format. |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +Use VSCode to open the unzipped folder to see the labeled dataset, which includes the images and the annotation files in JSON format. |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +At this point, the semi-automatic labeling is complete. We can use this dataset to train a more accurate model in MMRotate and then continue semi-automatic labeling on newly collected images with this model. This way, we can iteratively expand the high-quality dataset and improve the accuracy of the model. |
0 commit comments