前言
本文阐述了你ncnn转换时focus报错的原因。
转换和实现focus模块
$ onnx2ncnn yolov5s-sim.onnx yolov5s.param yolov5s.bin
转换为 ncnn 模型,会输出很多 Unsupported slice step,这是focus模块转换的报错
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
好多人遇到这种情况,便不知所措,这些警告表明focus模块这里要手工修复下
打开 yolov5/models/common.py 看看focus在做些什么
class Focus(nn.Module):
# Focus wh information into c-space
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups
super(Focus, self).__init__()
self.conv = Conv(c1 * 4, c2, k, s, p, g, act)
def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2)
return self.conv(torch.cat([x[..., ::2, ::2], x[...