Pytorch-yolov3: detect.py problem

Created on 13 May 2019  路  6Comments  路  Source: eriklindernoren/PyTorch-YOLOv3

hello, when I run the detecti.py . It shows :'RuntimeError: Given groups=1, weight of size 32 3 3 3, expected input[1, 4, 416, 416] to have 3 channels, but got 4 channels instead', Anyone can help me ?Thanks!

Most helpful comment

I managed to solve the issue.
detect.py uses ImageFolder class from utils.datasets.py for loading data into the dataloader instead of using ListDataset class like train.py and test.py.
ListDataset automatically converts images to RGB because it was fixed in this issue.

So what we have to do is to copy line 86 and paste it in line 47. That is, change line 47 to be exactly like line 86 in utils/datasets.py:

img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))

This fixed the issue for me.

All 6 comments

I have sloved the problem , it is because the form of the picture is not jpg.

I am getting the same error on a custom dataset. I only differ in that the RuntimeError ends with "but got 1 channels instead". My images are in the form of a jpg as well, and the problem persists

I got this error while training on a custom dataset as well. Any ideas on how to solve this?

Traceback (most recent call last):
File "detect.py", line 73, in
detections = model(input_imgs)
File "/home/ubuntu/anaconda3/envs/pytorch-env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(input, *kwargs)
File "/home/ubuntu/PyTorch-YOLOv3/models.py", line 258, in forward
x = module(x)
File "/home/ubuntu/anaconda3/envs/pytorch-env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(input, *kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch-env/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward
input = module(input)
File "/home/ubuntu/anaconda3/envs/pytorch-env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(input, *kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch-env/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 338, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 32 3 3 3, expected input[1, 1, 416, 416] to have 3 channels, but got 1 channels instead

I managed to solve the issue.
detect.py uses ImageFolder class from utils.datasets.py for loading data into the dataloader instead of using ListDataset class like train.py and test.py.
ListDataset automatically converts images to RGB because it was fixed in this issue.

So what we have to do is to copy line 86 and paste it in line 47. That is, change line 47 to be exactly like line 86 in utils/datasets.py:

img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))

This fixed the issue for me.

I managed to solve the issue.
detect.py uses ImageFolder class from utils.datasets.py for loading data into the dataloader instead of using ListDataset class like train.py and test.py.
ListDataset automatically converts images to RGB because it was fixed in this issue.

So what we have to do is to copy line 86 and paste it in line 47. That is, change line 47 to be exactly like line 86 in utils/datasets.py:

img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))

This fixed the issue for me.

I sovled my problem with your method, thank you very much!

Is this issue still relevant/occurring?

I closed this issue due to inactivity. Feel free to reopen for further discussion.

Was this page helpful?
0 / 5 - 0 ratings