This template is licensed under Apache 2.0 and contains the following components:
- anomalib Apache 2.0
- pytorch-lightning Apache 2.0
- matplotlib MDT
The purpose of anomaly detection via computer vision is to identify and flag instances in visual data that deviate significantly from what is considered normal or expected. Anomalies, also known as outliers, are data points or patterns that differ substantially from the majority of the data, either due to errors, defects, fraud, or any other unusual circumstances. Anomaly detection in computer vision involves leveraging machine learning and image processing techniques to automatically identify such anomalies in images or videos.
In this project, we go through the process of applying anomaly detection for the purposes of quality control and defect detection. We fit a PaDIM model against the MVTecAD dataset using Anomalib, a comprehensive deep learning library designed to serve as a hub for state-of-the-art anomaly detection algorithms.
The assets included in the project are:
anomaly_detection.ipynb - A notebook that walks the user over the process of acquiring the MVTecAD dataset and storing it as a Domino Dataset. It also configures, trains, and runs a test inference call with the PaDIM model. The trained model is also persisted in padim
for the purposes of deploying it as a Model API.
score.py - a scoring function that exposes the persisted model as Model API. The score function accepts an image path as an argument and returns a boolean prediction (anomalous or not) and a confidence score of the prediction.
Please refer to the AI Hub meta data to get information about the environment needed to run this project . Alternately, please create an environment based off of a Domino Standard Environment (DSE), that contains Python 3.9 or above.
Add the following entries to the Dockerfile:
USER ubuntu
RUN pip install --user anomalib==0.6.0 \
&& pip install --user openvino==2023.0.1
RUN pip install --user openvino-dev[pytorch,onnx]==2023.0.1
Don't forget to expose the relevant IDEs as pluggable workspaces, as described in the Domino Documentation.
This project works with a standard small-sized hardware tier, such as the small-k8s tier on all Domino deployments.
The scoring endpoint expects an image path as its input. For this to work, the model version needs to be configured with a Kubernetes volume, where the scored images are uploaded. The call then takes the form of
{
"data": {
"image": "[volume]/[image.png]"
}
}