def MyXception(imageShape, nClasses, trainable="onlyTop", dropout=None): # Load pretrained model modelBase = xception.Xception(include_top = False, input_shape = imageShape, \ weights = "imagenet") # Add top x = modelBase.outputs[0] x = GlobalAveragePooling2D(name="avg_pool")(x) if dropout is not None: print("Using dropout", dropout) x = Dropout(dropout, name="dropout")(x) x = Dense(nClasses, activation="softmax", name='predictions')(x) model = Model(modelBase.inputs, x, name="xception") # Add method to instance (not very good idea) model.SetTrainable = SetTrainableXception.__get__(model, type(model)) # Set trainable mode model.SetTrainable(trainable) return model