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)

    r = Lambda(lambda x: x[:, :, :, 0:1])(input_tensor)
    g = Lambda(lambda x: x[:, :, :, 1:2])(input_tensor)
    b = Lambda(lambda x: x[:, :, :, 2:])(input_tensor)

    r = Concatenate(axis=-1)([r, r, r])
    g = Concatenate(axis=-1)([g, g, g])
    b = Concatenate(axis=-1)([b, b, b])

    r_base = ResNet18(include_top=False,
                      weights='imagenet',
                      input_shape=(SIZE, SIZE, 3),
                      input_tensor=r)
    for layer in r_base.layers:
        layer.name += 'r'

    r = r_base.get_layer('stage3_unit1_relu1r').output

    g_base = ResNet18(include_top=False,
                      weights='imagenet',
                      input_shape=(SIZE, SIZE, 3),
                      input_tensor=g)
    for layer in g_base.layers:
        layer.name += 'g'
    g = g_base.get_layer('stage3_unit1_relu1g').output

    b_base = ResNet18(include_top=False,
                      weights='imagenet',
                      input_shape=(SIZE, SIZE, 3),
                      input_tensor=b)
    for layer in b_base.layers:
        layer.name += 'b'

    b = b_base.get_layer('stage3_unit1_relu1b').output

    rgb = Add()([r, g, b])

    rgb = Conv2D(256, kernel_size=(3, 3), activation='relu',
                 padding='same')(rgb)
    rgb = MaxPool2D()(rgb)

    rgb = Conv2D(28, kernel_size=(3, 3), activation='sigmoid',
                 padding='same')(rgb)
    x_pooled = NoisyAndPooling2D()(rgb)
    output = Dense(28, activation='sigmoid')(x_pooled)

    model = Model(input_tensor, output)

    return model
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 = ResNet18(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]))
    x3 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[2]))
    x = Concatenate()([x0, x1, x2, x3])
    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
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 = ResNet18(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]))
    x3 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[2]))
    x = Concatenate()([x0,x1,x2,x3])
    x = BatchNormalization()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    #x = BatchNormalization()(x)
    #x = Dropout(0.5)(x)
    #x = Dense(256, activation='relu')(x)
    x = BatchNormalization()(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)

    model = Model(input_tensor, output)


    return model
def create_model(input_shape, n_out):

    input_tensor2 = Input(shape=(SIZE, SIZE, 4))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)

    base_model2 = ResNet18(include_top=False,
                           weights=None,
                           input_shape=(SIZE, SIZE, 4),
                           input_tensor=input_tensor2)

    # transfer weights of deeper layers
    for k, layer in enumerate(base_model2.layers):
        if k > 4:
            base_model2.layers[k].set_weights(
                base_model.layers[k].get_weights())

    # get first conv weight matrix
    conv_w = base_model.layers[3].get_weights()[0]
    new_part = np.zeros((7, 7, 1, 64))
    fused = np.concatenate([conv_w, new_part], axis=2)

    base_model2.layers[3].set_weights([fused])

    enc_out, short_cuts = encoder(base_model2)
    x0 = GlobalAveragePooling2D()(squeeze_excite_block(enc_out))
    x1 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[0]))
    x2 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[1]))
    x3 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[2]))
    x4 = GlobalAveragePooling2D()(squeeze_excite_block(short_cuts[3]))
    x = Concatenate()([x0, x1, x2, x3, x4])
    x = BatchNormalization()(x)
    x = Dropout(0.5)(x)
    x = Dense(256, activation='relu')(x)
    #x = BatchNormalization()(x)
    #x = Dropout(0.5)(x)
    #x = Dense(256, activation='relu')(x)
    x = BatchNormalization()(x)
    x = Dropout(0.5)(x)
    output = Dense(n_out, activation='sigmoid')(x)

    model = Model(input_tensor2, 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
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 = ResNet18(include_top=False,
                             weights='imagenet',
                             input_shape=(SIZE, SIZE, 3),input_tensor=input_tensor)

    x = base_model.get_layer('stage4_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
示例#6
0
    c0 = backbone.get_layer('relu0').output

    c1 = backbone.get_layer('stage2_unit1_relu1').get_output_at(0)  # 128
    c2 = backbone.get_layer('stage3_unit1_relu1').output  # 63
    enc_out = backbone.get_layer('stage4_unit1_relu1').output  # 32
    #c4 = backbone.get_layer('stage4_unit1_relu1').output  # 16
    #enc_out = backbone.output  # 8

    short_cuts = [c0, c1, c2]
    return enc_out, short_cuts


input_tensor = Input(shape=(SIZE, SIZE, 3))
base_model = ResNet18(include_top=False,
                      weights='imagenet',
                      input_shape=(SIZE, SIZE, 3),
                      input_tensor=input_tensor)


def create_model(input_shape, n_out):

    input_tensor2 = Input(shape=(SIZE, SIZE, 4))
    #bn = BatchNormalization()(input_tensor)
    #conv = Conv2D(3,(3,3),padding='same',activation='relu')(bn)

    base_model2 = ResNet18(include_top=False,
                           weights=None,
                           input_shape=(SIZE, SIZE, 4),
                           input_tensor=input_tensor2)

    # transfer weights of deeper layers