Ejemplo n.º 1
0
def create_generator(input_shape):
    input_vec = Input(input_shape, name='input')
    x = Dense(128 * 4 * 4, activation='tanh', name='dense')(input_vec)
    x = BatchNormalization()(x)
    x = Reshape((4, 4, 128))(x)
    x = Conv2DTranspose(512, (3, 3),
                        strides=2,
                        activation=tf.nn.leaky_relu,
                        padding='same',
                        name='de_conv_1')(x)
    x = Conv2DTranspose(256, (3, 3),
                        strides=2,
                        activation=tf.nn.leaky_relu,
                        padding='same',
                        name='de_conv_2')(x)
    x = Conv2DTranspose(128, (3, 3),
                        strides=2,
                        activation=tf.nn.leaky_relu,
                        padding='same',
                        name='de_conv_3')(x)
    output = Conv2D(3, (3, 3),
                    activation='tanh',
                    padding='same',
                    name='conv_2')(x)

    model = Model(input_vec, outputs=output)

    return model
Ejemplo n.º 2
0
def FCN8(nClasses,input_height,input_width):

    # model = vgg16.VGG16(include_top=False,weights='imagenet',input_tensor=img_input)
    # vgg去除全连接层为:7x7x512
    # vgg:5个block,1:filters:64,kernel:3;3-128;3-256;3-512
    model = FCN32(11, 320, 320)
    model.load_weights("model.h5")


    skip1 = Conv2DTranspose(512,kernel_size=(3,3),strides=(2,2),padding='same',kernel_initializer="he_normal",name="up7")(model.get_layer("fc7").output)
    # skip2 = Conv2DTranspose(256,kernel_size=(3,3),strides=(2,2),padding='same',kernel_initializer="he_normal",name="up4")(model.get_layer('block4_pool').output)

    summed = add(inputs=[skip1,model.get_layer("block4_pool").output])
    skip2 = Conv2DTranspose(256,kernel_size=(3,3),strides=(2,2),padding='same',kernel_initializer="he_normal",name='up4')(summed)

    summed = add(inputs=[skip2,model.get_layer("block3_pool").output])

    up7 = UpSampling2D(size=(8,8),interpolation='bilinear',name='upsamping_7')(summed)
    o = Conv2D(nClasses,kernel_size=(3,3),activation='relu',padding='same',name='conv_7')(up7)


    o = Reshape((-1,nClasses))(o)
    o = Activation("softmax")(o)
    fcn8 = Model(model.input,o)
    return fcn8
Ejemplo n.º 3
0
    def __init__(self, raanan_architecture=False, sigmoid_activation=True):
        super(Decoder, self).__init__()

        self.input_layer = InputLayer()
        self.fully_connected3 = Dense(512)
        self.fully_connected4 = Dense(7 * 7 * 64)
        self.reshape = Reshape((7, 7, 64))
        self.conv_transpose1 = Conv2DTranspose(32,
                                               3,
                                               padding="same",
                                               strides=2)
        self.conv_transpose2 = Conv2DTranspose(1, 3, padding="same", strides=2)

        self.relu1 = ReLU()
        self.relu2 = ReLU()
        self.relu3 = ReLU()

        self.last_activation = sigmoid if sigmoid_activation else tanh
        if raanan_architecture:
            self.relu1 = LeakyReLU()
            self.relu2 = LeakyReLU()
            self.relu3 = LeakyReLU()

        print("Decoder network created with raanan architecture={}".format(
            raanan_architecture))
Ejemplo n.º 4
0
    def __init__(self):
        super(TopModel, self).__init__()
        input_filters = 2048  # output of resnet
        self.output_filters = 256
        self.nbJoints = 17
        self.depth_dim = 64

        self.deconv1 = Conv2DTranspose(filters=self.output_filters,
                                       kernel_size=4,
                                       strides=(2, 2),
                                       padding="valid")
        self.relu1 = ReLU()
        self.batchnorm1 = BatchNormalization()

        self.deconv2 = Conv2DTranspose(filters=self.output_filters,
                                       kernel_size=4,
                                       strides=(2, 2),
                                       padding="valid")
        self.relu2 = ReLU()
        self.batchnorm2 = BatchNormalization()

        self.deconv3 = Conv2DTranspose(filters=self.output_filters,
                                       kernel_size=4,
                                       strides=(2, 2),
                                       padding="valid")
        self.relu3 = ReLU()
        self.batchnorm3 = BatchNormalization()

        self.final_conv = Conv2D(filters=self.nbJoints * self.depth_dim,
                                 kernel_size=1,
                                 strides=1,
                                 padding="valid")
Ejemplo n.º 5
0
def standardUnet(width, height, chann, nc):    

    inputs = Input((height, width, chann))
    # image normalization between 0 and 1
    s = Lambda(lambda x: x / 255) (inputs)


    c1 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (s)
    #c1 = Dropout(0.1) (c1)
    c1 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c1)
    p1 = MaxPooling2D((2, 2)) (c1)

    c2 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p1)
    #c2 = Dropout(0.1) (c2)
    c2 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c2)
    p2 = MaxPooling2D((2, 2)) (c2)

    c3 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p2)
    #c3 = Dropout(0.2) (c3)
    c3 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c3)
    p3 = MaxPooling2D((2, 2)) (c3)

    c4 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p3)
    #c4 = Dropout(0.2) (c4)
    c4 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c4)
    p4 = MaxPooling2D(pool_size=(2, 2)) (c4)

    c5 = Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p4)
    #c5 = Dropout(0.3) (c5)
    c5 = Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c5)

    u6 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same') (c5)
    u6 = concatenate([u6, c4])
    c6 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u6)
    #c6 = Dropout(0.2) (c6)
    c6 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c6)

    u7 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same') (c6)
    u7 = concatenate([u7, c3])
    c7 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u7)
    #c7 = Dropout(0.2) (c7)
    c7 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c7)

    u8 = Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same') (c7)
    u8 = concatenate([u8, c2])
    c8 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u8)
    #c8 = Dropout(0.1) (c8)
    c8 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c8)

    u9 = Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same') (c8)
    u9 = concatenate([u9, c1], axis=3)
    c9 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u9)
    #c9 = Dropout(0.1) (c9)
    c9 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c9)

    outputs = Conv2D(nc, (1, 1), activation='softmax') (c9)

    model = Model(inputs=inputs, outputs=outputs)

    return model
