-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Single channel image training? #2609
Comments
@UNeedCryDear single-channel to 3-channel image you will see about zero speedup. 95% of FLOPS and parameter counts are not in the initial convolution. You can verify this by creating a 1-channel model in PyTorch Hub and comparing it's metrics against the default 3-channel model: import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=False, autoshape=False, channels=3)
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=False, autoshape=False, channels=1) See PyTorch Hub Tutorial to build your own single-channel models, though training single-channel would need some modifications to the dataloader. YOLOv5 Tutorials |
@glenn-jocher Thank you for your reply.
Because my images are grayscale. When converting to three channels, the data of each channel is the same, which will cause huge waste. So I'm going to ask if there's any way to get a single channel model. Thank you again for your reply. I'll try it myself. |
@UNeedCryDear your interpretation of the output shape being a function of the channel count is incorrect. Output shape is a function of anchor count and image size only, not channel count. |
@glenn-jocher Well, that should be my misunderstanding |
@UNeedCryDear yes these are 3 anchors times 85 values (4 box coordinates, 1 objectness, 80 classes), at each of 3 output strides (8, 16, 32) for small, medium, large objects. |
Hi ! What I understood from your discussion is that training a model with only one channel or 3 channels has no impact on model speed and inference! right? |
@besmaGuesmi yes correct, input channel count has little effect on the model. You can create models with different input channels like this and compare stats and speeds: import torch
for ch in 1, 3, 4, 10:
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', channels=ch)
results = model(np.array((640, 640, ch)))
results.print() EDIT: Please git pull or git clone again to update your code as #5542 and #5543 fixed a bug in channel count adjustment with hub models. Above example works correctly with #5542 and #5543. |
how about single channel onnx model? I trained a model on gray scale images. I would like to export it to onnx with a single channel |
Line 504 in 2f1eb21
change it to
and try again: |
🚀 Feature
Thanks for this great work!
Can a parameter be set up to train and predict single channel image,like gray image.
Motivation
In the actual application process, many times do not need three channel BGR-image, but a single channel gray-image. I think a lot of people will have this situation. So I hope to have a parameter that can train and predict single channel images to speed up. From three channels to single channel, I think this speed should be nearly tripled.
Pitch
dataset=cv2.imread(train_data,0)
train(dataset,ch=1)
save(single_model)
detect_set=cv2.imread(detet_img,0)
model.predict(detect_set)
Alternatives
Additional context
The text was updated successfully, but these errors were encountered: