def __init__(self, n_channles, n_filters, activation, num_sigmas, block_depth=2): super().__init__() self.activation = activation self.channels_to_filters = nn.Conv2d(n_channles, n_filters, kernel_size=3, padding=1) self.output_1_layer = ConvBlock(n_filters, n_filters, conv_before=False, activation=activation, num_sigmas=num_sigmas, kernel_size=3, residual=True, padding=1, block_depth=block_depth) self.output_2_layer = ConvBlock(n_filters, 2 * n_filters, conv_before=False, activation=activation, num_sigmas=num_sigmas, kernel_size=3, residual=True, block_depth=block_depth, pooling=True) self.output_3_layer = ConvBlock(2 * n_filters, 2 * n_filters, conv_before=False, activation=activation, num_sigmas=num_sigmas, kernel_size=3, dilation=2, padding=2, residual=True, block_depth=block_depth) self.output_4_layer = ConvBlock(2 * n_filters, 2 * n_filters, conv_before=False, activation=activation, num_sigmas=num_sigmas, kernel_size=3, dilation=4, padding=4, residual=True, block_depth=block_depth) self.refine_block4 = RefineBlock(2 * n_filters, 2 * n_filters, activation, num_sigmas, num_inputs=1) self.refine_block3 = RefineBlock(2 * n_filters, 2 * n_filters, activation, num_sigmas, num_inputs=2) self.refine_block2 = RefineBlock(2 * n_filters, 2 * n_filters, activation, num_sigmas, num_inputs=2) self.refine_block1 = RefineBlock(2 * n_filters, 2 * n_filters, activation, num_sigmas, num_inputs=2, in_channels_high=n_filters) self.output_layer = SequentialWithSigmas( ConditionalInstanceNormalizationPlusPlus(2 * n_filters, num_sigmas), activation(), nn.Conv2d(2 * n_filters, n_channles, kernel_size=3, padding=1) )
def __init__(self): #layers for the partial resnet self.layers = [ ConvLayer(d = 7,mi=3,mo=64,stride = 2,padding='SAME'), BatchNormLayer(64), ReluLayer(), MaxPoolLayer(3), ConvBlock(mi = 64,fm_sizes = [64,64,256],stride = 1) ] self.input_1 = tf.placeholder(dtype = tf.float32,shape = [None,224,224,3]) self.output1 = self.forward(self.input_1)
def __init__(self): self.conv_layer1 = ConvLayer(7, 3, 64, stride=2, padding='SAME') self.batch_norm1 = BatchNormLayer(64) self.relu_layer1 = ReluLayer() self.max_pool1 = MaxPoolLayer(3) self.conv_block1 = ConvBlock(64, mo=[64, 64, 256], stride=1) self.layers = [ self.conv_layer1, self.batch_norm1, self.relu_layer1, self.max_pool1, self.conv_block1 ]
def add_block_layer(self, n_layers, stride, out_channels): # stride_for_each_layer_list = [stride] concatonated with [1, 1, .....] stride_for_each_layer_list = [stride] + [1] * (n_layers - 1) layers = [] for stride in stride_for_each_layer_list: layers.append( ConvBlock(self.in_channels, out_channels, kernel_size=3, stride=stride, padding=1)) self.in_channels = out_channels return nn.Sequential(*layers)
def __init__(self): #1st block self.conv1 = ConvLayer(7, 3, 64, stride=2, padding='SAME') self.bn1 = BatchNormLayer(64) self.activation1 = ReluLayer() self.max_pool1 = MaxPoolLayer(3, stride=2) #2nd Block self.conv_block2a = ConvBlock(64, [64, 64, 256], stride=1) self.identity_block2b = IdentityBlock(256, [64, 64, 256]) self.identity_block2c = IdentityBlock(256, [64, 64, 256]) #3rd Block self.conv_block3a = ConvBlock(256, [128, 128, 512], stride=2) self.identity_block3b = IdentityBlock(512, [128, 128, 512]) self.identity_block3c = IdentityBlock(512, [128, 128, 512]) self.identity_block3d = IdentityBlock(512, [128, 128, 512]) #4th Block self.conv_block4a = ConvBlock(512, [256, 256, 1024], stride=2) self.identity_block4b = IdentityBlock(1024, [256, 256, 1024]) self.identity_block4c = IdentityBlock(1024, [256, 256, 1024]) self.identity_block4d = IdentityBlock(1024, [256, 256, 1024]) self.identity_block4e = IdentityBlock(1024, [256, 256, 1024]) self.identity_block4f = IdentityBlock(1024, [256, 256, 1024]) #5th Block self.conv_block5a = ConvBlock(1024, [512, 512, 2048], stride=2) self.identity_block5b = IdentityBlock(2048, [512, 512, 2048]) self.identity_block5c = IdentityBlock(2048, [512, 512, 2048]) #Final block self.avg_poolf = AvgPoolLayer(7, stride=7) self.flattenf = FlattenLayer() self.dense_layerf = DenseLayer(2048, 1000)