Ejemplo n.º 6
0
def create_generator():
    model = Sequential()

    # Reshape input into 32x32x256 tensor via a fully connected layer
    model.add(Dense(64 * 32 * 32, input_dim=z_dim))
    model.add(Reshape((32, 32, 64)))
    model.add(
        Conv2DTranspose(  # Transposed convolution layer, from 32x32x256 into 64x64x128 tensor
            128,
            kernel_size=3,
            strides=2,
            padding='same'))
    model.add(BatchNormalization())  # Batch normalization
    model.add(LeakyReLU(alpha=0.01))  # Leaky ReLU
    model.add(
        Conv2DTranspose(  # Transposed convolution layer, from 64x64x128 to 128x128x64 tensor
            64,
            kernel_size=3,
            strides=2,
            padding='same'))
    model.add(BatchNormalization())  # Batch normalization
    model.add(LeakyReLU(alpha=0.01))  # Leaky ReLU
    model.add(
        Conv2DTranspose(  # Transposed convolution layer, from 128x128x64 to 256x256x3 tensor
            3,
            kernel_size=3,
            strides=2,
            padding='same'))
    model.add(Activation('tanh'))  # Tanh activation
    model.compile(loss='binary_crossentropy', optimizer=adam_optimizer())
    model.summary()
    return model
Ejemplo n.º 7
0
def Decoder(inputs, opts, istrain=True):
    assert opts.isize % 16 == 0, "isize has to be a multiple of 16"
    cngf, tisize = opts.dis_filter // 2, 4
    while tisize != opts.isize:
        cngf = cngf * 2  # after loop, cngf reaches to 256
        tisize = tisize * 2
    '''z is input, and first deconvolution layer to size channel * 4 * 4'''
    x = Conv2DTranspose(cngf, (4, 4), padding='valid', use_bias=False)(inputs)
    x = batch_norm(x, "bn1", is_train=istrain)
    x = Activation('relu')(x)
    '''size increaing layers '''
    size_now = 4
    while size_now < opts.isize // 2:
        x = Conv2DTranspose(cngf // 2, (4, 4),
                            strides=2,
                            padding='same',
                            use_bias=False)(x)
        x = batch_norm(x, "bn2_" + str(size_now), is_train=istrain)
        x = Activation('relu')(x)
        cngf = cngf // 2
        size_now = size_now * 2
    '''extral layers, keep the channel and size of the layers same'''
    for t in range(opts.n_extra_layers):
        x = Conv2DTranspose(cngf, (3, 3), padding='same', use_bias=False)(x)
        x = batch_norm(x, "bn3_" + str(t), is_train=istrain)
        x = Activation('relu')(x)
    ''' final layer, expand the size with 2 and channel of n_output_channel'''
    x = Conv2DTranspose(opts.image_channel, (4, 4),
                        strides=2,
                        padding='same',
                        use_bias=False)(x)
    x = Activation('tanh')(x)
    return x
Ejemplo n.º 8
0
def get_upsampled_signal(x):
    y = Conv2DTranspose(filters=64,
                        kernel_size=(3, 3),
                        strides=1,
                        padding='same',
                        name='decode_convtrans_1')(x)
    y = LeakyReLU(name='decode_relu_1')(y)
    y = UpSampling2D(size=(2, 2), name='decode_upsample_1')(y)
    y = Conv2DTranspose(filters=64,
                        kernel_size=(3, 3),
                        strides=1,
                        padding='same',
                        name='decode_convtrans_2')(x)
    y = LeakyReLU(name='decode_relu_2')(y)
    y = UpSampling2D(size=(2, 2), name='decode_upsample_2')(y)
    y = Conv2DTranspose(filters=32,
                        kernel_size=(3, 3),
                        strides=1,
                        padding='same',
                        name='decode_convtrans_3')(y)
    y = LeakyReLU(name='decode_relu_3')(y)
    y = UpSampling2D(size=(2, 2), name='decode_upsample_3')(y)
    y = Conv2DTranspose(filters=16,
                        kernel_size=(2, 2),
                        strides=1,
                        padding='same',
                        name='decode_convtrans_4')(y)
    y = LeakyReLU(name='decode_relu_4')(y)
    return y
Ejemplo n.º 9
0
    def init_generator(self):
        layers = [
            Dense(self.latent_space_size,
                  input_dim=self.latent_space_size,
                  activation='tanh'),
            Reshape((self.image_height, self.image_width, 1)),
            BatchNormalization(),
            Conv2DTranspose(64, (4, 4),
                            strides=(1, 1),
                            kernel_initializer=self.kernel_init,
                            padding='same',
                            use_bias=False),
            LeakyReLU(),
            BatchNormalization(),
            Conv2DTranspose(1, (4, 4),
                            strides=(1, 1),
                            kernel_initializer=self.kernel_init,
                            padding='same',
                            use_bias=False),
        ]

        self.generator = self.make_model(layers)
        self.generator = self.compile_model(self.generator)

        self.generator_first_layer_to_unlock = 0
        self.generator_last_layer_to_unlock = len(layers)  #-1 ?
