Anomaly#
The AnomalyModel
is a generic OpenVINO model that aims to provide a single interface for all the exported models based on Anomalib.
Currently, the AnomalyModel
supports the following models:
Padim
STFPM
Definition for anomaly models.
Note: This file will change when anomalib is upgraded in OTX. CVS-114640
- class model_api.models.anomaly.AnomalyDetection(inference_adapter, configuration={}, preload=False)#
Bases:
ImageModel
Anomaly Detection model.
Generic anomaly detection model that acts as an inference wrapper for all the exported models from Anomalib.
- Parameters:
inference_adapter (InferenceAdapter) – Inference adapter
configuration (dict, optional) – Configuration parameters. Defaults to {}.
preload (bool, optional) – Whether to preload the model. Defaults to False.
Example
>>> from model_api.models import AnomalyDetection >>> import cv2 >>> model = AnomalyDetection.create_model("./path_to_model.xml") >>> image = cv2.imread("path_to_image.jpg") >>> result = model.predict(image) AnomalyResult(anomaly_map=array([[150, 150, 150, ..., 138, 138, 138], [150, 150, 150, ..., 138, 138, 138], [150, 150, 150, ..., 138, 138, 138], ..., [134, 134, 134, ..., 138, 138, 138], [134, 134, 134, ..., 138, 138, 138], [134, 134, 134, ..., 138, 138, 138]], dtype=uint8), pred_boxes=None, pred_label='Anomaly', pred_mask=array([[1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], ..., [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1]], dtype=uint8), pred_score=0.8536462108391619)
Image model constructor
It extends the Model constructor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the wrapper failed to define appropriate inputs for images
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Return type:
dict
- Returns:
the dictionary with defined wrapper data parameters
- postprocess(outputs, meta)#
Post-processes the outputs and returns the results.
- Parameters:
outputs (Dict[str, np.ndarray]) – Raw model outputs
meta (Dict[str, Any]) – Meta data containing the original image shape
- Returns:
Results
- Return type:
AnomalyResult