After training the model, an error occurs when running the demo.py inference file in YOLOX, and the running code with the error is as follows:
Run Code
python tools/demo.py image -f exps/example/yolox_voc/yolox_voc_s.py -c YOLO_outputs/yolox_voc_s_1/best_ckpt.pth --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu]
Note:
-f exps/example/yolox_voc/yolox_voc_s.py
This command must match, not the yolox used for testing before training_s.py, which is configured by yourself. If you don’t correct it, you will always report the following errors.
![](https://programmerah.com/wp-content/uploads/2022/10/23633b627d9a447ca4480697776d152b.png)
Of course, if the above instructions are OK, this error still occurs, that is, the category corresponding error in the demo.
Take my own example, I use VOC format datasets, but the default in the demo file is COCO_CLASSES, so this will definitely report an error, so we have to change it in the demo.py file.
First, find the file yolox/data/datasets/_init_.py and add the following code to the file.
from .voc_classes import VOC_CLASSES
Then enter tools/demo.py file
About 15 lines, Modify
from yolox.data.datasets import COCO_CLASSES
to
from yolox.data.datasets import VOC_CLASSES
Modify about 100 lines of cls_names in Predictor:
![](https://programmerah.com/wp-content/uploads/2022/10/f29d607705224306bb4f781b8ba6154c.png)
to
![](https://programmerah.com/wp-content/uploads/2022/10/2c467f0b075543f5841cf9de608a079f.png)
Set the function of about 300 lines
![](https://programmerah.com/wp-content/uploads/2022/10/5978172421654e60b13d20268a550f6d.png)
Change to
![](https://programmerah.com/wp-content/uploads/2022/10/6082a1ee67fe42519790a8e8e63802bc.png)
No error will be reported during operation, successful! NICE!