Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized padim #1473

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions anomaly_detection/padim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ You can specify the directory of normal product files with the `--train_dir` opt
$ python3 padim.py --train_dir train
```

The feature vectors created from files in the train directory are saved to the pickle file.
From the second time, by specifying the pickle file by `--feat` option,
The feature vectors created from files in the train directory can be saved to the pickle, numpy or pytorch file. For that you have to specify desired format as `npy`, `pt` or `pkl`. Depending on --enable_optimization flag, files saved might be originally pytorch tensors (True) or numpy arrays (False).
```bash
$ python3 padim.py --save_format pt
```

From the second time, by specifying the saved file by `--feat` option,
it can omit the calculation of the feature vector of the normal product.
The name of the pickle file created is the same as the name of a normal product file directory.
```bash
Expand Down Expand Up @@ -104,6 +108,20 @@ By adding the `--aug` option, you can process with augmentation.
$ python3 padim.py --aug
```

By adding the `--enable_optimization` option, you can use optimized code, which significantly speeds up distance matrix calculation. You have to have cuda compatible GPU and pytorch installed
(default is processing without optimization)
```bash
$ python3 padim.py --enable_optimization True
```

By adding the `--compare_optimization` option, you can compare output of the optimized code with the output of the original code. You have to have cuda compatible GPU and pytorch installed
(default is processing without comparison)
```bash
$ python3 padim.py --compare_optimization True
```



## PaDiM GUI

You can also use the GUI to train and test.
Expand All @@ -115,6 +133,7 @@ Start the GUI with the following command.
```bash
$ python3 padim_gui.py
```
Specify the inference mode from the `Set optimization` button and choose the `Trained file format`.

Specify the folder from the `Select train folder` button and press the `Train button`.

Expand All @@ -123,6 +142,8 @@ Inference results are listed in Result images.

Change the Threshold and press the `Test button` again

If you want to benchmark the inference, set `Benchmark mode`

## Reference

[PaDiM-Anomaly-Detection-Localization-master](https://github.com/xiahaifeng1995/PaDiM-Anomaly-Detection-Localization-master)
Expand Down
Loading