Skip to content

Detecting images that deviate from the norm - My Masters thesis project

Notifications You must be signed in to change notification settings

circle-queue/anomaly-detection-public

Repository files navigation

Anomaly detection

Disclaimer

The folders under src contains modified version of the following repositories:

Prerequsites

  • CUDA 12.1 (Windows install: winget install -e --id Nvidia.CUDA -v 12.1)
  • For patchcore, faiss-gpu is required, which is Linux only

Installation

python -m pip install poetry
poetry config virtualenvs.in-project true

poetry install --with dev --with ipy --with plotting
poetry shell

Setup

# These scripts must be run in seperate CMDs and kept alive while metrics are logged
poetry run mlflow server
# Allow sagemaker notebooks to connect to the mlflow server (Assumes you've configureed ~/.ssh/config, e.g. using `gdmake`)
ssh -o ExitOnForwardFailure=yes -R 5000:127.0.0.1:5000 christoffer-sommerlund-thesis
ssh -o ExitOnForwardFailure=yes -R 5000:127.0.0.1:5000 christoffer-sommerlund-patchcore

Run

The entire suite of experiments are located in experiments. The backbones must be run before the classifiers

source experiments/backbones/train_scavport_backbones.sh
source experiments/backbones/train_vesselarchive_backbones.sh
source experiments/backbones/train_backbones_for_scavport_clfs.sh
source experiments/backbones/train_backbones_for_condition_clfs.sh

NOTE: This will take multiple days to complete and may crash if your GPU has below 24GB ram and is not on a Linux machine.

To run a single experiment, you can invoke it from the CLI, e.g..

python -m anomaly_detection
    dataloader-condition
        --sub-dataset=images-scavengeport-overview
        --transform=resnet18
        --train-classes=['good']
        --test-classes=['good','abnormal']
        --batch-size=1
    set-outliers
        --labels-inliers=['good']
        --labels-outliers=['abnormal']
    add-model
        --model-name=resnet18_T-S
        --weights=imagenet
    add-task--teacher-student-anomaly
        --cfg='"optuna"'
    run-optuna
        --optuna-direction=maximize
        --optuna-metric-name=anomaly_auc
        --trial-overrides="{"n_samples":lambda trial:trial.suggest_int("n_samples",1,1000,log=True)}"
        --params-cls=TSAnomalyParams

To add a custom dataset, you need to add a command in __main__.py, which invokes model_builder.py. The datasets are assumed to have the following structure .../{dataset_name}/{train,dev,test}/{label1,label2,label3}/{*.jpg}

About

Detecting images that deviate from the norm - My Masters thesis project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published