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

自定义网络剪枝问题请教 #23

Closed
tonyskypc opened this issue Nov 24, 2021 · 4 comments
Closed

自定义网络剪枝问题请教 #23

tonyskypc opened this issue Nov 24, 2021 · 4 comments

Comments

@tonyskypc
Copy link

作者现有的剪枝,经过测试非常有效,现有对网络修改后,再运行剪枝失败,请指教:# parameters
nc: 1 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple

anchors

anchors:

  • [4,4, 5,5, 5,5] # P2/4
  • [5,5, 5,5, 6,6] # P3/8
  • [6,6, 7,7, 8,8] # P4/16
    #- [116,90, 156,198, 373,326] # P5/16
    #- 4,4, 5,5, 5,5, 5,5, 5,5, 6,6, 6,6, 7,7, 8,8

YOLOv5 backbone

backbone:

[from, number, module, args]

[from, number, module, args]

[ [ -1, 1, Conv, [ 64, 6, 2, 2, 1, True, 1.0 ] ], # 0-P1/2
[ -1, 1, Conv, [ 128, 3, 2, None, 1, True, 1.0 ] ], # 1-P2/4
[ -1, 3, C3, [ 128, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0 ], 1.0 ] ],
[ -1, 1, Conv, [ 256, 3, 2, None, 1, True, 1.0 ] ], # 3-P3/8
[ -1, 6, C3, [ 256, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], 1.0 ] ],
[ -1, 1, Conv, [ 512, 3, 2, None, 1, True, 1.0 ] ], # 5-P4/16
[ -1, 9, C3, [ 512, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], 1.0 ] ],

[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 去掉32倍特征图输出

[ -1, 3, C3, [ 512, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0 ], 1.0 ] ],
[ -1, 1, SPPF, [ 512, 5, 0.5 ] ],  # 9

]

YOLOv5 v6.0 head

head:
[[-1, 1, Conv, [512, 1, 1, None, 1, True, 1.0]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [512, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 17 (P3/8-small)

[ -1, 1, Conv, [256, 1, 1, None, 1, True, 1.0]],
[ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
[ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 160*160
[ -1, 3, C3, [256, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 16 (P2/4-small)

[-1, 1, Conv, [256, 3, 2, None, 1, True, 1.0]],
[[-1, 13], 1, Concat, [1]], # cat head P2
[-1, 3, C3, [256, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 20 (P3/16-medium)

[-1, 1, Conv, [256, 3, 2, None, 1, True, 1.0]],
[[-1, 9], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 22 (P4/16-large)

[[16, 19, 22], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4)
]

@Cydia2018
Copy link
Collaborator

请问对网络结构修改了哪些部分?报错信息是什么?

@tonyskypc
Copy link
Author

[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 去掉32倍特征图输出 去掉了,在head里面,对p2检测头做了上采样,为了提取更小目标的特征。p5检测头输出也去了,只有p2,p3,p4(4,8,16)输出
Reversing anchor order
Model Summary: 266 layers, 1397744 parameters, 1397744 gradients, 12.2 GFLOPs
Reversing anchor order
Model Summary: 266 layers, 1748606 parameters, 1748606 gradients, 13.3 GFLOPs
Reversing anchor order
Model Summary: 266 layers, 1414902 parameters, 1414902 gradients, 10.3 GFLOPs
Reversing anchor order
Model Summary: 266 layers, 1591100 parameters, 1591100 gradients, 12.7 GFLOPs
Reversing anchor order
Model Summary: 266 layers, 1608152 parameters, 1608152 gradients, 13.5 GFLOPs
Reversing anchor order
Model Summary: 266 layers, 1355248 parameters, 1355248 gradients, 12.0 GFLOPs
0%| | 0/134 [00:00<?, ?it/s]
Traceback (most recent call last):
File "prune_eagleeye.py", line 126, in
rand_prune_and_eval(model,ignore_idx,opt)
File "prune_eagleeye.py", line 67, in rand_prune_and_eval
mAP = ABE(compact_model)
File "/root/share175/sport_trains/shot_ball/detect_shot/yolov5-multibackbone-compression/utils/adaptive_bn.py", line 126, in call
pred = compact_model(imgs) # forward
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/share175/sport_trains/shot_ball/detect_shot/yolov5-multibackbone-compression/models/yolo.py", line 128, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "/root/share175/sport_trains/shot_ball/detect_shot/yolov5-multibackbone-compression/models/yolo.py", line 152, in _forward_once
x = m(x) # run
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/share175/sport_trains/shot_ball/detect_shot/yolov5-multibackbone-compression/models/yolo.py", line 55, in forward
x[i] = self.mi # conv
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 399, in forward
return self._conv_forward(input, self.weight, self.bias)
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 395, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Given groups=1, weight of size [18, 128, 1, 1], expected input[16, 121, 480, 480] to have 128 channels, but got 121 channels instead
Exception in thread Thread-3:
Traceback (most recent call last):
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/utils/data/_utils/pin_memory.py", line 25, in _pin_memory_loop
r = in_queue.get(timeout=MP_STATUS_CHECK_INTERVAL)
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/multiprocessing/queues.py", line 116, in get
return _ForkingPickler.loads(res)
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/site-packages/torch/multiprocessing/reductions.py", line 282, in rebuild_storage_fd
fd = df.detach()
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/multiprocessing/resource_sharer.py", line 57, in detach
with _resource_sharer.get_connection(self._id) as conn:
File "/root/miniconda3/envs/Pytorch180/lib/python3.8/multiprocessing/resource_sharer.py", line 87, in get_connection

@Cydia2018
Copy link
Collaborator

你好,已解决。

@tonyskypc
Copy link
Author

非常即时,非常棒,通过测试,之前的错误已经解决了,希望提供一个捐赠渠道,感谢作者的辛苦。

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

No branches or pull requests

2 participants