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

I am trying to custom a model with ghostnet base on yolov5 #1249

Closed
hawkinglai opened this issue Oct 30, 2020 · 2 comments
Closed

I am trying to custom a model with ghostnet base on yolov5 #1249

hawkinglai opened this issue Oct 30, 2020 · 2 comments
Labels
question Further information is requested

Comments

@hawkinglai
Copy link

hawkinglai commented Oct 30, 2020

❔Question

This is my model config file base on this paper: GhostNet: More Features from Cheap Operations
Link: https://arxiv.org/abs/1911.11907
I am a beginner of deep learning and thanks for your patient answer

YOLOv5 backbone

backbone:

[from, number, module, args]

[[-1, 1, Focus, [64, 3]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, GhostBottleneck, [128, 3, 1]],
[-1, 1, GhostBottleneck, [256, 3, 2]], # 3-P3/8
[-1, 9, GhostBottleneck, [256, 3, 1]],
[-1, 1, GhostBottleneck, [512, 3, 2]], # 5-P4/16
[-1, 9, GhostBottleneck, [512, 3, 1]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 1, SPP, [1024, [5, 9, 13]]],
]

YOLOv5 head

head:
[[-1, 3, GhostBottleneck, [1024, 3, 1]], #10

[-1, 1, DWConv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 8], 1, Concat, [1]],
[-1, 1, DWConv, [512, 3, 1]],
[-1, 3, GhostBottleneck, [512, 3, 1]], #15

[-1, 1, DWConv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 5], 1, Concat, [1]],
[-1, 1, DWConv, [256, 3, 1]],
[-1, 3, GhostBottleneck, [256, 3, 1]],
[-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1]],

[-2, 1, DWConv, [256, 3, 2]],
[[-1, 15], 1, Concat, [1]],
[-1, 3, GhostBottleneck, [512, 3, 1]],
[-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1]],

[-2, 1, DWConv, [512, 3, 2]],
[[ -1, 10], 1, Concat, [1]],
[-1, 3, GhostBottleneck, [1024, 3, 1]],
[-1, 1, nn.Conv2d, [na * (nc + 5), 1, 1]],

[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]

Additional context

And after these operations, I ran yolo.py to try this model. And yolo.py report this error:
Sizes of tensors must match except in dimension 1. Got 4 and 2 in dimension 2 (The offending index is 1)

Paste the full text:
from n params module arguments
0 -1 1 3520 models.common.Focus [3, 32, 3]
1 -1 1 18560 models.common.Conv [32, 64, 3, 2]
2 -1 1 3440 models.experimental.GhostBottleneck [64, 64, 3, 1]
3 -1 1 18784 models.experimental.GhostBottleneck [64, 128, 3, 2]
4 -1 3 32928 models.experimental.GhostBottleneck [128, 128, 3, 1]
5 -1 1 66240 models.experimental.GhostBottleneck [128, 256, 3, 2]
6 -1 3 115008 models.experimental.GhostBottleneck [256, 256, 3, 1]
7 -1 1 1180672 models.common.Conv [256, 512, 3, 2]
8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]]
9 -1 1 142208 models.experimental.GhostBottleneck [512, 512, 3, 1]
10 -1 1 1024 n DWConv at 0x000001F4DBB19E5 [512, 256, 1, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 7] 1 0 models.common.Concat [1]
13 -1 1 7424 n DWConv at 0x000001F4DBB19E5 [768, 256, 3, 1]
14 -1 1 38336 models.experimental.GhostBottleneck [256, 256, 3, 1]
15 -1 1 512 n DWConv at 0x000001F4DBB19E5 [256, 128, 1, 1]
16 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
17 [-1, 5] 1 0 models.common.Concat [1]
18 -1 1 3712 n DWConv at 0x000001F4DBB19E5 [384, 128, 3, 1]
19 -1 1 10976 models.experimental.GhostBottleneck [128, 128, 3, 1]
20 -1 1 32895 torch.nn.modules.conv.Conv2d [128, 255, 1, 1]
21 -2 1 1408 n DWConv at 0x000001F4DBB19E5 [128, 128, 3, 2]
22 [-1, 15] 1 0 models.common.Concat [1]
23 -1 1 38336 models.experimental.GhostBottleneck [256, 256, 3, 1]
24 -1 1 65535 torch.nn.modules.conv.Conv2d [256, 255, 1, 1]
25 -2 1 2816 n DWConv at 0x000001F4DBB19E5 [256, 256, 3, 2]
26 [-1, 10] 1 0 models.common.Concat [1]
27 -1 1 142208 models.experimental.GhostBottleneck [512, 512, 3, 1]
28 -1 1 130815 torch.nn.modules.conv.Conv2d [512, 255, 1, 1]
29 [17, 20, 23] 1 228990 Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [384, 255, 256]]
Traceback (most recent call last):
File "D:/yolov/yolov5-comment-master/models/yolo.py", line 251, in
model = Model(opt.cfg).to(device)
File "D:/yolov/yolov5-comment-master/models/yolo.py", line 79, in init
m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward
File "D:/yolov/yolov5-comment-master/models/yolo.py", line 109, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "D:/yolov/yolov5-comment-master/models/yolo.py", line 129, in forward_once
x = m(x) # run
File "D:\anaconda_yolo\envs\yolov5\lib\site-packages\torch\nn\modules\module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\yolov\yolov5-comment-master\models\common.py", line 100, in forward
return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Got 8 and 4 in dimension 2 (The offending index is 1)

Process finished with exit code 1

@hawkinglai hawkinglai added the question Further information is requested label Oct 30, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2020

Hello @KitaharaYukimori, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@glenn-jocher
Copy link
Member

@KitaharaYukimori there was a GhostConv() bug fix recently, you should clone the latest and see if the error persists. See #1176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants