Preface
Nanodet-plus was grandly released two days ago, and it has gained a lot of popularity. I took advantage of my free time at the end of the year to learn it quickly to avoid being trapped; because I have had practical training experience with nanodet before, but it has not been used for a long time. The code is old. Fortunately, the author merged the new version into the old warehouse. The code structure has basically not changed. The old configuration file modifications are still applicable. It is easier to get started again. This time I plan to use the previous chopsticks data set . Let’s try the effect. This article records the training process.
Compared with the previous generation NanoDet, NanoDet-Plus has improved accuracy by 30% while only adding more than 1 millisecond of delay. Compared with other lightweight models such as YOLOv5-n, YOLOX-Nano, etc., NanoDet-Plus has improved accuracy and speed. The height is also much higher! At the same time, NanoDet-Plus has improved the code and architecture, and proposed a very simple training auxiliary module to make the model easier to train! At the same time, the new version is easier to deploy and provides demos of ncnn, OpenVINO, MNN and Android APP!
Let’s first look at the comparison between nanodet-plus and the previous generation nanodet and other lightweight detection algorithms: for
specific improvements, please refer to the author’s original Zhihu introduction: Nanodet-Plus Zhihu introduction
1. Environment configuration
A brief introduction to my local environment:
- ubuntu 18.04
- RTX 3070
- cuda 11.2
- python 3.7
- pytorch 1.8
1.1 nanodet installation
You need to install nanodet and related dependencies, open the terminal interface, and enter the following commands in the terminal:
git clone https://github.com/RangiLyu/nanodet.git
cd nanodet
pip install -r requirements.txt
python setup.py develop
After the installation is successful, test it. Create an images folder under the nanodet folder, put the test images into the folder, and then download the weights trained on the coco data set (the weights are placed on Google Cloud Disk. To download, you need to go online scientifically) , run the test demo:
python demo/demo.py image --config CONFIG_PATH --model MODEL_PATH --path IMAGE_PATH
- CONFIG_PATH is the yml configuration file of nanodet-plus
- MODEL_PATH is the weight path just downloaded
- IMAGE_PATH is the test image path
Weight download link address, you can download both weight and checkpoint. Only weight is used during inference, and checkpoint is used during training. I only downloaded the 416 size here:
The following is my test example. The downloaded weights are placed in the newly created weights folder, using the 416 size inference of nanodet-plus-m:
python demo/demo.py image --config config/nanodet-plus-m_416.yml --model weights/nanodet-plus-m_416.pth --path images/
The test results are as follows. The false detection rate is still quite high, but the confidence level is relatively low. It can be filtered out through the threshold:
Or use the nanodet-plus-m-1.5x_416 version, the effect will be much better:
Okay, let’s not worry about the accuracy for now. Question, if the test is successful, it means that the environment has been installed successfully. If there is an error in operation, you need to check it yourself. Generally, there will be no problems if you follow the steps.
2. Data preparation
In order to facilitate the testing of a new target detection algorithm in the future, since the coco and voc data sets are too large, training once takes a long time, so I built a chopstick data set myself, with only more than 200 images. , there are a few pictures, but it is very convenient to configure the training. The data set is small, the training speed is fast, and the results are easy to produce. It has very good model testing significance. For detailed introduction, please see my previous construction article. I built a data set for target detection points
and then divided the voc format data set into train and val according to the configuration file data set reading requirements. Part, the folders are divided as follows. Because the data set has a small amount of data, if you don’t want to write a script to divide it, you can manually copy and paste it and divide it. Record the path:
3. Modify the configuration file
Copy config/nanodet_custom_xml_dataset.yml and name it config/nanodet_plus-m-416_test.yml. Modify the following as needed:
The folder where training is saved:
the number of training target categories, according to your own data set, mine only has one category:
data set label category:
training size and data set path:
in order, training batch size (according to your own graphics card), preset Training weight path (it seems that the convergence speed is very fast without adding any addition), total training rounds:
After modification, run the training command:
python tools/train.py config/config/nanodet_plus-m-416_test.yml
The following training interface appears, indicating that the model has started training. If you encounter problems, check whether the configuration file has not been modified successfully, and troubleshoot specific problems:
The final training accuracy results are as follows:
It looks pretty good. AP0.5:0.95 reached 0.749, and AP0.5 also reached 0.989. It depends on the visualization effect.
Run the test demo, and the visual results are as follows. The effect seems to be slightly worse, but the problem is not big. You can adjust the post-processing threshold filtering, or adjust some hyperparameters during the training process for better training, because it is just a simple run through to see the effect. , the result actually looks very good, the effect of the 1.5x model should be better: