0

Ich versuche, die letzte Schicht des VGG-16 fein abzustimmen. Hier ist der Teil des Codes, wo ich das neue Modell machen:Probleme mit Eingabeformen bei der Feineinstellung von VGG mit Keras

def train2false(model): 
    for layer in model.layers: 
     layer.trainable = False 
    return model 

def define_training_layers(model): 
    model.layers = model.layers[0:21] 
    model = train2false(model) 
    last_layer = model.get_layer('fc7') 
    out = Dense(n_classes, activation='softmax', name='fc8')(last_layer) 
    model = Model(input=model.input, output=out) 
    return model 

def compile_model(epochs, lrate, model): 
    decay = lrate/epochs 
    sgd = SGD(lr=lrate, momentum=0, decay=0.0002, nesterov=True) 
    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy']) 
    print (model.summary()) 

    return model 

def train_evaluate(model, X_train, y_train, X_test, y_test, epochs): 
    model.fit(X_train, y_train, validation_data=(X_test, y_test), nb_epoch=epochs, batch_size=32) 
    # Final evaluation of the model 
    scores = model.evaluate(X_test, y_test, verbose=0) 
    print("Accuracy: %.2f%%" % (scores[1]*100)) 

    return model 

X_train, X_test, labels_test, labels_train, n_classes = load_dataset() 
image_input = Input(shape=(3, 224, 224)) 
vgg_model = VGGFace(input_tensor= image_input, include_top=True) 
custom_vgg_model = define_training_layers(vgg_model) 
custom_vgg_model = compile_model(epochs=50, lrate=0.001, model=custom_vgg_model) 
custom_vgg_model = train_evaluate(custom_vgg_model, X_train=X_train, y_train=labels_train, X_test=X_test, y_test=labels_test, epochs=50) 

bekomme ich folgende Fehlermeldung:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, 
but are 1000 and 2622 for 'Assign_30' (op: 'Assign') with input shapes: [4096,1000], [4096,2622]. 

Es funktioniert für mich, wenn ich versuche, alle voll mit include_top=False verbundenen Teil finetune anstatt nur die softmax Aktivierung.

Gibt es etwas, das ich vermisse?

Danke !!!

Antwort

Verwandte Themen