An minimum implementation of SSD object detection using pytorch.
-
Create virtual environment:
conda create -n SSD python=3.8 conda activate SSD pip install -r requirements.txt
-
Download VOC2007 dataset from following website and unzip them:
-
Download pre-trained and fc-reduced
VGG16model from here. -
Modify the value of
rootintrain.py, please ensure that the directory structure of therootfolder is as follows:root ├───Annotations ├───ImageSets │ ├───Layout │ ├───Main │ └───Segmentation ├───JPEGImages ├───SegmentationClass └───SegmentationObject
-
Start training:
conda activate SSD python train.py
When lr is 5e-4, batch_ size is 8 and train on VOC2007 + VOC2012, the training loss curve is shown in following figure:
-
Modify the value of
rootandmodel_pathineval.py. -
Calculate mAP:
conda activate SSD python eval.py
-
Modify the value of
rootandmodel_dirinevals.py. -
Calculate and plot mAP:
conda activate SSD python evals.py
| class | AP |
|---|---|
| aeroplane | 74.15% |
| bicycle | 83.26% |
| bird | 70.90% |
| boat | 64.99% |
| bottle | 42.33% |
| bus | 85.87% |
| car | 84.64% |
| cat | 89.25% |
| chair | 56.23% |
| cow | 79.70% |
| diningtable | 72.67% |
| dog | 85.87% |
| horse | 88.80% |
| motorbike | 84.49% |
| person | 78.48% |
| pottedplant | 42.97% |
| sheep | 76.03% |
| sofa | 77.72% |
| train | 86.43% |
| tvmonitor | 75.85% |
| mAP | 75.03% |
-
Download
SSD_120000.pthfrom here. -
Modify the value of
model_pathandimage_pathindemo.py. -
Display detection results:
conda activate SSD python demo.py
- Sometimes
lossmay becomenan. If this happens, please reduce the value oflr. - 75.03% mAP may not be the limit of this project. This is the result of 7.5 hours of training on NVIDIA RTX 3090. You can try to increase the
batch_sizeandlr, and then iterate 120000 times on the VOC2007 + VOC2012. The mAP should be higher. If you get a better result, please don't hesitate to tell me. - If you want to train custom dataset, here are some steps to follow:
-
The label file must be in the same XML format as VOC2007, and the structure of dataset must be the same as follows:
root ├───Annotations ├───ImageSets │ └───Main └───JPEGImages
-
Put your
test.txtandtrain.txtin theMainfolder. These txt files must contain the names of the corresponding jpg format pictures. These names do not need a suffix. -
Modify the
classesproperty ofVOCDatasetinnet/dataset.pyto include all the classes in your dataset. -
Change the
rootandimage_setofVOCDatasetintrain.pyand start training.
-
MIT License
Copyright (c) 2021 Huang Zhengzhi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.