Exemplo n.º 1
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 4))
    bn = BatchNormalization()(input_tensor)
    conv = Conv2D(3, (3, 3), padding='same', activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                          weights=None,
                          input_shape=(SIZE, SIZE, 3),
                          input_tensor=conv)

    x = base_model.output
    x = Conv2D(32, kernel_size=(1, 1), activation='relu')(x)
    x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(1024, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    res_img = ResNet34(include_top=False,
                       weights='imagenet',
                       input_shape=(SIZE, SIZE, 3))
    offset = 2
    for i, l in enumerate(base_model.layers[offset + 1:]):
        l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 2
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3),
                          input_tensor=input_tensor)

    enc_out, short_cuts = encoder(base_model)
    x0 = GlobalAveragePooling2D()(squeeze_excite_block(enc_out))
    x1 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[0]))
    x2 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[1]))
    x = Concatenate()([x0, x1, x2])
    x = Dropout(0.3)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.3)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.3)(x)
    output = Dense(n_out, activation='sigmoid')(x)

    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 3
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3),
                          input_tensor=input_tensor)

    x = base_model.get_layer('stage3_unit1_relu1').output

    #x = Dropout(0.5)(x)
    x_map32 = Conv2D(28,
                     kernel_size=(1, 1),
                     activation='sigmoid',
                     name='map32')(x)
    x_pooled = NoisyAndPooling2D()(x_map32)
    output = Dense(n_out, activation='sigmoid', name='pred')(x_pooled)
    model = Model(input_tensor, [output, x_map32])

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 4
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                             weights='imagenet',
                             input_shape=(SIZE, SIZE, 3),input_tensor=input_tensor)

    x = base_model.output
    x1 = Conv2D(32, kernel_size=(1, 1), activation='relu')(x)
    x1 = Flatten()(x1)
    x1 = Dropout(0.5)(x1)
    x1 = Dense(1024, activation='relu')(x1)
    x1 = Dropout(0.5)(x1)
    predictions = Dense(n_out, activation='sigmoid',name = 'predictions')(x1)

    x2 = decoder_block(x,5,512)
    img_out = Dense(3, activation='sigmoid', name='img_out')(x2)


    model = Model(input_tensor, [predictions,img_out])

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 5
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))

    base_model = ResNet34(include_top=False,
                             weights='imagenet',
                             input_shape=(SIZE, SIZE, 3),input_tensor=input_tensor)

    x = base_model.output
    x1 = GlobalMaxPooling2D()(x)
    x2 = GlobalAveragePooling2D()(x)
    x = Concatenate()([x1,x2])
    #x = BatchNormalization(axis=-1)(x)
    x = Dropout(0.5)(x)
    x = Dense(512, activation='relu')(x)
    #x = BatchNormalization(axis=-1)(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out)(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 6
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))

    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3),
                          input_tensor=input_tensor)

    enc_out, short_cuts = encoder(base_model)
    x = GlobalAveragePooling2D()(enc_out)

    #x = Conv2D(32, kernel_size=(1, 1), activation='relu')(x)
    #x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 7
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    red = Lambda(lambda x: x[:, :, :, :1])(input_tensor)
    green = Lambda(lambda x: x[:, :, :, 1:2])(input_tensor)
    blue = Lambda(lambda x: x[:, :, :, 2:])(input_tensor)

    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    red_base_model = ResNet34(include_top=False,
                              weights='imagenet',
                              input_shape=(SIZE, SIZE, 3))
    red_base_model.name = 'resnet34_red'

    green_base_model = ResNet34(include_top=False,
                                weights='imagenet',
                                input_shape=(SIZE, SIZE, 3))
    green_base_model.name = 'resnet34_green'
    blue_base_model = ResNet34(include_top=False,
                               weights='imagenet',
                               input_shape=(SIZE, SIZE, 3))
    blue_base_model.name = 'resnet34_blue'
    x = Add()([
        red_base_model(Concatenate(axis=-1)([red, red, red])),
        green_base_model(Concatenate(axis=-1)([green, green, green])),
        blue_base_model(Concatenate(axis=-1)([blue, blue, blue]))
    ])
    x = Conv2D(256, (3, 3), activation='relu')(x)
    x = GlobalMaxPooling2D()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 8
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=input_shape)
    #bn = BatchNormalization()(input_tensor)
    base_model = ResNet34(include_top=False,
                             weights='imagenet',
                             input_shape=input_shape,input_tensor=input_tensor)

    x = base_model.output
    x = Conv2D(32, kernel_size=(1, 1), activation='relu')(x)
    x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(1024, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    return model
Exemplo n.º 9
0
def create_model(n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3),
                          input_tensor=input_tensor)

    enc_out, short_cuts = encoder(base_model)
    x0 = GlobalAveragePooling2D()(enc_out)
    x1 = GlobalAveragePooling2D()(short_cuts[0])
    x2 = GlobalAveragePooling2D()(short_cuts[1])
    x3 = GlobalAveragePooling2D()(short_cuts[2])
    x4 = GlobalAveragePooling2D()(short_cuts[3])
    x = Concatenate()([x0, x1, x2, x3, x4])
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)
    return model
Exemplo n.º 10
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))

    up_left = Cropping2D(((0, 128), (0, 128)))(input_tensor)
    up_left = UpSampling2D()(up_left)
    up_right = Cropping2D(((128, 0), (0, 128)))(input_tensor)
    up_right = UpSampling2D()(up_right)
    mid = Cropping2D(((64, 64), (64, 64)))(input_tensor)
    mid = UpSampling2D()(mid)
    bot_left = Cropping2D(((0, 128), (128, 0)))(input_tensor)
    bot_left = UpSampling2D()(bot_left)
    bot_right = Cropping2D(((128, 0), (128, 0)))(input_tensor)
    bot_right = UpSampling2D()(bot_right)

    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3))

    up_left_out = top(base_model(up_left))
    up_right_out = top(base_model(up_right))
    mid_out = top(base_model(mid))
    bot_left_out = top(base_model(bot_left))
    bot_right_out = top(base_model(bot_right))

    x = Concatenate()(
        [up_left_out, up_right_out, mid_out, bot_left_out, bot_right_out])
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 11
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    base_model = ResNet34(include_top=False,
                          weights='imagenet',
                          input_shape=(SIZE, SIZE, 3))

    x = base_model(input_tensor)
    x = Conv2D(256, (3, 3), activation='relu')(x)
    x = GlobalMaxPooling2D()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model
Exemplo n.º 12
0
def create_model(input_shape, n_out):
    input_tensor = Input(shape=(SIZE, SIZE, 3))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)
    base_model = ResNet34(include_top=False,
                             weights='imagenet',
                             input_shape=(SIZE, SIZE, 3),input_tensor=input_tensor)

    x = base_model.output
    x = GlobalAveragePooling2D()(x)
    #x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)
    model = Model(input_tensor, output)

    # transfer imagenet weights
    #res_img = ResNet34(include_top=False, weights='imagenet', input_shape=(SIZE, SIZE, 3))
    #offset = 2
    #for i, l in enumerate(base_model.layers[offset+1:]):
    #    l.set_weights(res_img.layers[i + 1].get_weights())

    return model