Example #1
0
def hourglass_module(inpt, n_classes, n_channles):
    x = inpt
    features = [x]  # from x4 to x64
    n_levels = len(n_channles)
    # encoder: s1 residual + s2 residual
    for i in range(n_levels):
        if i != 0:
            x = residual(x, n_channles[i], strides=1)
            features.append(x)
        if i != n_levels - 1:
            x = residual(x, n_channles[i + 1], strides=2)

    # mid connection: 4 residuals
    for i in range(4):
        x = residual(x, n_channles[-1], strides=1)

    # decoder:
    for i in range(n_levels - 2, -1, -1):
        # skip: 2 residuals
        skip = features[i]
        skip = residual(skip, n_channles[i], strides=1)
        skip = residual(skip, n_channles[i], strides=1)
        # features
        x = residual(x, n_channles[i])
        x = residual(x, n_channles[i])
        x = UpSampling2D()(x)
        # add
        x = add([x, skip])

    # head branches
    x_intermediate = Conv2D(n_classes,
                            1,
                            strides=1,
                            padding='same',
                            activation='sigmoid')(x)
    input_branch = Conv2D(n_channles[0],
                          1,
                          strides=1,
                          padding='same',
                          use_bias=False)(inpt)
    output_branch = Conv2D(n_channles[0],
                           1,
                           strides=1,
                           padding='same',
                           use_bias=False)(x)
    x = add([input_branch, output_branch])
    x = ReLU()(x)

    return x, x_intermediate
Example #2
0
def separable(x, filters_pw, block_num, strides=(1, 1), trainable=True):
    if strides != (1, 1):
        x = ZeroPadding2D(((0, 1), (0, 1)), name='conv_pad_%d' % block_num)(x)
    x = DepthwiseConv2D(kernel_size=(3, 3),
                        strides=strides,
                        padding='same' if strides == (1, 1) else 'valid',
                        use_bias=False,
                        depthwise_initializer=glorot_uniform(),
                        trainable=trainable,
                        name='conv_dw_%d' % block_num)(x)
    x = BatchNormalization(trainable=trainable, name='conv_dw_%d_bn' % block_num)(x)
    x = ReLU(6., name='conv_dw_%d_relu' % block_num)(x)

    x = Conv2D(filters=filters_pw,
               kernel_size=(1, 1),
               strides=(1, 1),
               padding='same',
               use_bias=False,
               kernel_initializer=glorot_uniform(),
               trainable=trainable,
               name='conv_pw_%d' % block_num)(x)
    x = BatchNormalization(trainable=trainable, name='conv_pw_%d_bn' % block_num)(x)
    x = ReLU(6., name='conv_pw_%d_relu' % block_num)(x)
    return x
Example #3
0
def temporal_and_mask_multi_propagation(inputs, inputs_image_keys, inputs_mask_keys):
    x1 = temporal_propagation(inputs_image_keys)
    x1_multi = []
    for i in range(len(inputs_image_keys)):
        x1_multi.append(ReLU(name="x1_" + str(i))(x1))

    x2 = mask_propagation(inputs_mask_keys)
    x2_multi = []
    for i in range(len(inputs_mask_keys)):
        x2_multi.append(ReLU(name="x2_" + str(i))(x2))
    x = Conv2D_BN_Relu(inputs, 256, kernel_size=(3, 3), name="input_downsample", padding="valid",
                       strides=(2, 2))
    x, x1, x2 = triple_multi_attention(x, x1_multi, x2_multi, name="tri_multi_attention")
    add = Add(name="TMPropp_add")
    relu = ReLU(name="TMProp_relu")
    res = []
    for f1, f2 in zip(x1, x2):
        x = add([f1, f2])
        x = relu(x)
        res.append(x)
    x = Add(name="TMProp_output_add")([x] + res)
    x = ReLU(name="TMProp_output_relu")(x)
    x = Conv2D_BN_Relu(x, 256, (3, 3), "output", padding="same")
    return x
