Create Models Quickly

This helps you to create a model ready for training all in a single line of code.
This includes loading the pretrained model along with the weights, addition of the the classification model on top of pretrained model and the compilation of the model. All in a single line of code.
The function is situated in the load_models_quick module of quick_ml package.

create_model() function parameters/arguments :-





Arguments Description =>
    classes - Number of classes for classification.
    model_name - Name of the model. Default, VGG16.
Available models ->
MODELS -> 'VGG16', 'VGG19',
         'DenseNet121', 'DenseNet169', 'DenseNet201',
         'ResNet50', 'ResNet101', 'ResNet152', 'ResNet50V2', 'ResNet101V2', 'ResNet152V2',
         'MobileNet', 'MobileNetV2',
         'InceptionV3', 'InceptionResNetV2',
         'EfficientNetB0', 'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3', 'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', 'EfficientNetB7'

    classification_model - The classification model which you want to attach as the top to the pretrained model. The 'default' classification model has a Global Average Pooling2D followed by Dense layer with output nodes same as the number of classes for classification.
You can define your own classification_model (Sequential Model) and pass the model as an argument to the classification model.

class_model = tf.keras.Sequential([ tf.keras.layers(), tf.keras.layers() ]) get_models_training_report(models, tpu, n_class, traindata, steps_per_epoch, epochs, val_data, classification_model = class_model)

    freeze - True or False. Whether or not to freeze the pretrained model weights while training the model. Default, False.
    input_shape - Input shape of the images of the TFRecords Dataset. Default, [512,512,3]
    activation - The activation function to be used for the final layer of the classification model put on top of the pretrained model. For Binary Classification, use 'sigmoid'. For multi-class classification, use 'softmax'. Default, 'softmax'.
    weights - What kind of weights to use for the pretrained model you have decided as your model backbone. Default, 'imagenet'. Options, 'imagenet' & None. In case you are using 'imagenet' weights, ensure you have loaded TF Keras pretrained weights in your Kaggle Notebook.
    optimizer - The optimizer to be used for converging the model while training. Default, 'adam'.
    loss - Loss function for the model while training. Default, 'sparse_categorical_crossentropy'. Options, 'binary_crossentropy' or 'sparse_categorical_crossentropy'. Use 'binary_crossentropy' for Binary Classifications. Use 'sparse_categorical_crossentropy' for multi-class classifications. Support for 'categorical_crossentropy' is not provided as it is computationally expensive. Both sparse & categorical cross entropy serve the same purpose.
    metrics - The metrics for gauging your model's training performance. Default, 'sparse_categorical_accuracy'. Options, 'sparse_categorical_accuracy' & 'accuracy'. For Binary Classifications, use 'accuracy'. For Multi-class classifications, use 'sparse_categorical_accuracy'.


Returns =>
A tf.keras.Sequential compiled Model with base model as the pretrained model architecture name specified along with the classification model attached. This model is ready for training via

from quick_ml.load_models_quick import create_model

model = create_model(classes, model_name = 'VGG16', classification_model = 'default', freeze = False, input_shape = [512,512,3], activation = 'softmax', weights = 'imagenet', optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = 'sparse_categorical_accuracy')

Was this helpful?