Ejemplo n.º 10
0
def define_generator(latent_dim, n_classes=10):
    # weight initialization
    init = RandomNormal(stddev=0.02)
    # label input
    in_label = Input(shape=(1,))
    # embedding for categorical input
    li = Embedding(n_classes, 50)(in_label)
    # linear multiplication
    n_nodes = 7 * 7
    li = Dense(n_nodes, kernel_initializer=init)(li)
    # reshape to additional channel
    li = Reshape((7, 7, 1))(li)
    # image generator input
    in_lat = Input(shape=(latent_dim,))
    # foundation for 7x7 image
    n_nodes = 384 * 7 * 7
    gen = Dense(n_nodes, kernel_initializer=init)(in_lat)
    gen = Activation('relu')(gen)
    gen = Reshape((7, 7, 384))(gen)
    # merge image gen and label input
    merge = Concatenate()([gen, li])
    # upsample to 14x14
    gen = Conv2DTranspose(192, (5,5), strides=(2,2), padding='same', kernel_initializer=init)(merge)
    gen = BatchNormalization()(gen)
    gen = Activation('relu')(gen)
    # upsample to 28x28
    gen = Conv2DTranspose(1, (5,5), strides=(2,2), padding='same', kernel_initializer=init)(gen)
    out_layer = Activation('tanh')(gen)
    # define model
    model = Model([in_lat, in_label], out_layer)
    return model
Ejemplo n.º 11
0
    def __generate_detection_resnet34(self, input_layer, n_category=None):
        out_filters = n_category + 4

        x_1, x_2, x_3, x = self.__generate_encoder(input_layer)

        # Deconvolution block 1: (16, 16, 512) -> (32, 32, 512)
        x = Conv2D(filters=256, kernel_size=3, strides=1, padding='same')(x)
        x = Conv2DTranspose(filters=256, kernel_size=4, strides=2, padding='same')(x)
        x = Concatenate()([x_3, x])
        x = BatchNormalization()(x)
        x = LeakyReLU(alpha=0.1)(x)

        # Deconvolution block 2: (32, 32, 512) -> (64, 64, 256)
        x = Conv2D(filters=128, kernel_size=3, strides=1, padding='same')(x)
        x = Conv2DTranspose(filters=128, kernel_size=4, strides=2, padding='same')(x)
        x = Concatenate()([x_2, x])
        x = BatchNormalization()(x)
        x = LeakyReLU(alpha=0.1)(x)

        # Deconvolution block 3: (64, 64, 256) -> (128, 128, 128)
        x = Conv2D(filters=64, kernel_size=3, strides=1, padding='same')(x)
        x = Conv2DTranspose(filters=64, kernel_size=4, strides=2, padding='same')(x)
        x = Concatenate()([x_1, x])
        x = BatchNormalization()(x)
        x = LeakyReLU(alpha=0.1)(x)

        # Block 4:
        x = Conv2D(filters=out_filters, kernel_size=1, strides=1, padding='same')(x)
        out = Activation('sigmoid')(x)  # optional

        return Model(input_layer, out)
Ejemplo n.º 12
0
def decoder_128(vector_len: int) -> Model:
    input_decoder = Input(shape=(vector_len, ), name=f"input_{vector_len}x1")
    x = Dense(64, activation=tanh, name="Activate_Input")(input_decoder)
    x = Reshape((8, 8, 1), name="Reshape_8x8")(x)
    x = Conv2DTranspose(16, (3, 3),
                        strides=1,
                        activation=relu,
                        padding='same',
                        name="Transpose_8x8")(x)
    x = Conv2DTranspose(32, (3, 3),
                        strides=2,
                        activation=relu,
                        padding='same',
                        name="Transpose_16x16")(x)
    x = Conv2DTranspose(32, (5, 5),
                        strides=2,
                        activation=relu,
                        padding='same',
                        name="Transpose_32x32")(x)
    x = Conv2DTranspose(64, (5, 5),
                        strides=2,
                        activation=relu,
                        padding='same',
                        name="Transpose_64x64")(x)
    decoded = Conv2DTranspose(4, (5, 5),
                              strides=2,
                              activation=sigmoid,
                              padding='same',
                              name="Output_128x128")(x)

    return Model(input_decoder, decoded, name="Decoder")
Ejemplo n.º 13
0
    def generator(self):
        if self.G:
            return self.G
        self.G = Sequential()
        dropout = 0.2
        depth = 64 + 64 + 64 + 64
        dim = 8

        self.G.add(Dense(dim * dim * depth, input_dim=100))
        self.G.add(BatchNormalization(momentum=0.9))
        self.G.add(Activation('relu'))
        self.G.add(Reshape((dim, dim, depth)))
        self.G.add(Dropout(dropout))

        self.G.add(UpSampling2D())
        self.G.add(Conv2DTranspose(int(depth / 2), 5, padding='same'))
        self.G.add(BatchNormalization(momentum=0.9))
        self.G.add(Activation('relu'))

        self.G.add(UpSampling2D())
        self.G.add(Conv2DTranspose(int(depth / 4), 5, padding='same'))
        self.G.add(BatchNormalization(momentum=0.9))
        self.G.add(Activation('relu'))

        self.G.add(UpSampling2D())
        self.G.add(Conv2DTranspose(int(depth / 8), 5, padding='same'))
        self.G.add(BatchNormalization(momentum=0.9))
        self.G.add(Activation('relu'))

        # Out: 64 x 64 x 1 grayscale image [0.0,1.0] per pix
        self.G.add(Conv2DTranspose(1, 5, padding='same'))
        self.G.add(Activation('sigmoid'))
        self.G.summary()
        return self.G
