def __init__(self, in_chs, out_chs, dilation=1, bottle_ratio=0.5, groups=1, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, attn_layer=None, aa_layer=None, drop_block=None, drop_path=None): super(DarkBlock_ACON, self).__init__() mid_chs = int(round(out_chs * bottle_ratio)) ckwargs = dict(act_layer=act_layer, norm_layer=norm_layer, aa_layer=aa_layer, drop_block=drop_block) self.conv1 = ConvBnAct(in_chs, mid_chs, kernel_size=1, **ckwargs) self.conv2 = Conv3x3_ACON(mid_chs, out_chs, kernel_size=3, dilation=dilation, groups=groups) self.attn = create_attn(attn_layer, channels=out_chs) self.drop_path = drop_path
def __init__(self, inplanes, planes, stride=1, downsample=None, cardinality=1, base_width=64, reduce_first=1, dilation=1, first_dilation=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, attn_layer=None, drop_block=None, drop_path=None): super(Bottleneck, self).__init__() width = int(math.floor(planes * (base_width / 64)) * cardinality) first_planes = width // reduce_first outplanes = planes * self.expansion first_dilation = first_dilation or dilation self.conv1 = nn.Conv2d(inplanes, first_planes, kernel_size=1, bias=False) self.bn1 = norm_layer(first_planes) self.act1 = act_layer(inplace=True) self.conv2 = nn.Conv2d( first_planes, width, kernel_size=3, stride=stride, padding=first_dilation, dilation=first_dilation, groups=cardinality, bias=False) self.bn2 = norm_layer(width) self.act2 = act_layer(inplace=True) self.conv3 = nn.Conv2d(width, outplanes, kernel_size=1, bias=False) self.bn3 = norm_layer(outplanes) self.se = create_attn(attn_layer, outplanes) self.act3 = act_layer(inplace=True) self.downsample = downsample self.stride = stride self.dilation = dilation self.drop_block = drop_block self.drop_path = drop_path
def __init__(self, inplanes, planes, stride=1, downsample=None, cardinality=1, base_width=64, reduce_first=1, dilation=1, first_dilation=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, attn_layer=None, drop_block=None, drop_path=None): super(BasicBlock, self).__init__() assert cardinality == 1, 'BasicBlock only supports cardinality of 1' assert base_width == 64, 'BasicBlock doest not support changing base width' first_planes = planes // reduce_first outplanes = planes * self.expansion first_dilation = first_dilation or dilation self.conv1 = nn.Conv2d( inplanes, first_planes, kernel_size=3, stride=stride, padding=first_dilation, dilation=first_dilation, bias=False) self.bn1 = norm_layer(first_planes) self.act1 = act_layer(inplace=True) self.conv2 = nn.Conv2d( first_planes, outplanes, kernel_size=3, padding=dilation, dilation=dilation, bias=False) self.bn2 = norm_layer(outplanes) self.se = create_attn(attn_layer, outplanes) self.act2 = act_layer(inplace=True) self.downsample = downsample self.stride = stride self.dilation = dilation self.drop_block = drop_block self.drop_path = drop_path
def __init__(self, inplanes, planes, stride=1, cardinality=1, base_width=64, reduce_first=1, dilation=1, first_dilation=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, attn_layer=None, aa_layer=None, drop_block=None, drop_path=None, fmap_size=56, up_inplanes=None): super(ResConv, self).__init__() width = int(math.floor(planes * (base_width / 64)) * cardinality) first_planes = width // reduce_first outplanes = planes * self.expansion first_dilation = first_dilation or dilation use_aa = aa_layer is not None and (stride == 2 or first_dilation != dilation) self.fmap_size = fmap_size if up_inplanes is not None: self.downsample_d = nn.Sequential( nn.Conv2d(up_inplanes, outplanes, 3, stride=2, padding=1, bias=False), nn.BatchNorm2d(outplanes), act_layer(inplace=True)) if inplanes != outplanes: self.downsample = nn.Sequential( nn.Conv2d(inplanes, outplanes, 1, stride=1, padding=0, bias=False), nn.BatchNorm2d(outplanes), act_layer(inplace=True)) else: self.downsample = nn.Identity() if up_inplanes is not None: self.conv1_d = nn.Conv2d(up_inplanes, first_planes, kernel_size=1, bias=False) self.peg_d = PEG(first_planes, stride=2) self.bn1_d = norm_layer(first_planes) self.conv1 = nn.Conv2d(inplanes, first_planes, kernel_size=1, bias=False) self.peg = PEG(first_planes, stride=1) self.bn1 = norm_layer(first_planes) self.act1 = act_layer(inplace=True) self.conv2 = nn.Conv2d( first_planes, width, kernel_size=3, stride=1 if use_aa else stride, padding=first_dilation, dilation=first_dilation, groups=cardinality, bias=False) self.bn2 = norm_layer(width) self.act2 = act_layer(inplace=True) self.aa = aa_layer(channels=width, stride=stride) if use_aa else None self.conv3 = nn.Conv2d(width, outplanes, kernel_size=1, bias=False) self.bn3 = norm_layer(outplanes) self.se = create_attn(attn_layer, outplanes) self.act3 = act_layer(inplace=True) self.stride = stride self.dilation = dilation self.drop_block = drop_block self.drop_path = drop_path self.inc = inplanes self.zero_init_last_bn()
def __init__(self, inplanes, planes, stride=1, cardinality=1, base_width=64, reduce_first=1, dilation=1, first_dilation=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, attn_layer=None, aa_layer=None, drop_block=None, drop_path=None, avg_down=False): super(ResConv, self).__init__() width = int(math.floor(planes * (base_width / 64)) * cardinality) first_planes = width // reduce_first outplanes = planes * self.expansion first_dilation = first_dilation or dilation use_aa = aa_layer is not None and (stride == 2 or first_dilation != dilation) # act_layer = nn.SiLU if avg_down and (stride == 2 or inplanes != outplanes): avg_stride = stride if dilation == 1 else 1 if stride == 1 and dilation == 1: pool = nn.Identity() else: avg_pool_fn = AvgPool2dSame if avg_stride == 1 and dilation > 1 else nn.AvgPool2d pool = avg_pool_fn(2, avg_stride, ceil_mode=True, count_include_pad=False) self.downsample = nn.Sequential(*[ pool, nn.Conv2d( inplanes, outplanes, 1, stride=1, padding=0, bias=False), norm_layer(outplanes) ]) else: if stride == 2: self.downsample = nn.Sequential( nn.Conv2d(inplanes, outplanes, 3, stride=2, padding=1, bias=False), norm_layer(outplanes), act_layer(inplace=True)) elif inplanes != outplanes: self.downsample = nn.Sequential( nn.Conv2d(inplanes, outplanes, 1, stride=1, padding=0, bias=False), norm_layer(outplanes), act_layer(inplace=True)) else: self.downsample = nn.Identity() self.conv1 = nn.Conv2d(inplanes, first_planes, kernel_size=1, bias=False) self.peg = PEG(first_planes, stride=stride) self.bn1 = norm_layer(first_planes) self.act1 = act_layer(inplace=True) self.conv2 = nn.Conv2d(first_planes, width, kernel_size=3, stride=1, padding=first_dilation, dilation=first_dilation, groups=cardinality, bias=False) self.bn2 = norm_layer(width) self.act2 = act_layer(inplace=True) self.aa = aa_layer(channels=width, stride=stride) if use_aa else None self.conv3 = nn.Conv2d(width, outplanes, kernel_size=1, bias=False) self.bn3 = norm_layer(outplanes) if attn_layer == 'se': self.se = create_attn(attn_layer, outplanes) else: self.se = None self.act3 = act_layer(inplace=True) # self.downsample = downsample self.stride = stride self.dilation = dilation self.drop_block = drop_block self.drop_path = drop_path self.inc = inplanes