eriklindernoren / PyTorch-YOLOv3

Minimal PyTorch implementation of YOLOv3
GNU General Public License v3.0
7.32k stars 2.63k forks source link

After single-class training, nothing can be detected. #126

Closed MarkDana closed 5 years ago

MarkDana commented 5 years ago

I've used this model to train for a single-class dataset, which contains 300 images. After 500 epochs of training, total loss has been reduced to a fairly low level (min=0.011), with precision up to 0.887.

However when I use the generated weights to detect images in the train-val set, nothing can be detected for each image. When running detect.py,

detections = model(input_imgs)
detections = non_max_suppression(detections, 1, opt.conf_thres, opt.nms_thres)
print(detections)

All images show [None].

Below is some changes I made to the original project:

One of the reason may be that, the weights were initialized from yolov9.weights, and that may be different in network structure I edited in yolov3.cfg.

What's more, exploding gradient problem happened 3 times in the 500 epochs.

Anyone in same situation or can help me? thks.

fourth-archive commented 5 years ago

@MarkDana try this tutorial. https://github.com/ultralytics/yolov3/wiki/Example:-Train-Single-Class

The https://github.com/ultralytics/yolov3 repository also includes a YOLOv3 realtime iPhone app:

MarkDana commented 5 years ago

@MarkDana try this tutorial. https://github.com/ultralytics/yolov3/wiki/Example:-Train-Single-Class

The https://github.com/ultralytics/yolov3 repository also includes a YOLOv3 realtime iPhone app:

Thks and I've tried this tutorial. Training now, waiting to see the result. What's more, the two bugs mentioned in issue127 also work for me.

gfjiangly commented 5 years ago

I had same questiones with me before. I think the reason is that "save_weights" function in trian.py doesn't match "load_weights" function in detect.py. You can replace
model.apply(weights_init_normal) with model.apply(weights_init_normal) model.load_state_dict(torch.load(opt.weights_path)) and replace model.save_weights("%s/%d.weights" % (opt.checkpoint_dir, epoch)) with torch.save(model.state_dict(), "%s/%d.weights" % (opt.checkpoint_dir, epoch)) in train.py.

in detect.py, replace model.load_weights(opt.weights_path) with model.load_state_dict(torch.load(opt.weights_path))

0merjavaid commented 5 years ago

Use transfer learning as mentioned by @gfjiangly it wont show results otherwise

MarkDana commented 5 years ago

Both @gfjiangly and @fourth-archive 's method work well. I'll close this issue, thx.