Ejemplo n.º 14
0
def create_generator():
    # Create the Generator network structure
    generator = Sequential()

    generator.add(Dense(12544, input_dim=100))
    generator.add(BatchNormalization(momentum=0.9))
    generator.add(Activation('relu'))
    generator.add(Reshape((7, 7, 256)))
    generator.add(Dropout(0.4))

    generator.add(UpSampling2D())
    generator.add(Conv2DTranspose(int(128), 5, padding='same'))
    generator.add(BatchNormalization(momentum=0.9))
    generator.add(Activation('relu'))
    generator.add(UpSampling2D())
    generator.add(Conv2DTranspose(int(64), 5, padding='same'))
    generator.add(BatchNormalization(momentum=0.9))
    generator.add(Activation('relu'))
    generator.add(Conv2DTranspose(int(32), 5, padding='same'))
    generator.add(BatchNormalization(momentum=0.9))
    generator.add(Activation('relu'))

    generator.add(Conv2DTranspose(1, 5, padding='same'))
    generator.add(Activation('sigmoid'))

    generator.compile(optimizer=RMSprop(lr=0.0004, clipvalue=1.0, decay=3e-8),
                      loss='binary_crossentropy',
                      metrics=['accuracy'])

    generator.summary()

    return generator
Ejemplo n.º 15
0
def decoder():
    latent_inputs = keras.Input(shape=(128, ))
    x = Dropout(0.25)(Dense(8 * 8 * 512)(latent_inputs))
    x = Reshape((8, 8, 512))(x)
    x = Conv2D(512, 1, padding='same')(x)
    x = BatchNormalization()(x)
    x = LeakyReLU()(x)

    x = Conv2DTranspose(512, 3, strides=2, padding="same")(x)
    x = BatchNormalization()(x)
    x = LeakyReLU()(x)

    x = Conv2DTranspose(256, 3, strides=2, padding="same")(x)
    x = BatchNormalization()(x)
    x = LeakyReLU()(x)

    x = Conv2DTranspose(128, 3, padding="same")(x)
    x = BatchNormalization()(x)
    x = LeakyReLU()(x)

    decoder_outputs = Conv2D(128,
                             1,
                             strides=1,
                             padding='same',
                             activation='sigmoid')(x)

    decoder = Model(latent_inputs, decoder_outputs, name="decoder")
    return decoder
def initialize_model():

    model = Sequential()
    model.add(
        Conv2D(40, 11, strides=1, padding='same', input_shape=(1, 1024, 4)))
    model.add(BatchNormalization(axis=-1))
    model.add(Activation('relu'))

    model.add(Conv2D(40, 11, strides=1, padding='same'))
    model.add(BatchNormalization(axis=-1))
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(1, 64)))

    model.add(Flatten())

    model.add(Dense(units=500))

    model.add(Dense(units=640))

    model.add(Reshape((1, 16, 40)))

    model.add(Conv2DTranspose(40, 11, strides=(1, 64), padding='same'))
    model.add(BatchNormalization(axis=-1))
    model.add(Activation('relu'))

    model.add(Conv2DTranspose(40, 11, strides=(1, 1), padding='same'))
    model.add(BatchNormalization(axis=-1))
    model.add(Activation('relu'))

    model.add(Conv2D(4, 11, strides=1, padding='same', activation='sigmoid'))
    model.summary()
    model.compile(optimizer='adam', loss='mse')

    return model
Ejemplo n.º 17
0
    def build(self):
        inputs = Input(shape=[None, None, 3])
        conv1 = Conv2D(64, 4, 2, activation=LeakyReLU(0.2), padding='same')(inputs)
        conv2 = Conv2D(128, 4, 2, padding='same')(conv1)
        conv2 = self.norm(conv2)
        conv2 = LeakyReLU(0.2)(conv2)
        conv3 = Conv2D(256, 4, 2, padding='same')(conv2)
        conv3 = self.norm(conv3)
        conv3 = LeakyReLU(0.2)(conv3)
        conv4 = Conv2D(512, 4, 2, padding='same')(conv3)
        conv4 = self.norm(conv4)
        conv4 = LeakyReLU(0.2)(conv4)
        conv5 = Conv2D(1, 4, 2, padding='same')(conv4)

        upconv1 = Conv2DTranspose(256, 4, 2, padding='same')(conv5)
        upconv1 = self.norm(upconv1)
        upconv1 = Activation('relu')(upconv1)
        concat1 = Concatenate()([conv4, upconv1])
        upconv2 = Conv2DTranspose(128, 4, 2, padding='same')(concat1)
        upconv2 = self.norm(upconv2)
        upconv2 = Activation('relu')(upconv2)
        concat2 = Concatenate()([conv3, upconv2])
        upconv3 = Conv2DTranspose(64, 4, 2, padding='same')(concat2)
        upconv3 = self.norm(upconv3)
        upconv3 = Activation('relu')(upconv3)
        concat3 = Concatenate()([conv2, upconv3])
        upconv4 = Conv2DTranspose(32, 4, 2, padding='same')(concat3)
        upconv4 = self.norm(upconv4)
        upconv4 = Activation('relu')(upconv4)
        concat4 = Concatenate()([conv1, upconv4])
        outputs = Conv2DTranspose(self.classes, 4, 2, padding='same', activation='softmax')(concat4)

        model = Model(inputs=inputs, outputs=[conv5, outputs])

        return model
