class documentation

Configuration for running a TorchImageModel.

Models are represented by this class via the following three components:

  1. Model:

    # Directly specify a model
    model
    
    # Load model from an entrypoint
    model = entrypoint_fcn(**entrypoint_args)
    
  2. Transforms:

    # Directly provide transforms
    transforms
    
    # Load transforms from a function
    transforms = transforms_fcn(**transforms_args)
    
    # Use the `image_XXX` parameters defined below to build a transform
    transforms = build_transforms(image_XXX, ...)
    
  3. OutputProcessor:

    # Directly provide an OutputProcessor
    output_processor
    
    # Load an OutputProcessor from a function
    output_processor = output_processor_cls(**output_processor_args)
    

Given these components, inference happens as follows:

def predict_all(imgs):
    imgs = [transforms(img) for img in imgs]
    if not raw_inputs:
        imgs = torch.stack(imgs)

    output = model(imgs)
    return output_processor(output, ...)
Parameters
modela torch:torch.nn.Module instance to use
entrypoint_fcna function or string like "torchvision.models.inception_v3" specifying the entrypoint function that loads the model
entrypoint_argsa dictionary of arguments for entrypoint_fcn
transformsa preprocessing transform to apply
transforms_fcna function or string like "torchvision.models.Inception_V3_Weights.DEFAULT.transforms" specifying a function that returns a preprocessing transform function to apply
transforms_argsa dictionary of arguments for transforms_args
ragged_batcheswhether the provided transforms or transforms_fcn may return tensors of different sizes. This must be set to False to enable batch inference, if it is desired
raw_inputswhether to feed the raw list of images to the model rather than stacking them as a Torch tensor
output_processoran OutputProcessor instance to use
output_processor_clsa class or string like "fifytone.utils.torch.ClassifierOutputProcessor" specifying the OutputProcessor to use
output_processor_argsa dictionary of arguments for output_processor_cls(classes=classes, **kwargs)
confidence_threshan optional confidence threshold apply to any applicable predictions generated by the model
classesa list of class names for the model, if applicable
labels_stringa comma-separated list of the class names for the model, if applicable
labels_paththe path to the labels map for the model, if applicable
mask_targetsa mask targets dict for the model, if applicable
mask_targets_paththe path to a mask targets map for the model, if applicable
skeletona keypoint skeleton dict for the model, if applicable
image_min_sizeresize the input images during preprocessing, if necessary, so that the image dimensions are at least this (width, height)
image_min_dimresize input images during preprocessing, if necessary, so that the smaller image dimension is at least this value
image_max_sizeresize the input images during preprocessing, if necessary, so that the image dimensions are at most this (width, height)
image_max_dimresize input images during preprocessing, if necessary, so that the largest image dimension is at most this value.
image_sizea (width, height) to which to resize the input images during preprocessing
image_dimresize the smaller input dimension to this value during preprocessing
image_patch_sizecrop the input images during preprocessing, if necessary, so that the image dimensions are a multiple of this patch size
image_meana 3-array of mean values in [0, 1] for preprocessing the input images
image_stda 3-array of std values in [0, 1] for preprocessing the input images inputs that are lists of Tensors
embeddings_layerthe name of a layer whose output to expose as embeddings. Prepend "<" to save the input tensor instead
as_feature_extractorwhether to operate the model as a feature extractor. If embeddings_layer is provided, this layer is passed to torchvision's create_feature_extractor() function. If no embeddings_layer is provided, the model's output is used as-is for feature extraction
use_half_precisionwhether to use half precision (only supported when using GPU)
cudnn_benchmarka value to use for torch:torch.backends.cudnn.benchmark while the model is running
devicea string specifying the device to use, eg ("cuda:0", "mps", "cpu"). By default, CUDA is used if available, else CPU is used
Method __init__ Undocumented
Instance Variable as_feature_extractor Undocumented
Instance Variable classes Undocumented
Instance Variable confidence_thresh Undocumented
Instance Variable cudnn_benchmark Undocumented
Instance Variable device Undocumented
Instance Variable embeddings_layer Undocumented
Instance Variable entrypoint_args Undocumented
Instance Variable entrypoint_fcn Undocumented
Instance Variable image_dim Undocumented
Instance Variable image_max_dim Undocumented
Instance Variable image_max_size Undocumented
Instance Variable image_mean Undocumented
Instance Variable image_min_dim Undocumented
Instance Variable image_min_size Undocumented
Instance Variable image_patch_size Undocumented
Instance Variable image_size Undocumented
Instance Variable image_std Undocumented
Instance Variable labels_path Undocumented
Instance Variable labels_string Undocumented
Instance Variable mask_targets Undocumented
Instance Variable mask_targets_path Undocumented
Instance Variable model Undocumented
Instance Variable output_processor Undocumented
Instance Variable output_processor_args Undocumented
Instance Variable output_processor_cls Undocumented
Instance Variable ragged_batches Undocumented
Instance Variable raw_inputs Undocumented
Instance Variable skeleton Undocumented
Instance Variable transforms Undocumented
Instance Variable transforms_args Undocumented
Instance Variable transforms_fcn Undocumented
Instance Variable use_half_precision Undocumented

Inherited from Config:

Method __repr__ Undocumented
as_feature_extractor: False = (source)

Undocumented

confidence_thresh: None = (source)

Undocumented

cudnn_benchmark: None = (source)

Undocumented

Undocumented

embeddings_layer: None = (source)

Undocumented

entrypoint_args: None = (source)

Undocumented

entrypoint_fcn: None = (source)

Undocumented

image_dim: None = (source)

Undocumented

image_max_dim: None = (source)

Undocumented

image_max_size: None = (source)

Undocumented

image_mean: None = (source)

Undocumented

image_min_dim: None = (source)

Undocumented

image_min_size: None = (source)

Undocumented

image_patch_size: None = (source)

Undocumented

image_size: None = (source)

Undocumented

image_std: None = (source)

Undocumented

labels_path: None = (source)

Undocumented

labels_string: None = (source)

Undocumented

mask_targets: None = (source)

Undocumented

mask_targets_path: None = (source)

Undocumented

output_processor: None = (source)

Undocumented

output_processor_args: None = (source)

Undocumented

output_processor_cls: None = (source)

Undocumented

ragged_batches: None = (source)

Undocumented

raw_inputs: None = (source)

Undocumented

skeleton: None = (source)

Undocumented

transforms: None = (source)

Undocumented

transforms_args: None = (source)

Undocumented

transforms_fcn: None = (source)

Undocumented

use_half_precision: None = (source)

Undocumented