Example #1
0
def init(model_path, is_decaf6=False):
    if is_decaf6:
        K.set_image_data_format('channels_first')
        base_model = decaf()
        predictions = Dense(25, activation='softmax')(base_model.output)
        model = Model(inputs=base_model.input, outputs=predictions)
        model.load_weights(model_path, by_name=True)
    else:
        model = load_model(model_path)
    model.compile(optimizer='rmsprop', loss='categorical_crossentropy',
                  metrics=['accuracy', metrics.top_k_categorical_accuracy])    
    return model
Example #2
0
params = vars(args)

# BUILDING MODEL

if model_name == 'alexnet_empty':
    K.set_image_data_format('channels_first')
    size = (227, 227)
    model = alexnet(weights=None)
    for layer in model.layers:
        layer.trainable = True

elif model_name == 'decaf6':
    K.set_image_data_format('channels_first')
    size = (227, 227)
    base_model = decaf()
    predictions = Dense(25, activation='softmax')(base_model.output)
    model = Model(inputs=base_model.input, outputs=predictions)
    for layer in base_model.layers:
        layer.trainable = False

elif model_name == 'resnet':
    K.set_image_data_format('channels_last')
    size = (224, 224)

    base_model = resnet_trained(n_layers_trainable)
    predictions = Dense(25, activation='softmax')(base_model.output)
    model = Model(inputs=base_model.input, outputs=predictions)

elif model_name == 'inception':
    K.set_image_data_format('channels_last')