Хотя я использую StratifiedKFold, точность всегда 0,5 - PullRequest
0 голосов
/ 07 мая 2019

Я использую предварительно обученную модель ResNet50 для классификации набора данных по малярии . После этого я добавил два плотных слоя с 1024, 2048 единицами соответственно и один слой классификации, используя функцию softmax (результаты хуже с сигмовидной оболочкой). Я использовал StratifiedKFold для проверки этой модели, но точность всегда равна 0,5 после первого сгиба.

После первого сгиба все эпохи одинаковы:

22047/22047  [==============================] - 37s 3ms/step - loss: 8.0596 - acc: 0.5000

Это моя модель:

height = 100 #dimensions of image
width = 100
channel = 3 #RGB
classes = 2

batch_size = 64 #vary depending on the GPU
epochs = 10
folds = 5
optimizer = "Adam"
metrics = ["accuracy"]
loss = 'categorical_crossentropy'

random_state = 1377
chanDim = -1

model = ResNet50(include_top=False, weights="imagenet", input_shape=(height, width, channel))

# Get the ResNet50 layers up to res5c_branch2c
model = Model(input=model.input, output=model.get_layer('res5c_branch2c').output)

for layer in model.layers:
    layer.trainable = False 

Flatten1 = Flatten()(model.output)

F1 = Dense(1024, activation='relu')(Flatten1)
D1 = Dropout(0.5)(F1)

F2 = Dense(2048, activation='relu')(D1)
D2 = Dropout(0.2)(F2)

F3 = Dense(classes, activation='softmax')(D2)

model = Model(inputs = model.input, outputs = F3)

# Compile the model
model.compile(loss = loss, optimizer = optimizer, metrics = metrics)

Это часть проверки:

# Create a model compatible with sklearn
model = KerasClassifier(build_fn=customResnetBuild, epochs=epochs, batch_size=batch_size)
kfold = StratifiedKFold(n_splits=folds, shuffle=False, random_state=random_state)

# Make a custom score for classification report method to get results for mean of the all folds
def classification_report_with_accuracy_score(y_true, y_pred):
    originalclass.extend(y_true)
    predictedclass.extend(y_pred)
    return accuracy_score(y_true, y_pred) # return accuracy score

scores = cross_val_score(model, data, labels, cv=kfold, error_score="raise", scoring=make_scorer(classification_report_with_accuracy_score) )
print(classification_report(originalclass, predictedclass)) 

Результат

Mean of results:  0.6404469896025613
          precision    recall  f1-score   support

       0       0.86      0.34      0.48     13781
       1       0.59      0.94      0.72     13779

   micro avg       0.64      0.64      0.64     27560
   macro avg       0.72      0.64      0.60     27560
weighted avg       0.72      0.64      0.60     27560

1 Ответ

0 голосов
/ 08 мая 2019

Это ответ.Напомним, проблема в том, что #parameters больше, чем #dataset, и использование trainable = false неверно.

...