Another Yolox article, solving the AP is 0 under the Voc data set: Solving the AP is 0 when training YOLOX
When a friend is training the coco data set, the AP is 0. In fact, I have not encountered this problem. I tested it here and it can run normally. But some friends asked, so I will summarize how to do it here. Let's train the Coco dataset. ..
Proceed as follows
- First of all, make sure that the Coco dataset is in the correct format
Contains twoAnimals_Coco ├─annotations ├─train2017 └─val2017
annotations
important files under the folder ,instances_train2017.json
andinstances_val2017.json
contains image data for training and verificationtrain2017
val2017
- Then modify
yolox/data/datasets/coco_classes.py
, modify to the category of your own data setCOCO_CLASSES = ( "tiger", "panda", )
- Then modify according to your own needs
yolox/exp/yolox_base.py
(or not modify)(这里应该也可以不用修改,因为后面的exps/example/yolox_voc/yolox_s.py会对self.num_classes进行重载) 将self.num_classes修改为自己的类别数 self.num_classes = 2 (我的数据集是 2) 你还可以修改 self.inputsize, self.random_size 改变训练尺寸大小 你还可以修改 self.test_size 改变测试的尺寸大小
- Revise
exps/example/custom/yolox_s.py
修改数据集地址 self.data_dir self.data_dir = "D:/Z_Data/Animals_Coco" 修改类别 self.num_classes self.num_classes = 2 剩下的 self.max_epoch,self.data_num_workers,self.eval_interval 可自行选择修改
- Finally modify
tools/train.py
the parameter configuration in设置 default="Animals_Coco", 训练后结果就会保存在 tools/YOLOX_outputs/Animals_Coco下 parser.add_argument("-expn", "--experiment-name", type=str, default=None) 设置 model_name,我也不太清楚这是不是必须项 (我觉得不是) parser.add_argument("-n", "--name", type=str, default="yolox-s", help="model name") 设置 batch_size parser.add_argument("-b", "--batch-size", type=int, default=64, help="batch size") 设置gpu,因为我只有一张卡,所以设 default=0 parser.add_argument( "-d", "--devices", default=0, type=int, help="device for training" ) 设置你的数据配置的路径,default="../exps/example/custom/yolox_s.py" parser.add_argument( "-f", "--exp_file", default="../exps/example/custom/yolox_s.py", type=str, help="plz input your expriment description file", ) 设置预训练权重路径, default="../weights/yolox_s.pth" parser.add_argument("-c", "--ckpt", default="../weights/yolox_s.pth", type=str, help="checkpoint file")
After the above operations, it can be seen from the figure below that it can run normally.
If after these series of operations, the AP is still 0, my personal guess is that there is json
a problem with the content of the file.
Let's see the test results
Generally speaking, the speed and accuracy are still ok.
Finally, if you have found or found in the training process , modify the lineTypeError: 'numpy.float64' object cannot be interpreted as an integer
Anaconda3\Lib\site-packages\pycocotools\cocoeval.py
pycahrm
External Libraries
site-packages\pycocotools\cocoeval.py
507、508
self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
修改为
self.iouThrs = np.linspace(.5, 0.95, 10, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, 101, endpoint=True)