tlt.models.image_anomaly_detection.torchvision_image_anomaly_detection_model.TorchvisionImageAnomalyDetectionModel¶
- class tlt.models.image_anomaly_detection.torchvision_image_anomaly_detection_model.TorchvisionImageAnomalyDetectionModel(model_name: str, **kwargs)[source]¶
Class to represent a Torchvision pretrained model for anomaly detection
Methods
__init__
(model_name, **kwargs)Class constructor
benchmark
(dataset[, saved_model_dir, ...])Use Intel Neural Compressor to benchmark the model with the dataset argument.
cleanup_saved_objects_for_distributed
()evaluate
(dataset[, pca_mats, use_test_set, ...])Evaluate the accuracy of the model on a dataset.
export
(output_dir)Exports a trained model as a model.pt file along with the PCA components as pca_mats.pkl.
export_for_distributed
([export_dir, ...])Exports the model, optimizer, loss, train data and validation data to the export_dir for distributed script to access.
freeze_layer
(layer_name)Freezes the model's layer using a layer name :param layer_name: The layer name that will be frozen in the model :type layer_name: string
list_layers
([verbose])Lists all of the named modules (e.g.
load_checkpoint_weights
(model_name, ...[, ...])Load checkpoints from the given checkpoint directory based on feature extractor
load_from_directory
(model_dir)Load a saved model and its PCA components from the model_dir path
load_pretrained_model
()Return PyTorchImageAnomalyDetectionModel object for feature extraction and finding PCA
optimize_graph
(output_dir[, overwrite_model])Performs FP32 graph optimization using the Intel Neural Compressor on the model and writes the inference-optimized model to the output_dir. Graph optimization includes converting variables to constants, removing training-only operations like checkpoint saving, stripping out parts of the graph that are never reached, removing debug operations like CheckNumerics, folding batch normalization ops into the pre-calculated weights, and fusing common operations into unified versions. :param output_dir: Writable output directory to save the optimized model :type output_dir: str :param overwrite_model: Specify whether or not to overwrite the output_dir, if it already exists (default: False) :type overwrite_model: bool.
predict
(input_samples[, pca_mats, ...])Perform inference and predict the class of the input_samples.
quantize
(output_dir, dataset[, config, ...])Performs post training quantization using the Intel Neural Compressor on the model using the dataset.
train
(dataset, output_dir[, epochs, ...])Trains the model using the specified image anomaly detection dataset.
train_cutpaste
(dataset, output_dir, optim, ...)Trains a CutPaste model using the specified dataset.
train_simsiam
(dataset, output_dir, epochs, ...)Trains a SimSiam model using the specified dataset.
unfreeze_layer
(layer_name)Unfreezes the model's layer using a layer name :param layer_name: The layer name that will be frozen in the model :type layer_name: string
Attributes
do_fine_tuning
When True, the weights in all of the model's layers will be trainable.
dropout_layer_rate
The probability of any one node being dropped when a dropout layer is used
framework
Framework with which the model is compatible
image_size
The fixed image size that the pretrained model expects as input, in pixels with equal width and height
learning_rate
Learning rate for the model
model_name
Name of the model
num_classes
The number of output neurons in the model; equal to the number of classes in the dataset
preprocessor
Preprocessor for the model
use_case
Use case (or category) to which the model belongs