Skip to main content

Padim Anomaly Detection package

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

padim_ad-0.0.2.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

padim_ad-0.0.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file padim_ad-0.0.2.tar.gz.

File metadata

  • Download URL: padim_ad-0.0.2.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.17

File hashes

Hashes for padim_ad-0.0.2.tar.gz
Algorithm Hash digest
SHA256 24162a61acd17f253bcfee23c4f0c2c95e9bf7f5a7a57d64b8e85b9e1670cc39
MD5 4902a0daac64a551fe0bf27a5902eb32
BLAKE2b-256 c76fd0077b8db0794fe142c103abf7a44f831cee7e7621d899d678bba0fb7348

See more details on using hashes here.

File details

Details for the file padim_ad-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: padim_ad-0.0.2-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

Hashes for padim_ad-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5a088e396fafded2f987b3e8838b999cd80c90e7a606a809a80c2e23ed48073a
MD5 67f306da2e929a53e2bfad6f778e1542
BLAKE2b-256 92337cb04c59a3f0806e33491c2c83e6d34cf87d57054cea1a6b72c93ea068aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page