I follow the document to apply transfer learning on xception model to classify cats and dogs:
But the results I achieved is very pool.
Here is the architecture code:
from keras.layers import Input, Dense, Flatten
from keras.models import Model
from keras.applications import Xception
def build_model(input_shapes, n_classes=None):
#### DEFINING INPUT AND BASE ARCHITECTURE
# You need to modify the name and shape of the "image_input"
# according to the preprocessing and name of your
# initial feature.
# This feature should to be preprocessed as an "Image", with a
# custom preprocessing.
image_input = Input(shape=(299,299,3), name="path_preprocessed")
base_model = Xception(include_top=False, weights=None, input_tensor=image_input)
#### LOADING WEIGHTS OF PRE TRAINED MODEL
# To leverage this architecture, it is better to use weights
# computed on a previous training on a large dataset (Imagenet).
# To do so, you need to download the file containing the weights
# and load them into your model.
# You can do it by using the macro "Download pre-trained model"
# of the "Deep Learning image" plugin (CPU or GPU version depending
# on your setup) available in the plugin store. For this architecture,
# you need to select:
# "Xception trained on Imagenet"
# This will download the weights and put them into a managed folder
folder = dataiku.Folder("xception_weights")
weights_path = "xception_imagenet_weights_notop.h5"
for layer in base_model.layers:
layer.trainable = False
#### ADDING FULLY CONNECTED CLASSIFICATION LAYER
x = base_model.layers[-1].output
x = Flatten()(x)
predictions = Dense(n_classes, activation="softmax")(x)
model = Model(input=base_model.input, output=predictions)
Here is code for training:
from dataiku.doctor.deep_learning.sequences import DataAugmentationSequence
from keras.preprocessing.image import ImageDataGenerator
from keras import callbacks
# A function that builds train and validation sequences.
# You can define your custom data augmentation based on the original train and validation sequences
# build_train_sequence_with_batch_size - function that returns train data sequence depending on
# batch size
# build_validation_sequence_with_batch_size - function that returns validation data sequence depending on
# batch size
def build_sequences(build_train_sequence_with_batch_size, build_validation_sequence_with_batch_size):
batch_size = 16
augmentator = ImageDataGenerator(
train_sequence = build_train_sequence_with_batch_size(batch_size)
validation_sequence = build_validation_sequence_with_batch_size(batch_size)
augmented_sequence = DataAugmentationSequence(
return augmented_sequence, validation_sequence
# A function that contains a call to fit a model.
# model - compiled model
# train_sequence - train data sequence, returned in build_sequence
# validation_sequence - validation data sequence, returned in build_sequence
# base_callbacks - a list of Dataiku callbacks, that are not to be removed. User callbacks can be added to this list
def fit_model(model, train_sequence, validation_sequence, base_callbacks):
epochs = 10
callback = callbacks.ReduceLROnPlateau(
From the training curve, I do not think to increase epochs will be helpful. What could be the problem?