コード例 #1
0
 def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False):
     # ch_in, ch_out, kernel, stride, groups, expansion, shortcut
     super(CrossConv, self).__init__()
     c_ = int(c2 * e)  # hidden channels
     self.cv1 = Conv(c1, c_, (1, k), (1, s))
     self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g)
     self.add = shortcut and c1 == c2
コード例 #2
0
 def __init__(self,
              c1,
              c2,
              k=1,
              s=1,
              g=1,
              act=True):  # ch_in, ch_out, kernel, stride, groups
     super(GhostConv, self).__init__()
     c_ = c2 // 2  # hidden channels
     self.cv1 = Conv(c1, c_, k, s, None, g, act)
     self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)
コード例 #3
0
 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 = nn.Conv2d(c1, c_, 1, 1, bias=False)
     self.cv3 = nn.Conv2d(c_, c_, 1, 1, bias=False)
     self.cv4 = Conv(2 * c_, c2, 1, 1)
     self.bn = nn.BatchNorm2d(2 * c_)  # applied to cat(cv2, cv3)
     self.act = nn.LeakyReLU(0.1, inplace=True)
     self.m = nn.Sequential(
         *[CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])
コード例 #4
0
 def __init__(self, c1, c2, k, s):
     super(GhostBottleneck, self).__init__()
     c_ = c2 // 2
     self.conv = nn.Sequential(
         GhostConv(c1, c_, 1, 1),  # pw
         DWConv(c_, c_, k, s, act=False) if s == 2 else nn.Identity(),  # dw
         GhostConv(c_, c2, 1, 1, act=False))  # pw-linear
     self.shortcut = nn.Sequential(DWConv(
         c1, c1, k, s, act=False), Conv(
             c1, c2, 1, 1, act=False)) if s == 2 else nn.Identity()