I'm new to keras and deep learning. I'have tried to use data augmentation for for training my model, but not sure if i'm doing it the right way. Can anyone assure me it my approach is correct? here is my code:
train_path = 'Digital_Mamo/OPTIMAM' # Relative Path
valid_path = 'Digital_Mamo/InBreast'
test_path = 'Digital_Mamo/BCDR'
valid_batches = ImageDataGenerator().flow_from_directory(valid_path, target_size=(224, 224), classes=['Benign', 'Malignant'], batch_size=9)
test_batches = ImageDataGenerator().flow_from_directory(test_path, target_size=(224, 224), classes=['Benign', 'Malignant'], batch_size=7)
datagen = ImageDataGenerator(rotation_range=10, width_shift_range=0.1,
height_shift_range=0.1, shear_range=0.15, zoom_range=0.1,
channel_shift_range=10., horizontal_flip=True)
train_batches = datagen.flow_from_directory(
train_path,
target_size=(224, 224),
batch_size=10,
classes=['Benign','Malignant'])
vgg16_model= load_model('Fetched_VGG.h5')
# transform the model to Sequential
model= Sequential()
for layer in vgg16_model.layers[:-1]:
model.add(layer)
model.summary()
# Freezing the layers (Oppose weights to be updated)
for layer in model.layers:
layer.trainable = False
model.add(Dense(2, activation='softmax', name='predictions'))
### Compile the model
model.compile(Adam(lr=.0001), loss='categorical_crossentropy', metrics=['accuracy'])
# train the model
model.fit_generator(train_batches, steps_per_epoch=28, validation_data=valid_batches, validation_steps=3, epochs=5, verbose=2)
#test
predictions = model.predict_generator(test_batches, steps=3, verbose=0)