Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I train 4-channel pictures? #314

Closed
LVROBOT opened this issue Jul 7, 2020 · 3 comments
Closed

Can I train 4-channel pictures? #314

LVROBOT opened this issue Jul 7, 2020 · 3 comments
Labels
enhancement New feature or request Stale Stale and schedule for closing soon

Comments

@LVROBOT
Copy link

LVROBOT commented Jul 7, 2020

Did some data processing,Can I train 4-channel pictures?

@LVROBOT LVROBOT added the enhancement New feature or request label Jul 7, 2020
@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 7, 2020

@LVROBOT sure, you can train any channel images. When models are created you can specify how many input channels are used, though beware opencv will typically load most images, even black-white images as 3-ch images.

The Model() accepts a channel argument here, with ch=3 by default.

yolov5/models/yolo.py

Lines 45 to 46 in 121d90b

class Model(nn.Module):
def __init__(self, model_cfg='yolov5s.yaml', ch=3, nc=None): # model, input channels, number of classes

Also when calling a model from torch hub you can set the input channel count similarly. See https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading

@LVROBOT
Copy link
Author

LVROBOT commented Jul 7, 2020

@glenn-jocher
I train 4-channel pictures, error is :

0%| | 0/1196 [00:07<?, ?it/s]
Traceback (most recent call last):
File "/home/leo/Desktop/DL/yolov5-master/train.py", line 409, in
train(hyp)
File "/home/leo/Desktop/DL/yolov5-master/train.py", line 258, in train
pred = model(imgs)
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/leo/Desktop/DL/yolov5-master/models/yolo.py", line 90, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "/home/leo/Desktop/DL/yolov5-master/models/yolo.py", line 107, in forward_once
x = m(x) # run
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/leo/Desktop/DL/yolov5-master/models/common.py", line 86, in forward
return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/leo/Desktop/DL/yolov5-master/models/common.py", line 21, in forward
return self.act(self.bn(self.conv(x)))
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 345, in forward
return self.conv2d_forward(input, self.weight)
File "/home/leo/anaconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 32 16 3 3, expected input[8, 12, 320, 320] to have 16 channels, but got 12 channels instead

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

2 participants