Example #4
0
def triple_single_attention(inputs, inputs_image_keys, inputs_mask_keys, name):
    x = Conv2D_BN_Relu(inputs, 64, kernel_size=(3, 3), name=name + "_input_a", padding="same", strides=(1, 1))
    x1 = Conv2D_BN_Relu(inputs_image_keys, 64, kernel_size=(3, 3), name=name + "_images_a", padding="same",
                        strides=(1, 1))
    x2 = Conv2D_BN_Relu(inputs_mask_keys, 64, kernel_size=(3, 3), name=name + "_masks_a", padding="same",
                        strides=(1, 1))
    x1 = Add(name=name + "_image_add")([x, x1])
    x1 = ReLU(name=name + "_image_relu")(x1)

    x2 = Add(name=name + "_mask_add")([x, x2])
    x2 = ReLU(name=name + "_mask_relu")(x2)
    x1 = Conv2D_BN_Relu(x1, 64, kernel_size=(3, 3), name=name + "_image_b", padding="same", strides=(1, 1))
    x2 = Conv2D_BN_Relu(x2, 64, kernel_size=(3, 3), name=name + "_mask_b", padding="same", strides=(1, 1))
    f = Multiply(name=name + "_multiply")([x1, x2])
    x1 = Add(name=name + "_image_output_add1")([x1, f])
    x1 = ReLU(name=name + "_image_output_relu1")(x1)

    x2 = Add(name=name + "_image_output_add2")([x2, f])
    x2 = ReLU(name=name + "_image_output_relu2")(x2)

    x = Add(name=name + "_output_add")([x, f])
    x = ReLU(name=name + "_output_relu")(x)

    return x, x1, x2
