Reputation: 575
I was on the process of training a VGG16 fine-tuned model.After the first epoch,the program stopped and gave this error:
Below is the code I used for the model:
# create a copy of a mobilenet model
import keras
vgg_model=keras.applications.vgg16.VGG16()
type(vgg_model)
vgg_model.summary()
from keras.models import Sequential
model = Sequential()
for layer in vgg_model.layers[:-1]:
model.add(layer)
model.summary()
# CREATE THE MODEL ARCHITECTURE
from keras.layers import Dense, Activation, Dropout
model.add(Dropout(0.25))
model.add(Dense(7,activation='softmax'))
model.summary()
#Train the Model
# Define Top2 and Top3 Accuracy
from keras.metrics import categorical_accuracy, top_k_categorical_accuracy
def top_3_accuracy(y_true, y_pred):
return top_k_categorical_accuracy(y_true, y_pred, k=3)
def top_2_accuracy(y_true, y_pred):
return top_k_categorical_accuracy(y_true, y_pred, k=2)
from keras.optimizers import Adam
model.compile(Adam(lr=0.01), loss='categorical_crossentropy',
metrics=[categorical_accuracy, top_2_accuracy, top_3_accuracy])
# Get the labels that are associated with each index
print(valid_batches.class_indices)
# Add weights to try to make the model more sensitive to melanoma
class_weights={
0: 1.0, # akiec
1: 1.0, # bcc
2: 1.0, # bkl
3: 1.0, # df
4: 3.0, # mel # Try to make the model more sensitive to Melanoma.
5: 1.0, # nv
6: 1.0, # vasc
}
filepath = "skin.h5"
checkpoint = ModelCheckpoint(filepath, monitor='val_top_3_accuracy', verbose=1,
save_best_only=True, mode='max')
reduce_lr = ReduceLROnPlateau(monitor='val_top_3_accuracy', factor=0.5, patience=2,
verbose=1, mode='max', min_lr=0.00001)
callbacks_list = [checkpoint, reduce_lr]
history = model.fit_generator(train_batches, steps_per_epoch=train_steps,
class_weight=class_weights,
validation_data=valid_batches,
validation_steps=val_steps,
epochs=40, verbose=1,
callbacks=callbacks_list)
I am trying to learn how to fine tune, train and use VGG16 model on image dataset. I was following this blog where he used mobileNet.
I was following this VGG16 tutorial to write the code for the model.
If anyone can help me fix this error or explain how and why it happened I would highly appreciate your help.
Dependencies:
Upvotes: 3
Views: 1080
Reputation: 180
I had the same error when I used the ReduceLROnPlateau
callback. Unless it's absolutely necessary, you can maybe omit its usage.
Upvotes: 3