def __init__(self, block, layers, num_classes=21): self.inplanes = 64 super(ResNetLW, self).__init__() self.do = nn.Dropout(p=0.5) self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.layer1 = self._make_layer(block, 64, layers[0]) self.layer2 = self._make_layer(block, 128, layers[1], stride=2) self.layer3 = self._make_layer(block, 256, layers[2], stride=2) self.layer4 = self._make_layer(block, 512, layers[3], stride=2) self.p_ims1d2_outl1_dimred = conv1x1(2048, 512, bias=False) self.mflow_conv_g1_pool = self._make_crp(512, 512, 4) self.mflow_conv_g1_b3_joint_varout_dimred = conv1x1(512, 256, bias=False) self.p_ims1d2_outl2_dimred = conv1x1(1024, 256, bias=False) self.adapt_stage2_b2_joint_varout_dimred = conv1x1(256, 256, bias=False) self.mflow_conv_g2_pool = self._make_crp(256, 256, 4) self.mflow_conv_g2_b3_joint_varout_dimred = conv1x1(256, 256, bias=False) self.p_ims1d2_outl3_dimred = conv1x1(512, 256, bias=False) self.adapt_stage3_b2_joint_varout_dimred = conv1x1(256, 256, bias=False) self.mflow_conv_g3_pool = self._make_crp(256, 256, 4) self.mflow_conv_g3_b3_joint_varout_dimred = conv1x1(256, 256, bias=False) self.p_ims1d2_outl4_dimred = conv1x1(256, 256, bias=False) self.adapt_stage4_b2_joint_varout_dimred = conv1x1(256, 256, bias=False) self.mflow_conv_g4_pool = self._make_crp(256, 256, 4) self.up1 = nn.ConvTranspose2d(256,256,2,2) self.up2 = nn.ConvTranspose2d(256,256,2,2) self.up3 = nn.ConvTranspose2d(256,256,2,2) self.clf_conv = nn.Conv2d( 256, num_classes, kernel_size=3, stride=1, padding=1, bias=True )
def __init__(self, in_channels): super(MMFNet, self).__init__() self.do = nn.Dropout(p=0.5) # these next blocks are the same for both RGB and HHA because # the input volumes are exactly the same dimensions (including # channels) # conv3 is also used for the convolution before and after fusion # pre-fusion RGB blocks self.conv1_rgb = conv1x1(in_planes=in_channels, out_planes=in_channels) self.RCUs_rgb = nn.Sequential( # 2 RCU blocks BasicBlock(inplanes=in_channels, planes=in_channels), # expansion=1, no downsampling BasicBlock(inplanes=in_channels, planes=in_channels) # expansion=1, no downsampling ) self.conv3_rgb = conv3x3(in_planes=in_channels, out_planes=in_channels) # pre-fusion HHA blocks self.conv1_hha = conv1x1(in_planes=in_channels, out_planes=in_channels) self.RCUs_hha = nn.Sequential( # 2 RCU blocks BasicBlock(inplanes=in_channels, planes=in_channels), # expansion=1, no downsampling BasicBlock(inplanes=in_channels, planes=in_channels) # expansion=1, no downsampling ) self.conv3_hha = conv3x3(in_planes=in_channels, out_planes=in_channels) # post-fusion block #self.maxpool = nn.MaxPool2d(kernel_size=5, stride=1) #self.conv3 = conv3x3(in_planes=in_channels, out_planes=in_channels) self.crp = CRPBlock(in_planes=in_channels, out_planes=in_channels, n_stages=1)
def __init__(self, num_classes): super(MBv2, self).__init__() self.layer1 = convbnrelu(3, self.in_planes, kernel_size=3, stride=2) c_layer = 2 for t,c,n,s in (self.mobilenet_config): layers = [] for idx in range(n): layers.append(InvertedResidualBlock(self.in_planes, c, expansion_factor=t, stride=s if idx == 0 else 1)) self.in_planes = c setattr(self, 'layer{}'.format(c_layer), nn.Sequential(*layers)) c_layer += 1 ## Light-Weight RefineNet ## self.conv8 = conv1x1(320, 256, bias=False) self.conv7 = conv1x1(160, 256, bias=False) self.conv6 = conv1x1(96, 256, bias=False) self.conv5 = conv1x1(64, 256, bias=False) self.conv4 = conv1x1(32, 256, bias=False) self.conv3 = conv1x1(24, 256, bias=False) self.crp4 = self._make_crp(256, 256, 4) self.crp3 = self._make_crp(256, 256, 4) self.crp2 = self._make_crp(256, 256, 4) self.crp1 = self._make_crp(256, 256, 4) self.conv_adapt4 = conv1x1(256, 256, bias=False) self.conv_adapt3 = conv1x1(256, 256, bias=False) self.conv_adapt2 = conv1x1(256, 256, bias=False) self.segm = conv3x3(256, num_classes, bias=True) self.relu = nn.ReLU6(inplace=True) self._initialize_weights()
def __init__(self, block, layers, num_classes=40): #21): super(ResNet, self).__init__() self.do = nn.Dropout(p=0.5) self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.conv1_depth = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(64) self.bn1_depth = nn.BatchNorm2d(64) #self.relu = nn.ReLU(inplace=True) -- switched to F.relu to avoid errors self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) # backbone self.inplanes = 64 self.layer1 = self._make_layer(block, 64, layers[0]) self.layer2 = self._make_layer(block, 128, layers[1], stride=2) self.layer3 = self._make_layer(block, 256, layers[2], stride=2) self.layer4 = self._make_layer(block, 512, layers[3], stride=2) self.inplanes = 64 self.layer1_depth = self._make_layer(block, 64, layers[0]) self.layer2_depth = self._make_layer(block, 128, layers[1], stride=2) self.layer3_depth = self._make_layer(block, 256, layers[2], stride=2) self.layer4_depth = self._make_layer(block, 512, layers[3], stride=2) # dimensionality reduction right off the backbone # note that for some reason, x4 uses the outl1 block, x3 uses outl2, etc # I would like to rename these as well, but I think the names are used for some other stuff self.p_ims1d2_outl1_dimred = conv1x1(2048, 512, bias=False) # really l4 self.p_ims1d2_outl2_dimred = conv1x1(1024, 256, bias=False) # really l3 self.p_ims1d2_outl3_dimred = conv1x1(512, 256, bias=False) # really l2 self.p_ims1d2_outl4_dimred = conv1x1(256, 256, bias=False) # really l1 self.p_ims1d2_outl1_dimred_depth = conv1x1(2048, 512, bias=False) # really l4 self.p_ims1d2_outl2_dimred_depth = conv1x1(1024, 256, bias=False) # really l3 self.p_ims1d2_outl3_dimred_depth = conv1x1(512, 256, bias=False) # really l2 self.p_ims1d2_outl4_dimred_depth = conv1x1(256, 256, bias=False) # really l1 # MMFNets self.MMFNet_l4 = MMFNet(in_channels=512) self.MMFNet_l3 = MMFNet(in_channels=256) self.MMFNet_l2 = MMFNet(in_channels=256) self.MMFNet_l1 = MMFNet(in_channels=256) # RefineNets self.RefineNet_l4 = RefineNet(inplanes_lr=512) # no fusion step self.RefineNet_l4_l3 = RefineNet(inplanes_lr=512, inplanes_hr=256, fancy_upsample=True) self.RefineNet_l3_l2 = RefineNet(inplanes_lr=256, inplanes_hr=256, fancy_upsample=True) self.RefineNet_l2_l1 = RefineNet(inplanes_lr=256, inplanes_hr=256, fancy_upsample=True) # CLF convolutional step applied to layer 1 output to get class predictions self.clf_conv = nn.Conv2d(256, num_classes, kernel_size=3, stride=1, padding=1, bias=True)