API Reference: Architecture

ArchitectureParams

class masterful.architecture.ArchitectureParams(task=None, num_classes=None, ensemble_multiplier=1, custom_objects=None, model_config=None, backbone_only=False, input_shape=None, input_range=None, input_dtype=None, input_channels_last=True, prediction_logits=None, prediction_dtype=None, prediction_structure=None, prediction_shape=None, total_parameters=None, total_trainable_parameters=None, total_non_trainable_parameters=None)

Model architecture parameters.

Parameters describing the model architecture used during training. These parameters describe structural attributes of the model, like input and output shapes, as well as higher order semantic parameters such as the task the model is attempting to solve.

Parameters
  • task (masterful.enums.Task) – A semantic description of the a model’s predictions or groundtruth labels, such as single-label classification (CIFAR10/Imagenet) and detection (COCO).

  • num_classes (int) – The number of possible classes in the model prediction.

  • ensemble_multiplier (int) – The number of models to train as part of an ensemble. Defaults to 1, which disables ensembling and trains only a single model.

  • custom_objects (Dict) – Some TF/Keras models have custom objects (layers, initializers, etc). If so, in order to load/save/clone the model, you need to let TF/Keras know how to load/save them. A dictionary of class mappings is the typical way to do this.

  • model_config (object_detection.protos.model.DetectionModel) – If the model is a Tensorflow Object Detection model, this is the configuration used to build the model.

  • backbone_only (bool) – True if this model represents a backbone (feature extractor) only, without a classification or task specific head. Defaults to False.

  • input_shape (Tuple) – The input shape of image data the model expects, in the format (height, width, channels) if input_channels_last=True, otherwise (channels, height, width) if input_channels_last=False.

  • input_range (masterful.enums.ImageRange) – The range of pixels in the input image space that the model is expecting.

  • input_dtype (tensorflow.python.framework.dtypes.DType) – The image data type the model expects.

  • input_channels_last (bool) – The ordering of the dimensions in the inputs. input_channels_last=True corresponds to inputs with shape (height, width, channels) while input_channels_last=False corresponds to inputs with shape (channels, height, width). Defaults to True.

  • prediction_logits (bool) – True the model’s output prediction is has no activation function. False means the model output is activated with a sigmoid or softmax layer.

  • prediction_dtype (tensorflow.python.framework.dtypes.DType) – The dtype of the predictions.

  • prediction_structure (masterful.enums.TensorStructure) – The tensor structure of the model predictions.

  • prediction_shape (Tuple) – The tensor shape of the model predictions. Only valid if the prediction_structure corresponds to SINGLE_TENSOR.

  • total_parameters (int) – Number of params of a model architecture

  • total_trainable_parameters (int) – Number of params that are updated trhough backprop inside a model architecture, e.g. un-frozen layer weights and biases.

  • total_non_trainable_parameters (int) – Number of params that are not updated trhough backprop inside a model architecture, e. g. frozen layer weights, biases or batch normalization parameters.

Return type

None

learn_architecture_params

masterful.architecture.learn_architecture_params(model, task, input_range, num_classes, prediction_logits, custom_objects={}, backbone_only=False, ensemble_multiplier=1)

Architecture parameter learner.

Learns the parameters of the given model. Most attributes can be introspected from the model itself. Any attributes that cannot be introspected can be passed into the function, or set on the ArchitectureParams after creation.

Example:

model: tf.keras.Model = ...
architecture_params = masterful.architecture.learn_architecture_params(
    model=model,
    task=masterful.enums.Task.CLASSIFICATION,
    input_range=masterful.enums.ImageRange.ZERO_255,
    num_classes=10,
    prediction_logits=False)
Parameters
  • model (keras.engine.training.Model) – The model to learn the parameters for.

  • task (masterful.enums.Task) – A semantic description of the a model’s predictions or groundtruth labels, such as single-label classification (CIFAR10/Imagenet) and detection (COCO).

  • input_range (masterful.enums.ImageRange) – The range of pixels in the input image space that the model is expecting.

  • num_classes (int) – The number of possible classes in the model prediction. If the model is a backbone only, then this should still be provided and represents the number of classes that should exist in in the classification head of the model.

  • prediction_logits (bool) – True the model’s output prediction is has no activation function. False means the model output is activated with a sigmoid or softmax layer.

  • custom_objects (Dict) – Some TF/Keras models have custom objects (layers, initializers, etc). If so, in order to load/save/clone the model, you need to let TF/Keras know how to load/save them. A dictionary of class mappings is the typical way to do this.

  • backbone_only (bool) – True if this model represents a backbone (feature extractor) only, without a classification or task specific head. Defaults to False.

  • ensemble_multiplier (int) – The number of models to train as part of an ensemble. Defaults to 1, which disables ensembling and trains only a single model.

Returns

An instance of ArchitectureParams describing the attributes of the model.

Return type

masterful.architecture.params.ArchitectureParams

predictions_to_labels

masterful.architecture.detection.predictions_to_labels(detection_model, max_bounding_boxes)

Converts raw predictions from a DetectionModel into Masterful labels. This relies on DetectionModel.postprocess() to convert the raw predictions into “detections”, and then we convert the detections into Masterful format.

Parameters
  • detection_model (DetectionModel) – The DetectionModel that will postprocess the predictions.

  • max_bounding_boxes (int) – The maximum number of bounding boxes to convert.

Returns

A Callable function which can convert predictions to labels.