Example #5
0
def ch_CNN(layer):
    # layer=BatchNormalization()(layer)
    """
    layer=Conv2D(16,(3,3))(layer)
    layer=se_block(16,layer)
    layer=BatchNormalization()(layer)
    layer=ReLU()(layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(16,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(32,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(64,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)
    """

    layer = Conv2D(64, (5, 5), padding='same')(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    # layer=se_block(64,layer)
    layer = Conv2D(128, (3, 3), padding='same')(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    # layer=se_block(128,layer)
    layer = Conv2D(256, (3, 3), padding='same')(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    # layer=se_block(256,layer)

    return layer
Example #6
0
def ch_CNN(layer):
    # layer=BatchNormalization()(layer)
    """
    layer=Conv2D(16,(3,3))(layer)
    layer=se_block(16,layer)
    layer=BatchNormalization()(layer)
    layer=ReLU()(layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(16,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(32,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)

    layer=res_block(64,layer)
    layer=MaxPooling2D(pool_size=(2,2))(layer)
    """

    layer = Conv2D(16, (2, 2))(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    layer = se_block(16, layer)
    layer = Conv2D(32, (3, 3))(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    layer = se_block(32, layer)
    layer = Conv2D(64, (3, 3))(layer)
    # layer=BatchNormalization()(layer)
    layer = ReLU()(layer)
    layer = MaxPooling2D(pool_size=(2, 2))(layer)
    layer = se_block(64, layer)

    return layer
    def _build_inverse_net(self):
        inputs = Input(
            [self._input_size[0] // 4, self._input_size[1] // 4, 256])

        def instance_norm(inputs):
            return tf.contrib.layers.instance_norm(inputs)

        # assume x as shape[None, w/4, h/4, 256]
        x = Conv2D(filters=128, kernel_size=3, padding='same',
                   use_bias=False)(inputs)
        x = Lambda(instance_norm)(x)
        x = ReLU()(x)

        # upsample to [w/2, h/2]
        x = UpSampling2D()(x)
        x = Conv2D(filters=128, kernel_size=3, padding='same',
                   use_bias=False)(x)
        x = Lambda(instance_norm)(x)
        x = ReLU()(x)

        x = Conv2D(filters=64, kernel_size=3, padding='same',
                   use_bias=False)(x)
        x = Lambda(instance_norm)(x)
        x = ReLU()(x)

        # upsample to [w, h]
        x = UpSampling2D()(x)
        x = Conv2D(filters=64, kernel_size=3, padding='same',
                   use_bias=False)(x)
        x = Lambda(instance_norm)(x)
        x = ReLU()(x)

        x = Conv2D(filters=3, kernel_size=3, padding='same',
                   activation='relu')(x)

        self.inverse_net = Model(inputs, x)
Example #8
0
def build_policy_head(head_base, num_classes, head_name):
    x = Conv2D(2,
               kernel_size=(1, 1),
               padding='same',
               kernel_regularizer=l2(L2_WEIGHT_DECAY))(head_base)
    x = BatchNormalization()(x)
    x = ReLU()(x)
    x = Flatten()(x)

    policy_head = Dense(num_classes,
                        activation='softmax',
                        name=head_name,
                        kernel_regularizer=l2(L2_WEIGHT_DECAY),
                        bias_regularizer=l2(L2_WEIGHT_DECAY))(x)
    return policy_head
Example #9
0
def depthwise_conv_block(input, conv_filter, depth_multiplier, strides=(1, 1)):

    if strides == (1, 1):
        x = input
        padding_type = 'same'
    else:
        x = ZeroPadding2D(padding=((1, 1), (1, 1)))(input)
        padding_type = 'valid'

    x = DepthwiseConv2D((3, 3),
                        padding=padding_type,
                        depth_multiplier=depth_multiplier,
                        strides=strides,
                        use_bias=False)(x)
    x = BatchNormalization()(x)
    x = ReLU(6.)(x)
    x = Conv2D(conv_filter, (1, 1),
               padding='same',
               use_bias=False,
               strides=(1, 1))(x)

    x = BatchNormalization()(x)

    return ReLU(6.)(x)
Example #10
0
def identity_block(input_tensor, pointwise_conv_filters, alpha, depth_multiplier=1, strides=(1, 1), block_id='1'):
    
    channel_axis = 1 if image_data_format() == 'channels_first' else -1
    pointwise_conv_filters = int(pointwise_conv_filters * alpha)

    x = input_tensor
    x = DepthwiseConv2D(kernel_size=(3, 3),
                        padding='same',
                        depth_multiplier=depth_multiplier,
                        strides=strides,
                        use_bias=False,
                        name='identity_conv_dw_%s' % block_id)(x)
    x = BatchNormalization(axis=channel_axis, name='identity_conv_dw_%s_bn' % block_id)(x)
    x = ReLU(name='identity_conv_dw_%s_relu' % block_id)(x)
    x = Conv2D(filters=pointwise_conv_filters, 
               kernel_size=(1, 1),
               padding='same',
               use_bias=False,
               strides=(1, 1),
               name='identity_conv_pw_%s' % block_id)(x)
    x = BatchNormalization(axis=channel_axis, name='identity_conv_pw_%s_bn' % block_id)(x)
    x = ReLU(name='identity_conv_pw_%s_relu' % block_id)(x)

    return x
def build_generator():
  gen_model = Sequential()

  gen_model.add(Dense(input_dim = 100, output_dim = 2048))
  gen_model.add(ReLU())
  
  gen_model.add(Dense(256 * 8 * 8))
  gen_model.add(BatchNormalization())
  gen_model.add(ReLU())
  gen_model.add(Reshape((8, 8, 256), input_shape = (256 * 8 * 8,)))
  gen_model.add(UpSampling2D(size=(2,2)))

  gen_model.add(Conv2D(128,(5,5),padding = 'same'))
  gen_model.add(ReLU())
  gen_model.add(UpSampling2D(size = (2,2)))

  gen_model.add(Conv2D(64,(5,5),padding = 'same'))
  gen_model.add(ReLU())
  gen_model.add(UpSampling2D(size=(2,2)))

  gen_model.add(Conv2D(3,(5,5),padding = 'same'))
  gen_model.add(Activation('tanh'))

  return gen_model
Example #12
0
def ConvBlock(inputs, n_filters, kernel_size=[3, 3]):
    """
    Basic conv block for Encoder-Decoder
    Apply successivly Convolution, BatchNormalization, ReLU nonlinearity
    """
    
    net = Conv2D(n_filters, kernel_size, padding='same')(inputs)
    net = BatchNormalization()(net)
    net = ReLU()(net)
    
    # TODO: Check order!
    
#    net = tf.nn.relu(slim.batch_norm(inputs, fused=True))
#    net = slim.conv2d(net, n_filters, kernel_size, activation_fn=None, normalizer_fn=None)
    return net
Example #13
0
def ConvUpscaleBlock(inputs, n_filters, kernel_size=[3, 3], scale=2):
    """
    Basic conv transpose block for Encoder-Decoder upsampling
    Apply successivly Transposed Convolution, BatchNormalization, ReLU nonlinearity
    """
    
    net = Conv2DTranspose(n_filters, kernel_size, strides = (scale,scale))(inputs)
    net = BatchNormalization()(net)
    net = ReLU()(net)
    
    # TODO: Check order!
    
#    net = tf.nn.relu(slim.batch_norm(inputs, fused=True))
#    net = slim.conv2d_transpose(net, n_filters, kernel_size=[3, 3], stride=[scale, scale], activation_fn=None)
    return net
Example #14
0
 def stub(x):
     # if latent_filters is None:
     #     latent_filters = K.int_shape(x)[-1]
     y = Conv2D(latent_filters, (1, 1), padding='same')(x)
     y = ReLU(max_value=ReLU_Max)(y)
     y = SeperableConvBlock(output_filters=output_filters,
                            ReLU_Max=ReLU_Max,
                            strides=strides)(y)
     if skipFunction is not None:
         if strides is not (1, 1):
             print("Strides can't be used with attention")
         x = skipFunction([x, y])
         return x
     else:
         return y
Example #15
0
def vdcnn():
    model = Sequential()
    model.add(Lambda(encode, input_shape=(None,), input_dtype='uint8', output_shape=(None, len(tokens))))
    model.add(Conv1D(filters=64, kernel_size=3))
    model.add(BatchNormalization())
    blocks = [64, 64, 128, 128, 256, 256, 512, 512]
    pools = range(1, len(blocks), 2)
    for i in range(len(blocks)):
        filter_size = blocks[i]
        model.add(Conv1D(filters=filter_size, kernel_size=3))
        model.add(BatchNormalization())
        model.add(ReLU())
        model.add(Conv1D(filters=filter_size, kernel_size=3))
        model.add(BatchNormalization())
        model.add(ReLU())
        if i in pools and i < len(blocks) - 1:
            model.add(MaxPooling1D(pool_size=3, strides=2))
    model.add(GlobalMaxPooling1D())
    model.add(Dense(2048, activation='relu'))
    model.add(BatchNormalization())
    model.add(Dense(2048, activation='relu'))
    model.add(BatchNormalization())
    model.add(Dense(1, activation='sigmoid'))
    return model
Example #16
0
def InvertedRes(input, expansion):
    '''
    Args:
        input: input tensor
        expansion: expand filters size
    Output:
        output: output tensor
    '''
    #Pointwise Convolution
    x = Conv2D(expansion*3,(1,1), padding='same')(input)
    x = BatchNormalization()(x)
    x = ReLU()(x) 
    #Depthwise Convolution
    x = DepthwiseConv2D((3,3), padding='same')(x)
    x = BatchNormalization()(x)
    x = ReLU()(x)
    #Pointwise Convolution
    x = Conv2D(3,(1,1))(x)
    x = BatchNormalization()(x)
    x = linear(x)

    x = Add()([x, input])
    
    return x
Example #17
0
    def __init__(self,
                 filters,
                 kernel_size,
                 gp_num=3,
                 pad_type="constant",
                 **kwargs):
        super(FlatConv, self).__init__(name="FlatConv")
        padding = (kernel_size - 1) // 2
        padding = (padding, padding)
        self.model = tf.keras.models.Sequential()
        self.model.add(get_padding(pad_type, padding))

        self.model.add(GroupNormalization(groups=gp_num, axis=-1))
        self.model.add(Conv2D(filters, kernel_size))
        self.model.add(ReLU())
Example #18
0
    def __new__(self, inputs, filters, l2_reg):
        from keras.layers import Conv2D, add, BatchNormalization, ReLU
        from keras.regularizers import l2

        residual = inputs

        conv_1 = Conv2D(filters, (4, 4),
                        padding='same',
                        use_bias=False,
                        kernel_regularizer=l2(l2_reg))(inputs)

        norm_1 = BatchNormalization()(conv_1)
        relu_1 = ReLU()(norm_1)

        conv_2 = Conv2D(filters, (4, 4),
                        padding='same',
                        use_bias=False,
                        kernel_regularizer=l2(l2_reg))(relu_1)

        norm_2 = BatchNormalization()(conv_2)
        out = add([residual, norm_2])
        out = ReLU()(out)

        return out
Example #19
0
    def __init__(self,
                 input_shape,
                 num_classes=20,
                 num_hidden=1,
                 hidden_size=500,
                 include_relu=False,
                 weights=None):

        super().__init__(input_shape, num_classes=num_classes)

        model_input = Input(shape=input_shape)
        model = Dense(hidden_size)(model_input)
        model = BatchNormalization()(model)
        model = ReLU()(model)
        if num_hidden > 1:
            for i in range(num_hidden - 1):
                model = Dense(hidden_size)(model)
                model = BatchNormalization()(model)
                model = ReLU()(model)
        model = Dense(self.num_classes)(model)
        if include_relu:
            model = ReLU()(model)

        self.model = Model(inputs=model_input, outputs=model)
Example #20
0
def conv_block(x, filters=64, strides=1, n_blocks=3):
    inpt = x
    inpt = Conv_BN(x,
                   filters * 4,
                   kernel_size=1,
                   strides=strides,
                   activation=False)
    for i in range(n_blocks):
        stride = strides if i == 0 else 1
        x = Conv_BN(x, filters, kernel_size=1, strides=stride, activation=True)
        x = Conv_BN(x, filters, kernel_size=3, strides=1, activation=True)
        x = Conv_BN(x, filters * 4, kernel_size=1, strides=1, activation=False)
    x = add([x, inpt])
    x = ReLU()(x)
    return x
 def _bottleneck(inputs, filters, kernel, t, s, r=False):
     channel_axis = 1 if K.image_data_format() == 'channels_first' else -1
     tchannel = K.int_shape(inputs)[channel_axis] * t
     x = _conv_block(inputs, tchannel, (1, 1), (1, 1))
     x = DepthwiseConv2D(kernel,
                         strides=(s, s),
                         depth_multiplier=1,
                         padding='same')(x)
     x = BatchNormalization(axis=channel_axis)(x)
     x = ReLU(6.0)(x)
     x = Conv2D(filters, (1, 1), strides=(1, 1), padding='same')(x)
     x = BatchNormalization(axis=channel_axis)(x)
     if r:
         x = add([x, inputs])
     return x
Example #22
0
def Conv_BN(x,
            filters,
            kernel_size,
            strides,
            activation=True,
            dilation_rate=1):
    x = Conv2D(filters,
               kernel_size,
               strides=strides,
               padding='same',
               dilation_rate=dilation_rate)(x)
    x = BatchNormalization()(x)
    if activation:
        x = ReLU()(x)
    return x
        def class_encoder_k(shape):
            Y_input = Input(shape=shape)

            Y = Conv2D(64, kernel_size=1, strides=1, padding='same')(Y_input)
            Y = ReLU()(Y)

            Y = Conv2D(128, kernel_size=1, strides=2, padding='same')(Y)
            Y = ReLU()(Y)

            Y = Conv2D(256, kernel_size=1, strides=2, padding='same')(Y)
            Y = ReLU()(Y)

            Y = Conv2D(512, kernel_size=1, strides=2, padding='same')(Y)
            Y = ReLU()(Y)

            Y = Conv2D(1024, kernel_size=1, strides=2, padding='same')(Y)
            Y = ReLU()(Y)

            Y = AveragePooling2D()(Y)

            #     Y = Dense(512)(Y)
            Y = Flatten()(Y)

            return Y
Example #24
0
    def __create_g_input(self):
        """Create generator input shape"""

        n_filters = self.filter_shape_list[0]
        img_shape = self.img_shape_list[0]
        input_shape = n_filters * img_shape * img_shape

        logging.debug(f'G_input: {n_filters, img_shape}')

        model = Sequential()
        model.add(Dense(input_shape, input_shape=(self.latent_shape,)))
        model.add(ReLU())
        model.add(Reshape((img_shape, img_shape, n_filters)))
        model.name = 'GENERATOR_INPUT'
        return model
Example #25
0
def build_model(DropoutRatio=0.5):
    capacity = 16
    input_layer = Input((28, 28, 1))
    # 28 * 28
    conv1 = Conv2D(32, (3, 3), padding="same")(input_layer)
    conv1 = ReLU()(conv1)

    # 14*14
    conv1 = Conv2D(64, (3, 3), padding="same")(conv1)
    conv1 = ReLU()(conv1)

    conv1 = MaxPooling2D(pool_size=(2, 2))(conv1)

    flatten = Flatten()(conv1)

    dense = Dense(128)(flatten)
    dense = ReLU()(dense)

    dense = Dense(10)(dense)
    softmax = Softmax()(dense)

    model = Model(input_layer, softmax)

    return model
Example #26
0
def p3d_resblock_a(inpt, filters, strides=1, padding='same'):
    x = ConvBN(inpt,
               filters // 4,
               kernel_size=1,
               strides=strides,
               activation='relu')
    x = ConvBN(x, filters // 4, kernel_size=(1, 3, 3), activation='relu')
    x = ConvBN(x, filters // 4, kernel_size=(3, 1, 1), activation='relu')
    x = ConvBN(x, filters, kernel_size=1, activation=None)

    if strides != 1 or inpt._keras_shape[-1] != filters:
        inpt = ConvBN(inpt, filters, 1, strides=strides, activation=None)
    x = add([x, inpt])
    x = ReLU()(x)
    return x
Example #27
0
def triple_multi_attention(inputs, inputs_image_keys, inputs_mask_keys, name):
    x = Conv2D_BN_Relu(inputs, 64, kernel_size=(3, 3), name=name + "_input_a", padding="same", strides=(1, 1))
    inputs_image_keys = multi_input_Conv2D_BN_Relu(inputs_image_keys, 64, kernel_size=(3, 3), name=name + "_images_a",
                                                   padding="same", strides=(1, 1))
    inputs_mask_keys = multi_input_Conv2D_BN_Relu(inputs_mask_keys, 64, kernel_size=(3, 3), name=name + "_masks_a",
                                                  padding="same", strides=(1, 1))

    f1 = []
    f2 = []
    for i, (x1, x2) in enumerate(zip(inputs_image_keys, inputs_mask_keys)):
        x1 = Add(name=name + "_image_add_" + str(i))([x, x1])
        x1 = ReLU(name=name + "_image_relu_" + str(i))(x1)
        f1.append(x1)
        x2 = Add(name=name + "_mask_add_" + str(i))([x, x2])
        x2 = ReLU(name=name + "_mask_relu_" + str(i))(x2)
        f2.append(x2)
    f1 = multi_input_Conv2D_BN_Relu(f1, 64, kernel_size=(3, 3), name=name + "_images_b", padding="same", strides=(1, 1))
    f2 = multi_input_Conv2D_BN_Relu(f2, 64, kernel_size=(3, 3), name=name + "_masks_b", padding="same", strides=(1, 1))
    res = []
    add = Add(name=name + "_output_add")
    relu = ReLU(name=name + "_output_relu")
    output_image_features = []
    output_mask_features = []
    for i, (f1_v, f2_v) in enumerate(zip(f1, f2)):
        f = Multiply(name=name + "_multiply_" + str(i))([f1_v, f2_v])
        f1_v = Add(name=name + "_image_output_add_" + str(i))([f1_v, f])
        f1_v = ReLU(name=name + "_image_output_relu_" + str(i))(f1_v)
        output_image_features.append(f1_v)
        f2_v = Add(name=name + "_mask_output_add_" + str(i))([f2_v, f])
        f2_v = ReLU(name=name + "_mask_output_relu_" + str(i))(f2_v)
        output_mask_features.append(f2_v)

        x = add([x, f])
        x = relu(x)
    outputs = x
    return outputs, output_image_features, output_mask_features
Example #28
0
    def generator_model(self):
        generator_input = keras.Input(shape=(self.latent_dim, ))

        x = Dense(128 * 32 * 32)(generator_input)
        x = ReLU()(x)
        x = Reshape((32, 32, 128))(x)

        x = Conv2D(256, 5, padding='same')(x)
        x = ReLU()(x)

        x = Conv2DTranspose(256, 4, strides=2, padding='same')(x)
        x = ReLU()(x)

        x = Conv2D(256, 5, padding='same')(x)
        x = ReLU()(x)
        x = Conv2D(256, 5, padding='same')(x)
        x = ReLU()(x)

        x = Conv2D(self.channels, 7, activation='tanh', padding='same')(x)
        generator = keras.models.Model(generator_input, x)
        # generator.summary()
        print("Generator built")

        return generator
Example #29
0
def multi_input_Atrous_Conv2D_BN_Relu(input_list, filters, kernel_size, name, padding, dilation_rate, strides=(1, 1),
                                      use_bias=True):
    h_kernel, w_kernel = kernel_size
    conv = Conv2D(filters, (h_kernel, w_kernel), strides=strides, padding=padding, dilation_rate=dilation_rate,
                  name=name + "_atrous_conv2d",
                  use_bias=use_bias)
    bn = BatchNormalization(name=name + "_bn")

    features = []
    for i, x in enumerate(input_list):
        x = conv(x)
        x = bn(x)
        x = ReLU(name=name + "_relu_" + str(i))(x)
        features.append(x)
    return features
Example #30
0
def residual_layer(input_block):
    x = Conv2D(filters=RESIDUAL_LAYER_PARAMETERS["filters"],
               kernel_size=RESIDUAL_LAYER_PARAMETERS["kernel_size"],
               padding=RESIDUAL_LAYER_PARAMETERS["padding"],
               data_format="channels_first",
               kernel_regularizer=RESIDUAL_LAYER_PARAMETERS["kernel_regularizer"]
    )(input_block)

    x = BatchNormalization(axis=1)(x)

    x = Add()([input_block, x])

    x = ReLU()(x)

    return x  # Are the parentheses needed?