Yolov5-deepsort-inference icon indicating copy to clipboard operation
Yolov5-deepsort-inference copied to clipboard

只能使用yolov5m吗

Open MindsetFather opened this issue 2 years ago • 2 comments

MindsetFather avatar Jul 06 '22 14:07 MindsetFather

当使用https://github.com/ultralytics/yolov5中的yolov5m.pt时,报错tributeError: Can't get attribute 'C3' on <module 'models.common' from 'Yolov5-deepsort-inference/models/common.py'>

MindsetFather avatar Jul 07 '22 06:07 MindsetFather

加个这个 #在最上面需要引入warnings库 import warnings

class C3(nn.Module): # CSP Bottleneck with 3 convolutions def init(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion super(C3, self).init() c_ = int(c2 * e) # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c1, c_, 1, 1) self.cv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) self.m = nn.Sequential([Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)]) # self.m = nn.Sequential([CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])

def forward(self, x):
    return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))

class SPPF(nn.Module): # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher def init(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13)) super().init() c_ = c1 // 2 # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c_ * 4, c2, 1, 1) self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)

def forward(self, x):
    x = self.cv1(x)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
        y1 = self.m(x)
        y2 = self.m(y1)
        return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

zhananda avatar Dec 28 '23 04:12 zhananda