Pytorch-yolov3: detect.py : how to use the code to have detections on a custom trained YOLO

Created on 1 Aug 2019  路  2Comments  路  Source: eriklindernoren/PyTorch-YOLOv3

I noticed that there are a lot of people (#196, #168, #111, #86, #64, #55) that don't have detection's with a custom trained YOLO.

I had the same problem. I figured out that you should include the .pth file after --weights_path (#185):

python3 detect.py --image_folder data/valid --checkpoint_model checkpoints/y
olov3_ckpt_99.pth --model_def config/yolov3-custom.cfg --class_path data/custom/classes.names --conf_thres 0.95 --nms_thres 0.4 --weights_path checkpoints/yolov3_ckpt_99.pth

If the weights path is not defined in your code then it will use the default, which is probably the yolov3.weights. Unfortunately this weights file does not work on your custom trained YOLO. Refer to line 46 of detect.py

if opt.weights_path.endswith(".weights"):
# Load darknet weights
model.load_darknet_weights(opt.weights_path)
else:
# Load checkpoint weights
model.load_state_dict(torch.load(opt.weights_path))

Most helpful comment

Update: This worked for me

python detect.py --model_def config/yolov3-custom.cfg --weights_path checkpoints/yolov3_ckpt_100.pth --image_folder data/samples/ --class_path data/custom/classes.names

All 2 comments

Update: This worked for me

python detect.py --model_def config/yolov3-custom.cfg --weights_path checkpoints/yolov3_ckpt_100.pth --image_folder data/samples/ --class_path data/custom/classes.names

Mr. Gohil, thank you very much for the clue. I also got my custom dataset to work after tweaking your template code.

Was this page helpful?
0 / 5 - 0 ratings