Pytorch-yolov3: cannot use yolov3-tiny ?

Created on 18 Oct 2018  路  11Comments  路  Source: eriklindernoren/PyTorch-YOLOv3

when I use yolov3-tiny: python3 detect.py --image_folder data/samples --config_path config/yolov3-tiny.cfg --weights_path weights/yolov3-tiny.weights
it show this error: RuntimeError: Given groups=1, weight of size [256, 256, 3, 3], expected input[1, 384, 26, 26] to have 256 channels, but got 384 channels instead
Could you tell me the reason?

Most helpful comment

The problem lies in the route part of create_modules function in models.py. The first element of output_filter is 3 (RGB channels), however, the index0 in configuration file is the output channel of the first CNN. You can:
filters = 0
for layer_i in layers:
if layer_i > 0:
layer_i += 1
filters += output_filters[layer_i]

instead of:
#filters = sum([output_filters[layer_i] for layer_i in layers])

All 11 comments

I also encounter the same problem.

same here. Guess there's something wrong when it read the cfg file.

Same problem here.

The problem lies in the route part of create_modules function in models.py. The first element of output_filter is 3 (RGB channels), however, the index0 in configuration file is the output channel of the first CNN. You can:
filters = 0
for layer_i in layers:
if layer_i > 0:
layer_i += 1
filters += output_filters[layer_i]

instead of:
#filters = sum([output_filters[layer_i] for layer_i in layers])

@Aslizy solved this problem ,thank you very much.
filters = 0
for layer_i in layers:
if layer_i > 0:
layer_i += 1
filters += output_filters[layer_i]

Indented version:

```
filters = 0
for layer_i in layers:
if layer_i > 0:
layer_i += 1
filters += output_filters[layer_i]

@Aslizy solved this problem ,thank you very much.
filters = 0
for layer_i in layers:
if layer_i > 0:
layer_i += 1
filters += output_filters[layer_i]

after edit these lines, I still got some errors in tinyv3:
File "video.py", line 92, in
model = Darknet(cfgfile)
File "/home/pakcy/Desktop/PyTorch-YOLOv3/models.py", line 243, in __init__
self.hyperparams, self.module_list = create_modules(self.module_defs)
File "/home/pakcy/Desktop/PyTorch-YOLOv3/models.py", line 42, in create_modules
bias=not bn,
File "/usr/local/lib/python3.6/dist-packages/torch-0.4.1-py3.6-linux-x86_64.egg/torch/nn/modules/conv.py", line 297, in __init__
False, _pair(0), groups, bias)
File "/usr/local/lib/python3.6/dist-packages/torch-0.4.1-py3.6-linux-x86_64.egg/torch/nn/modules/conv.py", line 33, in __init__
out_channels, in_channels // groups, *kernel_size))
RuntimeError: sizes must be non-negative

can you tell me why?

filters = 0
for layer_i in layers:
        if(layer_i > 0):
            filters += output_filters[layer_i+1]
        else:
            filters += output_filters[layer_i]

THIS IS MY SOLUTION..

Seems to be running that way, but performance appears to be bad. Anyone else?

For instance it's not detecting the dog/bike in the dog.jpg example:

predictions-pytorch-yolov3-tiny

Compared with the reference darknet implementation (same weight file):

predictions-reference-darknet-yolov3-tiny

Hey guys. I ran into the same problem in my own yolov3 repo, and got it fixed with a few changes. Results now match darknet:
https://github.com/ultralytics/yolov3/issues/51

./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg
50227882-c48a5300-0374-11e9-95b3-6cf8254aee64

detect.py --cfg cfg/yolov3-tiny.cfg --weights weights/yolov3-tiny.pt
dog

That's a serious bug. Thanks! Fixed with the latest commit.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qilong-zhang picture qilong-zhang  路  5Comments

ghimiredhikura picture ghimiredhikura  路  4Comments

FanLu1994 picture FanLu1994  路  3Comments

MAP
nationalflag picture nationalflag  路  5Comments

stadtgiraffe picture stadtgiraffe  路  3Comments