def __init__(self, filters, activation, y_conditioned=False, splits=None): super(RefineNet, self).__init__() self.in_shape = None # Boolean is True when conditional information is concatenated to x self.y_conditioned = y_conditioned self.splits = splits self.increase_channels = layers.Conv2D(filters, kernel_size=3, padding="same") self.preact_1 = ConditionalFullPreActivationBlock(activation, filters, kernel_size=3) # FIXME: In this second preactivation block we used dilation=1, but it should have been 2 self.preact_2 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, pooling=True, dilation=2, padding=2) self.preact_3 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=2, padding=2) self.preact_4 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=4, padding=4) self.refine_block_1 = RefineBlock( activation, filters, n_blocks_crp=2, n_blocks_begin_rcu=2, n_blocks_end_rcu=3, ) self.refine_block_2 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_3 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_4 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.norm = ConditionalInstanceNormalizationPlusPlus2D() self.activation = activation self.decrease_channels = None
def __init__(self, filters, activation): super(ResNet, self).__init__() self.increase_channels = layers.Conv2D(filters, kernel_size=3, padding='same') self.res_enc1 = ConditionalResidualBlock(activation, filters, is_encoder=True) self.res_enc2 = ConditionalResidualBlock(activation, filters * 2, dilation=2, is_encoder=True, resize=True) self.res_enc3 = ConditionalResidualBlock(activation, filters * 2, dilation=2, is_encoder=True) self.res_enc4 = ConditionalResidualBlock(activation, filters * 4, dilation=2, is_encoder=True, resize=True) self.res_enc5 = ConditionalResidualBlock(activation, filters * 4, dilation=2, is_encoder=True) self.res_dec1 = ConditionalResidualBlock(activation, filters * 4, dilation=2, is_encoder=False) self.res_dec2 = ConditionalResidualBlock(activation, filters * 4, dilation=2, is_encoder=False, resize=True) self.res_dec3 = ConditionalResidualBlock(activation, filters * 2, dilation=2, is_encoder=False) self.res_dec4 = ConditionalResidualBlock(activation, filters * 2, dilation=2, is_encoder=False, resize=True) self.res_dec5 = ConditionalResidualBlock(activation, filters, is_encoder=False) self.norm = ConditionalInstanceNormalizationPlusPlus2D() self.activation = activation self.decrease_channels = None
def __init__(self, filters, activation): super(RefineNet, self).__init__() self.in_shape = None self.increase_channels = layers.Conv2D(filters, kernel_size=3, padding='same') self.preact_1 = ConditionalFullPreActivationBlock(activation, filters, kernel_size=3) # FIXME: In this second preactivation block we used dilation=1, but it should have been 2 self.preact_2 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, pooling=True) self.preact_3 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=2, padding=2) self.preact_4 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=4, padding=4) self.refine_block_1 = RefineBlock(activation, filters, n_blocks_crp=2, n_blocks_begin_rcu=2, n_blocks_end_rcu=3) self.refine_block_2 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_3 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_4 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.norm = ConditionalInstanceNormalizationPlusPlus2D() self.activation = activation self.decrease_channels = None
def __init__(self, activation, filters, is_encoder, kernel_size=3, dilation=1, resize=False): super(ConditionalResidualBlock, self).__init__() self.norm1 = ConditionalInstanceNormalizationPlusPlus2D() self.norm2 = ConditionalInstanceNormalizationPlusPlus2D() self.activation = activation self.resize = resize self.filters = filters self.is_encoder = is_encoder if is_encoder: self.conv1 = layers.Conv2D(filters, kernel_size, dilation_rate=(dilation, dilation), padding="same") self.conv2 = layers.Conv2D(filters, kernel_size, dilation_rate=(dilation, dilation), padding="same") else: self.conv1 = layers.Conv2DTranspose(filters, kernel_size, dilation_rate=(dilation, dilation), padding="same") self.conv2 = layers.Conv2DTranspose(filters, kernel_size, dilation_rate=(dilation, dilation), padding="same") self.adjust_skip = None
def __init__(self, filters, activation, splits, y_conditioned=False): super(MaskedRefineNet, self).__init__() self.in_shape = None self.filters = filters # Describes how to split the conditioning information # Assumes x is concatenated with its pixel-wise conditioning info self.splits = splits # Concatenate x,y too feed into RefineNet block # Encourages local per-pixel conditioning self.y_conditioned = y_conditioned # Filters used for every channel when dotting # dotting with conditioning block self.conditional_embedding_size = 256 self.increase_channels = layers.Conv2D(filters, kernel_size=3, padding="same") self.preact_1 = ConditionalFullPreActivationBlock(activation, filters, kernel_size=3) # FIXME: In this second preactivation block we used dilation=1, but it should have been 2 self.preact_2 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, pooling=True) self.preact_3 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=2, padding=2) self.preact_4 = ConditionalFullPreActivationBlock(activation, filters * 2, kernel_size=3, dilation=4, padding=4) self.refine_block_1 = RefineBlock( activation, filters, n_blocks_crp=2, n_blocks_begin_rcu=2, n_blocks_end_rcu=3, ) self.refine_block_2 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_3 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.refine_block_4 = RefineBlock(activation, filters * 2, n_blocks_crp=2, n_blocks_begin_rcu=2) self.norm = ConditionalInstanceNormalizationPlusPlus2D() self.activation = activation self.decrease_channels = None self.depth_extension = layers.Conv2D( self.conditional_embedding_size * self.splits[0], kernel_size=3, padding="same", ) # Added for conditioning block self.increase_conditional_channels = layers.Conv2D(filters, kernel_size=3, padding="same") # self.conditional_block = FullPreActivationBlock(activation, self.conditional_embedding_size*splits[0], kernel_size=3) self.conditional_block = FullPreActivationBlock( activation, self.conditional_embedding_size, kernel_size=3, dilation=2, padding=2, ) self.pool = GlobalAveragePooling2D(data_format="channels_last") self.dot = tf.keras.layers.Dot(axes=(4, 1), name="condition_dot")