Skip to content

Image Classifer

class ImageClassifier

Class that represents the classifier for images.

The following pretrained CNNs from Keras can be used as base model:

  • Xception

  • VGG16

  • VGG19

  • ResNet50, ResNet101, ResNet152

  • ResNet50V2, ResNet101V2, ResNet152V2

  • ResNeXt50, ResNeXt101

  • InceptionV3

  • InceptionResNetV2

  • MobileNet

  • MobileNetV2

  • DenseNet121, DenseNet169, DenseNet201

  • NASNetLarge, NASNetMobile

Attributes
  • base_model_name: Name of Keras base model.

  • n_classes: Number of classes.

  • learning_rate: Learning rate for training phase.

  • dropout_rate: Fraction set randomly.

  • loss: A loss function as one of two parameters to compile the model.

  • weights: Pretrained weights the model architecture is loaded with (default imagenet).

__init__

def __init__(base_model_name, n_classes, learning_rate, dropout_rate, loss, weights)

Inits ImageClassifier object.

Loads Keras base_module specified by base_model_name.

get_base_layers

def get_base_layers()

Gets layers of classifiers' base model

Returns
  • base_layers: list of layers

get_preprocess_input

def get_preprocess_input()

Gets preprocess_input of classifiers' base_module

Returns
  • preprocess_input: Callable

set_learning_rate

def set_learning_rate(learning_rate)

sets classifiers' learning_rate

Args
  • learning_rate: the learning_rate.

build

def build()

Builds classifiers' model.

The following steps will be performed in sequence:

  • Loads a pretrained base model.

  • Adds dropout and dense layer to the model.

  • Sets classifiers' model.

compile

def compile()

Configures classifiers' model for training.

fit_generator

def fit_generator(**kwargs)

Trains classifiers' model on data generated by a Python generator.

Args
  • generator: Input samples from a data generator on which to train the model.

  • validation_data: Input samples from a data generator on which to evaluate the model.

  • epochs: Number of epochs to train the model.

  • initial_epoch: Epoch at which to start training.

  • verbose: Verbosity mode.

  • use_multiprocessing: Use process based threading.

  • workers: Maximum number of processes.

  • max_queue_size: Maximum size for the generator queue.

  • callbacks: List of callbacks to apply during training.

Returns
  • history: A History object.

predict_generator

def predict_generator(data_generator, **kwargs)

Generates predictions for the input samples from a data generator.

Args
  • data_generator: Input samples from a data generator.

  • workers: Maximum number of processes.

  • use_multiprocessing: Use process based threading.

  • verbose: Verbosity mode.

Returns
  • history: A History object.

summary

def summary()

Summarizes classifiers' model.