Ejemplo n.º 18
0
    def __init__(self, **kwargs):
        super(Generator, self).__init__(**kwargs)
        self.conv1 = Conv2D(64, kernel_size=7, strides=1, padding="valid")
        self.conv2 = Conv2D(64 * 2, kernel_size=3, strides=2, padding="same")
        self.conv3 = Conv2D(64 * 4, kernel_size=3, strides=2, padding="same")
        self.in_c1 = InstanceNorm_kong()
        self.in_c2 = InstanceNorm_kong()
        self.in_c3 = InstanceNorm_kong()

        self.resb1 = ResBlock(c_num=64 * 4)
        self.resb2 = ResBlock(c_num=64 * 4)
        self.resb3 = ResBlock(c_num=64 * 4)
        self.resb4 = ResBlock(c_num=64 * 4)
        self.resb5 = ResBlock(c_num=64 * 4)
        self.resb6 = ResBlock(c_num=64 * 4)
        self.resb7 = ResBlock(c_num=64 * 4)
        self.resb8 = ResBlock(c_num=64 * 4)
        self.resb9 = ResBlock(c_num=64 * 4)

        self.convT1 = Conv2DTranspose(64 * 2,
                                      kernel_size=3,
                                      strides=2,
                                      padding="same")
        self.convT2 = Conv2DTranspose(64,
                                      kernel_size=3,
                                      strides=2,
                                      padding="same")
        self.in_cT1 = InstanceNorm_kong()
        self.in_cT2 = InstanceNorm_kong()
        self.convRGB = Conv2D(3, kernel_size=7, strides=1, padding="valid")
Ejemplo n.º 19
0
    def _create_decoder(input_shape, encode_block):
        conv3 = encode_block.get_layer('conv3').output
        x = Input(shape=input_shape, name='decoder_input')
        net = Add()([x, conv3])

        conv2 = encode_block.get_layer('conv2').output
        net = Conv2DTranspose(filters=64,
                              kernel_size=3,
                              strides=2,
                              name='dconv1')(x)
        net = Add()([net, conv2])
        net = BatchNormalization()(net)

        net = Conv2DTranspose(filters=32,
                              kernel_size=3,
                              strides=2,
                              name='dconv2')(net)
        net = BatchNormalization()(net)

        encoder_input = encode_block.get_layer('encoder_input').output
        net = Conv2DTranspose(filters=1,
                              kernel_size=3,
                              strides=2,
                              name='dconv3')(net)
        net = Add()([net, encoder_input])
        net = BatchNormalization()(net)

        net = Model(inputs=[x, encode_block.input],
                    outputs=net,
                    name='decoder')
        return net
