ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.16k stars 3.44k forks source link

yolov3-spp.cfg Support #16

Closed happog closed 5 years ago

happog commented 5 years ago

Could you add support for yolov3-spp model? https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-spp.cfg

glenn-jocher commented 5 years ago

@happog I added yolov3-spp.cfg in commit b93839dea7bf814ed0374fbe01dccd5f4c251c28. You just need to specify it in train.py before you start training now. I'm unfamiliar with the SPP variant, what does it do?

https://github.com/ultralytics/yolov3/blob/b93839dea7bf814ed0374fbe01dccd5f4c251c28/train.py#L12

happog commented 5 years ago

@glenn-jocher Thank you for answering. SPP means spatial pyramid pooling. As the spp cfg needs the maxpool (stride=1) layer, so it should not work correctly if this layer is not implemented in the model.py file.

glenn-jocher commented 5 years ago

@happog models.py correctly implements any of the following layers in any *.cfg file. If the SPP file only uses these existing types, then everything should be fine. If the SPP is introducing a new type of layer then there could be a problem (if it is not recognized it may be skipped). When I start training with SPP I see 3 new layers added, layer count goes from 221 to 224. How many layers are you expecting the SPP cfg to produce?

nirbenz commented 5 years ago

@happog @glenn-jocher

Re-opening this. I gave this a shot, trying to simply add support for a maxpool layer as it should be (in models.py):

        elif module_def['type'] == 'maxpool':
            stride = int(module_def['stride'])
            kernel_size = int(module_def['size'])
            pad = (kernel_size - 1) / 2
            maxpool_layer = nn.MaxPool2d(stride=stride, kernel_size=kernel_size, padding=pad)
            modules.add_module('maxpool_%d' % i, maxpool_layer)

And this indeed works, however network performance is actually significantly worse so I'm obviously doing something wrong.

glenn-jocher commented 5 years ago

I added support for yolov3-tiny using the maxpool layer (and implementing a fix to the routing layer, and modifying the stride calculation in models.py yolo forward) in https://github.com/ultralytics/yolov3/issues/51, so if yolov3-spp was suffering from issues before perhaps these are now resolved as well. I'll try to run inference with yolov3-spp and see the result now:

python3 detect.py --cfg cfg/yolov3.cfg --weights weights/yolov3.weights dog zidane

python3 detect.py --cfg cfg/yolov3-spp.cfg --weights weights/yolov3-spp.weights dog zidane

Ok, results look comparable to yolov3. Well SPP certainly seems to be working, though this limited anecdotal evidence makes it hard to conclude whether it represents an improvement over standard yolov3, or if there are pytorch implementation issues. To resolve implementation issues I must compare against darknet directly. I'll try that now. Hmm, ok still inconclusive.

./darknet detect cfg/yolov3.cfg yolov3.weights data/... predictions predictions

./darknet detect cfg/yolov3-spp.cfg yolov3-spp.weights data/... predictions predictions

Strangely enough tie used to get 1.00 also using the repo originally. zidane_result

LukeAI commented 5 years ago

What was the conclusion here? Does Yolov3-SPP work now with reasonable performance and precision?

glenn-jocher commented 5 years ago

@LukeAI works perfectly. Yolov3-SPP is the default model for all operations now in train.py, detect.py and test.py. It acheives .607 mAP as you can see: https://github.com/ultralytics/yolov3#map.

LukeAI commented 5 years ago

Ah yes, thankyou! Why do you think this repo. achieves slightly higher accuracy?

sanazss commented 5 years ago

should we use yolove-1cls or yolov3-spp-1cls for single class and image size of 512*512? does it make difference? all default size in the code is 416 which is in yolov3-1cl

glenn-jocher commented 5 years ago

@sanazss yolov3-spp-1cls.cfg will give you better results for training single class models.