The official account was pushed by YOLOX for a while. All the public numbers were pushing hard. It is known as: the performance is over Yolov5, and all YOLO is being played.
So, full of expectation, I downloaded the source code and prepared to try
1, Problem description
Well, yes, I encountered a lot of bug s, but fortunately they were all solved. At the end of the training
Good guy, AP is always 0. I searched GIthub last time. It seems that I am not the only one who has encountered the same problem
And according to some answers, I found it wrong, and finally fell into meditation
Until yesterday, someone in the group said that he had successfully deployed with YOLOX, I was stunned, told him that my AP was 0 during training, and asked him about his specific use method. Of course, the answer did not really solve the problem
2, Find problems
So this morning I started debugging and checking again. I suddenly thought whether there was a problem with data loading,
Solid hammer, that's the problem caused by this
3, Problem solving
-
First, yolox/data/datasets/voc_classes.py to change it into the category of your training data (to be safe, you'd better add,) after each category:
VOC_CLASSES = ( "panda", "tiger", )
-
Then modify yolox/exp/yolox_base.py
take self.num_classes Modify to own category number self.num_classes = 2 (My dataset is 2) You can also modify it self.inputsize, self.random_size Change training size You can also modify it self.test_size Change the size of the test
The next two points are:
-
For yolox / data / datasets / VOC Py
annopath = os.path.join(rootpath, "Annotations", "{:s}.xml") Change to annopath = os.path.join(rootpath, "Annotations", "{}.xml")
-
My problem is mainly reflected in exps/example/yolox_voc/yolox_voc_s.py, I believe that AP=0 in most training is also due to this reason
modify self.num_classes = 2 modify get_data_loder Lower VOCDetection Lower image_sets=[('2007', 'trainval'), ('2012', 'trainval')], Change to image_sets=[('2007', 'train')] modify get_eval_loader Lower VOCDetection Lower image_sets=[('2007', 'test')], Change to image_sets=[('2007', 'val')]
Repeat what's important
get_ data_ VOCDetection under Loder
image_sets=[('2007', 'trainval'), ('2012', 'trainval')],
Change to image_sets=[('2007', 'train')]
More importantly: get_ eval_ VOCDetection under loader
image_sets=[('2007', 'test')],
Be sure to change it to image_ Sets = [('2007 ','val')], because the data we verified is in val.txt instead of test.txt Txt, which should be why the AP is always 0
-
Finally, modify tools / train Parameter configuration in PY
set up default="Animals", After training, the results will be saved in tools/YOLOX_outputs/Animals lower parser.add_argument("-expn", "--experiment-name", type=str, default=None) set up model_name,I'm not sure if it's necessary (I don't think so) parser.add_argument("-n", "--name", type=str, default="yolox-s", help="model name") set up batch_size parser.add_argument("-b", "--batch-size", type=int, default=64, help="batch size") set up gpu,Because I only have one card, I set it default=0 parser.add_argument( "-d", "--devices", default=0, type=int, help="device for training" ) Set the path of your data configuration, default="../exps/example/yolox_voc/yolox_voc_s.py" parser.add_argument( "-f", "--exp_file", default="../exps/example/yolox_voc/yolox_voc_s.py", type=str, help="plz input your expriment description file", ) Set the weight path, default="../weights/yolox_s.pth" parser.add_argument("-c", "--ckpt", default="../weights/yolox_s.pth", type=str, help="checkpoint file")
Once you have completed all the configurations, you can start training
4, Train and test results
You can see that with AP, it means success
Finally, let's look at the test results
The overall effect is still very good, and the accuracy is more than 90%
When testing, pay attention to the following points:
-
Due to demo Py calls coco by default_ Classes, so if you want to display the results correctly, you need to set yolox / data / datasets / COCO_CLASSES. Coco under PY_ Change classes to your data category
-
Or in yolox/data/datasets/__init__.py will be from VOC import vocdetection is modified to from voc import VOCDetection, VOC_ CLASSES
-
Then in tools / demo Py will be from yolox data. datasets import COCO_ Modify classes to from yolox data. datasets import COCO_ CLASSES, VOC_ CLASSES,
-
Then set tools / demo All cocos used in PY_ All parts of classes are changed to VOC_CLASSES