Ejemplo n.º 20
0
def get_unet(IMG_WIDTH=256,IMG_HEIGHT=256,IMG_CHANNELS=3):
    inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
    s = Lambda(lambda x: x / 255) (inputs)
    c1 = Conv2D(16, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (s)
    c1 = Dropout(0.1) (c1)
    c1 = Conv2D(16, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c1)
    p1 = MaxPooling2D((2, 2)) (c1)
    c2 = Conv2D(32, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (p1)
    c2 = Dropout(0.1) (c2)
    c2 = Conv2D(32, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c2)
    p2 = MaxPooling2D((2, 2)) (c2)

    c3 = Conv2D(64, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (p2)
    c3 = Dropout(0.2) (c3)
    c3 = Conv2D(64, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c3)
    p3 = MaxPooling2D((2, 2)) (c3)

    c4 = Conv2D(128, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (p3)
    c4 = Dropout(0.2) (c4)
    c4 = Conv2D(128, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c4)
    p4 = MaxPooling2D(pool_size=(2, 2)) (c4)

    c5 = Conv2D(256, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (p4)
    c5 = Dropout(0.3) (c5)
    c5 = Conv2D(256, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c5)

    u6 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same') (c5)
 #   u6 = concatenate([u6, c4])
    c6 = Conv2D(128, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (u6)
    c6 = Dropout(0.2) (c6)
    c6 = Conv2D(128, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c6)

    u7 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same') (c6)
#    u7 = concatenate([u7, c3])
    c7 = Conv2D(64, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (u7)
    c7 = Dropout(0.2) (c7)
    c7 = Conv2D(64, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c7)

    u8 = Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same') (c7)
#    u8 = concatenate([u8, c2])
    c8 = Conv2D(32, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (u8)
    c8 = Dropout(0.1) (c8)
    c8 = Conv2D(32, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c8)

    u9 = Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same') (c8)
  #  u9 = concatenate([u9, c1], axis=3)
    c9 = Conv2D(16, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (u9)
    c9 = Dropout(0.1) (c9)
    c9 = Conv2D(16, (3, 3), activation='elu', kernel_initializer='he_normal', padding='same') (c9)

    outputs = Conv2D(1, (1, 1), activation='sigmoid') (c9)

    model = Model(inputs=[inputs], outputs=[outputs])
    model.compile(optimizer='adam',loss='binary_crossentropy', metrics=[my_iou_metric])
    return model
Ejemplo n.º 21
0
    def build_model(self):
        inputs = Input((self.patch_height, self.patch_width, 1))
        conv1 = Conv2D(32, (1, 1), activation=None, padding='same')(inputs)
        conv1 = normalization.BatchNormalization(epsilon=2e-05, axis=3, momentum=0.9, weights=None, beta_initializer='zero', gamma_initializer='one')(conv1)
        conv1 = Activation('relu')(conv1)

        conv1 = self.DenseBlock(conv1, 32)  # 48
        conv1 = self.se_block(ratio=2)(conv1)
        pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

        conv2 = self.DenseBlock(pool1, 64)  # 24
        conv2 = self.se_block(ratio=2)(conv2)
        pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

        conv3 = self.DenseBlock(pool2, 64)  # 12
        conv3 = self.se_block(ratio=2)(conv3)
        pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)

        conv4 = self.DenseBlock(pool3, 64)  # 12
        conv4 = self.se_block(ratio=2)(conv4)

        up1 = Conv2DTranspose(64, (3, 3), strides=2, activation='relu', padding='same', kernel_regularizer=regularizers.l2(0.0001))(conv4)
        up1 = concatenate([up1, conv3], axis=3)

        conv5 = self.DenseBlock(up1, 64)
        conv5 = self.se_block(ratio=2)(conv5)

        up2 = Conv2DTranspose(64, (3, 3), strides=2, activation='relu', padding='same', kernel_regularizer=regularizers.l2(0.0001))(conv5)
        up2 = concatenate([up2, conv2], axis=3)

        conv6 = self.DenseBlock(up2, 64)
        conv6 = self.se_block(ratio=2)(conv6)

        up3 = Conv2DTranspose(32, (3, 3), strides=2, activation='relu', padding='same', kernel_regularizer=regularizers.l2(0.0001))(conv6)
        up3 = concatenate([up3, conv1], axis=3)

        conv7 = self.DenseBlock(up3, 32)
        conv7 = self.se_block(ratio=2)(conv7)

        conv8 = Conv2D(self.num_seg_class + 1, (1, 1), activation='relu', padding='same', kernel_regularizer=regularizers.l2(0.0001))(conv7)
        # conv6 = normalization.BatchNormalization(epsilon=1e-06, mode=1, axis=-1, momentum=0.9, weights=None, beta_init='zero', gamma_init='one')(conv6)

        # for tensorflow
        conv8 = core.Reshape((self.patch_height * self.patch_width, self.num_seg_class + 1))(conv8)
        # for theano
        # conv8 = core.Reshape(((self.num_seg_class + 1), self.patch_height * self.patch_width))(conv8)
        # conv8 = core.Permute((2, 1))(conv8)
        ############
        act = Activation('softmax')(conv8)

        model = Model(inputs=inputs, outputs=act)
        model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['categorical_accuracy'])
        plot_model(model, to_file=os.path.join(self.config.checkpoint, "model.png"), show_shapes=True)
        self.model = model
Ejemplo n.º 22
0
def _deconv4x(x, filters, kernel_sizes, cfg):
    assert len(filters) == 2
    assert len(kernel_sizes) == 2
    x = Conv2DTranspose(filters=filters[0],
                        kernel_size=kernel_sizes[0],
                        strides=2,
                        **cfg)(x)
    x = Conv2DTranspose(filters=filters[1],
                        kernel_size=kernel_sizes[1],
                        strides=2,
                        **cfg)(x)
    return x
Ejemplo n.º 23
0
def simple_instance_network(shape):
    input_img = Input(shape=shape)
    input_img_1 = Reshape((*shape, 1))(input_img)

    # Stage 1
    x = Conv2D(32, (3, 3), strides=(1, 1), padding='same', name='conv1', use_bias=True)(input_img_1)
    x = BatchNormalization(name='bn_conv1')(x)
    thumbnail1 = x = Activation('relu')(x)
    x = MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)

    # Stage 2
    x = conv_block(x, 3, [64, 64], stage=2, block='a')
    thumbnail2 = x = identity_block(x, 3, [64, 64], stage=2, block='b')
    x = MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)

    # Stage 3
    x = conv_block(x, 3, [128, 128], stage=3, block='a')
    thumbnail4 = x = identity_block(x, 3, [128, 128], stage=3, block='b')
    x = MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)

    # Stage 4
    x = conv_block(x, 3, [256, 256], stage=4, block='a')
    thumbnail8 = identity_block(x, 3, [256, 256], stage=4, block='b')

    # Co-stage 4
    forge8 = thumbnail8
    forge8 = conv_block(forge8, 3, [256, 256], stage=5, block='a')
    forge8 = identity_block(forge8, 3, [256, 256], stage=5, block='b')

    # Co-stage 3
    forge4 = Conv2DTranspose(128, (3, 3), padding='same', strides=(2, 2), activation='relu')(forge8)
    forge4_post = identity_block(forge4, 3, [128, 128], stage=6, block='a')
    thumbnail4_shortcut = conv_block(thumbnail4, 3, [128, 128], stage=6, block='b')
    forge4_sum_shortcut = Add()([forge4_post, thumbnail4_shortcut])

    # Co-stage 2
    forge2 = Conv2DTranspose(64, (3, 3), padding='same', strides=(2, 2), activation='relu')(forge4_sum_shortcut)
    forge2_post = identity_block(forge2, 3, [64, 64], stage=7, block='a')
    thumbnail2_shortcut = conv_block(thumbnail2, 3, [64, 64], stage=7, block='b')
    forge2_sum_shortcut = Add()([forge2_post, thumbnail2_shortcut])

    # Co-stage 1
    forge1 = Conv2DTranspose(32, (3, 3), padding='same', strides=(2, 2), activation='relu')(forge2_sum_shortcut)
    forge1_post = identity_block(forge1, 3, [32, 32], stage=8, block='a')
    thumbnail1_shortcut = conv_block(thumbnail1, 3, [32, 32], stage=8, block='b')
    forge1_sum_shortcut = Add()([forge1_post, thumbnail1_shortcut])

    output = Conv2D(2, (3, 3), padding='same', strides=(1, 1), activation='sigmoid')(forge1_sum_shortcut)

    generated = Model(input=input_img, output=output)

    return generated
Ejemplo n.º 24
0
def upsample(inp,
             factor,
             nchannels,
             config,
             bn=None,
             activation=None,
             upsampling='bilinear',
             residual=False):

    if residual:
        r1 = UpSampling2D(size=(factor, factor), interpolation=upsampling)(inp)
        up = Conv2D(nchannels, factor, **config)(r1)
        r2 = Conv2DTranspose(nchannels,
                             factor,
                             strides=(factor, factor),
                             padding='same')(inp)

    else:
        if upsampling in ['bilinear', 'nearest']:
            up = UpSampling2D(size=(factor, factor),
                              interpolation=upsampling)(inp)
            up = Conv2D(nchannels, factor, **config)(up)
        elif upsampling == 'conv':
            up = Conv2DTranspose(nchannels,
                                 factor,
                                 strides=(factor, factor),
                                 padding='same')(inp)
        elif upsampling == 'subpixel':
            up = SubPixelConv2D(upsample_factor=factor,
                                nchannels=nchannels)(inp)
        else:
            raise (NotImplementedError)

    if bn and bn == 'before':
        act = config['activation']
        config['activation'] = None

    if bn:
        up = BatchNormalization()(up)

        if bn == 'before':
            if act:
                up = Activation(act)(up)
            else:
                up = activation(up)

            config['activation'] = act

    if residual:
        up = up + r2

    return up
Ejemplo n.º 25
0
def miniUnet(width, height, chann, nc):    

    inputs = Input((height, width, chann))
    # image normalization between 0 and 1
    #s = Lambda(lambda x: x / 255) (inputs)

    c1 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (inputs)
    #c1 = Dropout(0.1) (c1)
    #c1 = BatchNormalization()(c1)
    c1 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c1)
    #c1 = BatchNormalization()(c1)
    
    p1 = MaxPooling2D((2, 2)) (c1)

    c2 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p1)
    #c2 = Dropout(0.2) (c2)
    #c2 = BatchNormalization()(c2)
    c2 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c2)
    #c2 = BatchNormalization()(c2)
    
    p2 = MaxPooling2D((2, 2)) (c2)

    c3 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (p2)
    #c3 = Dropout(0.2) (c3)
    #c3 = BatchNormalization()(c3)
    c3 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c3)
    #c3 = BatchNormalization()(c3)
    
    u4 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same') (c3)
    u4 = concatenate([u4, c2])

    c4 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u4)
    #c4 = Dropout(0.2) (c4)
    #c4 = BatchNormalization()(c4)
    c4 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c4)
    #c4 = BatchNormalization()(c4)
    
    u5 = Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same') (c4)
    u5 = concatenate([u5, c1])

    c5 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (u5)
    #c5 = Dropout(0.1) (c5)
    #c5 = BatchNormalization()(c5)
    c5 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same') (c5)
    #c5 = BatchNormalization()(c5)
    
    outputs = Conv2D(nc, (1, 1), activation='softmax') (c5)
    
    model = Model(inputs=[inputs], outputs=[outputs])
    
    return model
