Padim Anomaly Detection package for image anomaly detection and localization
Project description
Introduction
This is an unofficial implementation of the paper: https://arxiv.org/abs/2011.08785 The aim of this project is to provide a good entry point of retraining the algorithm on a different dataset with different needs.
Get Started
install all the requirements
pip install -r requirements.txt
For using the padim anomaly detector you should separate your dataset into 3 chunks:
- Training
- Calibration
- Test
While training and calibration contain no anomalies, so are only "good" data the testing dataset should contain some anomalies to check whether the algorithm is properly working.
The training dataset is used to create the features that are used to setup the system. The calibration dataset is for setting a threshold to compare against real anomalies.
First we need to instantiate an anomaly detector with:
import numpy as np
from PIL import Image
from anomaly_detection_padim.PadimAD import PadimAnomalyDetector
from anomaly_detection_padim.config.DTO import PadimADConfig
from anomaly_detection_padim.data.transform import DataTransform
from anomaly_detection_padim.data.dataset import PadimDataset
path_train_data = r'<insert_train_path>'
path_calibration_data = r'<insert_calibration_path>'
anomaly_im_path = r'<path_to_anomalous_image>'
config = PadimADConfig(
model_name='wide_resnet50_2',
device='cuda',
batch_size=8
)
padim_ad = PadimAnomalyDetector(config=config)
train_dataset = PadimDataset(data_path=path_train_data, transform=DataTransform.get_train_transform())
padim_ad.train_anomaly_detection(dataset=train_dataset)
calibration_dataset = PadimDataset(data_path=path_calibration_data, transform=DataTransform.get_test_transform())
src_im = Image.open(anomaly_im_path).convert('RGB')
anom_score = padim_ad.detect_anomaly(
im=src_im,
transform=DataTransform.get_test_transform(),
normalize=True,
)
anomaly_im = Image.fromarray(anom_score.astype(np.uint8))
How to use the GUI
this repository provides
Roadmap
- Add Variable Image Sizes to the Padim Anomaly Detector
- Forward the variable image size to the GUI
- Add status message for training and calibration part
- rework home frame
- create api to serve the anomaly detection results
- add storing anomaly detectors (serializing to disk)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file padim_ad-0.0.3.tar.gz.
File metadata
- Download URL: padim_ad-0.0.3.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73182124c91c70ad3c9c524386e30f4d89c9c666efe3ad1a91cb15768354168a
|
|
| MD5 |
d1671711db17c472bc2b00c036b50a0f
|
|
| BLAKE2b-256 |
794911ae89b800efb0c6d7ac1bd965e0d4da4fc93d020271d8c481caaf5c5758
|
File details
Details for the file padim_ad-0.0.3-py3-none-any.whl.
File metadata
- Download URL: padim_ad-0.0.3-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84591f35502778787991efe9777fd902402458efcbfee9b001cd3762f08a18fc
|
|
| MD5 |
d2058a9ee3a1bfa6c20aae725dc319ee
|
|
| BLAKE2b-256 |
67a4ae12b32b5a45b0c22622a8649441e47d8e6c0a2b027c8c31965d0e6f4b7e
|