PyTorch-YOLOv3 icon indicating copy to clipboard operation
PyTorch-YOLOv3 copied to clipboard

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

Open pieterblok opened this issue 6 years ago • 2 comments

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))

pieterblok avatar Aug 01 '19 14:08 pieterblok

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

priteshgohil avatar Dec 03 '19 18:12 priteshgohil

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

Mechazo11 avatar Dec 22 '20 23:12 Mechazo11