Ejemplo n.º 26
0
def kaggle_u_net_direct(im_height, im_width, im_chan):
    """
    This is a kaggle recommended u-net architecture from kaggle kernels.
    https://www.kaggle.com/jesperdramsch/intro-to-seismic-salt-and-how-to-geophysics
    :return:
    """
    inputs = Input((im_height, im_width, im_chan))
    s = tf.keras.layers.Lambda(lambda x: x / 255)(inputs)

    c1 = Conv2D(8, (3, 3), activation='relu', padding='same')(s)
    c1 = Conv2D(8, (3, 3), activation='relu', padding='same')(c1)
    p1 = MaxPooling2D((2, 2))(c1)

    c2 = Conv2D(16, (3, 3), activation='relu', padding='same')(p1)
    c2 = Conv2D(16, (3, 3), activation='relu', padding='same')(c2)
    p2 = MaxPooling2D((2, 2))(c2)

    c3 = Conv2D(32, (3, 3), activation='relu', padding='same')(p2)
    c3 = Conv2D(32, (3, 3), activation='relu', padding='same')(c3)
    p3 = MaxPooling2D((2, 2))(c3)

    c4 = Conv2D(64, (3, 3), activation='relu', padding='same')(p3)
    c4 = Conv2D(64, (3, 3), activation='relu', padding='same')(c4)
    p4 = MaxPooling2D(pool_size=(2, 2))(c4)

    c5 = Conv2D(128, (3, 3), activation='relu', padding='same')(p4)
    c5 = Conv2D(128, (3, 3), activation='relu', padding='same')(c5)

    u6 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same')(c5)
    u6 = concatenate([u6, c4])
    c6 = Conv2D(64, (3, 3), activation='relu', padding='same')(u6)
    c6 = Conv2D(64, (3, 3), activation='relu', padding='same')(c6)

    u7 = Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same')(c6)
    u7 = concatenate([u7, c3])
    c7 = Conv2D(32, (3, 3), activation='relu', padding='same')(u7)
    c7 = Conv2D(32, (3, 3), activation='relu', padding='same')(c7)

    u8 = Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same')(c7)
    u8 = concatenate([u8, c2])
    c8 = Conv2D(16, (3, 3), activation='relu', padding='same')(u8)
    c8 = Conv2D(16, (3, 3), activation='relu', padding='same')(c8)

    u9 = Conv2DTranspose(8, (2, 2), strides=(2, 2), padding='same')(c8)
    u9 = concatenate([u9, c1], axis=3)
    c9 = Conv2D(8, (3, 3), activation='relu', padding='same')(u9)
    c9 = Conv2D(8, (3, 3), activation='relu', padding='same')(c9)

    outputs = Conv2D(1, (1, 1), activation='sigmoid')(c9)

    return inputs, outputs
Ejemplo n.º 27
0
def encoder_decoder_generator(start_img):
    """
    """

    layer1 = Conv2D(64, kernel_size=4, strides=2, activation='elu', padding='same')(start_img)
    layer2 = Conv2D(64, kernel_size=4, strides=2, activation='elu', padding='same')(layer1)
    layer3 = Conv2D(64, kernel_size=4, strides=1, activation='elu', padding='same')(layer2)
    layer4 = Conv2DTranspose(64, kernel_size=4, strides=2, activation='elu', padding="same")(layer3)
    layer5 = Conv2DTranspose(64, kernel_size=4, strides=2, activation='elu', padding="same")(layer4)
    layer6 = Conv2D(64, kernel_size=2, strides=1, activation='elu', padding='same')(layer5)
    # Make sure that generator output is in the same range as `inputs`
    # ie [-1, 1].
    net = Conv2D(3, kernel_size=1, activation = 'tanh', padding='same')(layer6)
    return net
Ejemplo n.º 28
0
def simpleUnet(width, height, chann, nc, n_filters = 16, dropout = 0.1, batchnorm = False):
    
    inputs = Input((height, width, chann))
    # image normalization between 0 and 1
    s = Lambda(lambda x: x / 255) (inputs)
    
    # Contracting Path
    c1 = conv2dBlock(s, n_filters * 1, kernel_size = 3, batchnorm = batchnorm)
    p1 = MaxPooling2D((2, 2))(c1)
    #p1 = Dropout(dropout)(p1)
    
    c2 = conv2dBlock(p1, n_filters * 2, kernel_size = 3, batchnorm = batchnorm)
    p2 = MaxPooling2D((2, 2))(c2)
    #p2 = Dropout(dropout)(p2)
    
    c3 = conv2dBlock(p2, n_filters * 4, kernel_size = 3, batchnorm = batchnorm)
    p3 = MaxPooling2D((2, 2))(c3)
    #p3 = Dropout(dropout)(p3)
    
    c4 = conv2dBlock(p3, n_filters * 8, kernel_size = 3, batchnorm = batchnorm)
    p4 = MaxPooling2D((2, 2))(c4)
    #p4 = Dropout(dropout)(p4)
    
    c5 = conv2dBlock(p4, n_filters = n_filters * 16, kernel_size = 3, batchnorm = batchnorm)
    
    # Expansive Path
    u6 = Conv2DTranspose(n_filters * 8, (3, 3), strides = (2, 2), padding = 'same')(c5)
    u6 = concatenate([u6, c4])
    #u6 = Dropout(dropout)(u6)
    c6 = conv2dBlock(u6, n_filters * 8, kernel_size = 3, batchnorm = batchnorm)
    
    u7 = Conv2DTranspose(n_filters * 4, (3, 3), strides = (2, 2), padding = 'same')(c6)
    u7 = concatenate([u7, c3])
    #u7 = Dropout(dropout)(u7)
    c7 = conv2dBlock(u7, n_filters * 4, kernel_size = 3, batchnorm = batchnorm)
    
    u8 = Conv2DTranspose(n_filters * 2, (3, 3), strides = (2, 2), padding = 'same')(c7)
    u8 = concatenate([u8, c2])
    #u8 = Dropout(dropout)(u8)
    c8 = conv2dBlock(u8, n_filters * 2, kernel_size = 3, batchnorm = batchnorm)
    
    u9 = Conv2DTranspose(n_filters * 1, (3, 3), strides = (2, 2), padding = 'same')(c8)
    u9 = concatenate([u9, c1])
    #u9 = Dropout(dropout)(u9)
    c9 = conv2dBlock(u9, n_filters * 1, kernel_size = 3, batchnorm = batchnorm)
    
    outputs = Conv2D(nc, (1, 1), activation='softmax')(c9)
    model = Model(inputs=[inputs], outputs=[outputs])
    
    return model
Ejemplo n.º 29
0
def define_generator(latent_dim):
    model = Sequential()
    # foundation for 7x7 image
    n_nodes = 128 * 7 * 7
    model.add(Dense(n_nodes, input_dim=latent_dim))
    model.add(LeakyReLU(alpha=0.2))
    model.add(Reshape((7, 7, 128)))
    # upsample to 14x14
    model.add(Conv2DTranspose(128, (4, 4), strides=(2, 2), padding='same'))
    model.add(LeakyReLU(alpha=0.2))
    # upsample to 28x28
    model.add(Conv2DTranspose(128, (4, 4), strides=(2, 2), padding='same'))
    model.add(LeakyReLU(alpha=0.2))
    model.add(Conv2D(1, (7, 7), activation='sigmoid', padding='same'))
    return model
Ejemplo n.º 30
0
    def build_encoder_decoder(self,input_shape=(224, 224, 3)):
        """変換用ネットワークの構築"""

        # Encoder部分
        input_ts = Input(shape=input_shape, name='input')

        # 入力を[0, 1]の範囲に正規化
        x = Lambda(lambda a: a/255.)(input_ts)

        x = Conv2D(32, (9, 9), strides=1, padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)

        x = Conv2D(64, (3, 3), strides=2, padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)

        x = Conv2D(128, (3, 3), strides=2, padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)

        # ResidualBlockを5ブロック追加
        for _ in range(5):
            x = self.residual_block(x)

        # Decoder部分
        x = Conv2DTranspose(
                64, (3, 3), strides=2, padding='same'
        )(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)

        x = Conv2DTranspose(32, (3, 3), strides=2, padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('relu')(x)

        x = Conv2DTranspose(3, (9, 9), strides=1, padding='same')(x)
        x = BatchNormalization()(x)
        x = Activation('tanh')(x)

        # 出力値が[0, 255]になるようにスケール変換
        gen_out = Lambda(lambda a: (a + 1)*127.5)(x)

        model_gen = Model(
            inputs=[input_ts],
            outputs=[gen_out]
        )
        return model_gen