Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
ac3c501
Add Pytorch installation instructions for potential issues in Windows
lihyin Sep 14, 2020
6104c35
Add the Readme tips to resolve GPU Out of Memory issue and more speci…
lihyin Sep 14, 2020
16d69d6
train without test: save model and weight
jinzishuai Sep 14, 2020
9ab1a3e
Add timing
jinzishuai Sep 14, 2020
2ada233
runTest.py not working
jinzishuai Sep 14, 2020
a505a2f
runTest.py working
jinzishuai Sep 14, 2020
7c8b3f4
to use the model: no need to load the weights
jinzishuai Sep 15, 2020
0201156
load the model file directly
jinzishuai Sep 15, 2020
ac0e602
run test without loading training data
jinzishuai Sep 15, 2020
f4d31e1
Problem with Linux
jinzishuai Sep 15, 2020
4cbcef3
Enable LFS: add model_zerobox_test
jinzishuai Sep 16, 2020
710f323
stop using git-lfs
jinzishuai Sep 20, 2020
4116214
we don't need score_obs at testing: without good images (still need f…
jinzishuai Sep 20, 2020
394ba7e
cleanup lfs
jinzishuai Sep 20, 2020
c484fac
consistent results with zerobox test_differnet.py
jinzishuai Sep 21, 2020
70103d5
Merge pull request #3 from zerobox-ai/jinshi/PoC
lihyin Oct 2, 2020
5f88cd5
Separate validation and test datasets; Add test.py for test only
lihyin Oct 5, 2020
8fccb26
Fix how to get target_threshold; Add target_tpr in config.py;
lihyin Oct 5, 2020
27c831d
added new function differences_as_input. instead of using the input i…
kuangzijian Oct 25, 2020
03b70c3
updated differences function
kuangzijian Oct 25, 2020
2b03c72
Added function to randomly shrink image size of width and lenth
txrxrxr Oct 25, 2020
ffdd7e4
Added new random shrink
txrxrxr Nov 2, 2020
672c7c5
Added new annotation and data extratction method.
kuangzijian Nov 9, 2020
57a4fa9
Added function to randomly shrink image size of width and length
txrxrxr Nov 9, 2020
3c89256
Updated the data extraction method
kuangzijian Nov 9, 2020
96ea14b
Updated the utils not using the differences as input
kuangzijian Nov 9, 2020
6b9c57e
Updated the data_extraction.py structure
kuangzijian Nov 9, 2020
39fe3a1
Updated the data_extraction structure
kuangzijian Nov 9, 2020
c656115
Revert back the Utils, and remove the part that apply the concept of …
kuangzijian Nov 10, 2020
a43d71f
Revert back the Utils, and remove the part that apply the concept of …
kuangzijian Nov 10, 2020
9b02a03
save original frame image
kuangzijian Nov 17, 2020
1c68c6b
Update Readme.md
kuangzijian Nov 18, 2020
c84d9ba
Update Readme.md
kuangzijian Nov 18, 2020
5460ea6
included examples
kuangzijian Nov 18, 2020
5a88a58
Merge remote-tracking branch 'origin/zijian' into zijian
kuangzijian Nov 18, 2020
6df1af4
Update Readme.md
kuangzijian Nov 18, 2020
537e461
Added new shrink function. Shrink top by 20% and rest by 5%.
txrxrxr Nov 24, 2020
2f65829
Fixed bugs in shrink function.
txrxrxr Nov 25, 2020
d2e3475
Generate and save ROC curve image
Jason0917 Nov 26, 2020
13a0afc
save files with parameters in file name; add rotation degree config; …
lihyin Nov 28, 2020
2730450
merge RandcomCrop, AUROC curve plot, flow model, logo_detection
lihyin Nov 28, 2020
02ba81f
Merge remote-tracking branch 'origin/xinran' into zijian
lihyin Nov 28, 2020
00b6b9c
put the shrink percentage into config.py; set crop_bottom = 0.2
lihyin Nov 28, 2020
aef987c
define roc curve plot as a function and save it into model folder
lihyin Nov 28, 2020
8fce55a
Fixed bugs in shrink function.
txrxrxr Nov 30, 2020
c9bd62f
updated utils to include save_transformed_image in the config.py
kuangzijian Dec 5, 2020
f945989
Merge remote-tracking branch 'origin/zijian' into zijian
kuangzijian Dec 5, 2020
f5b056b
draw ground truth bounding box on saved original frames
kuangzijian Dec 5, 2020
0eb3a40
Included prediction visualization part
kuangzijian Dec 6, 2020
26fe50f
Updated config.py
kuangzijian Dec 6, 2020
8d7b731
Updated visualization part
kuangzijian Dec 6, 2020
9541774
Added new model MaskDifferNet.
txrxrxr Dec 10, 2020
3a2ec55
Merge branch 'zijian' of https://github.com/zerobox-ai/differnet into…
txrxrxr Dec 10, 2020
57265d9
Merge branch 'zijian' of https://github.com/zerobox-ai/differnet into…
kuangzijian Dec 10, 2020
bc9177f
Added visual for MaskDifferNet.
txrxrxr Dec 10, 2020
beb4b1b
Added optimizer parameters for VAE
kuangzijian Dec 10, 2020
2161fef
Merge remote-tracking branch 'origin/zijian' into zijian
kuangzijian Dec 10, 2020
fdcf954
code clean up
kuangzijian Dec 29, 2020
d04da3b
modified prediction class, to check if frame_name_is_given on each im…
kuangzijian Jan 29, 2021
ce354e1
Modify predict.py code for differnet to have better result visualization
kuangzijian Jan 29, 2021
8d58892
updated model naming format
kuangzijian Jan 31, 2021
ba3856d
Changed export gradient map to generate the map for both good and def…
txrxrxr Feb 14, 2021
3e1351c
merge test and predict into one file
kuangzijian Feb 15, 2021
76f9536
added mask calculation functions and apply calculated mask to input i…
kuangzijian Feb 15, 2021
2bff3dd
fixed typo
kuangzijian Feb 15, 2021
9aae1db
code clean up
kuangzijian Feb 15, 2021
745b0a4
output json file name fix; model.pth load file name fix
kuangzijian Feb 21, 2021
983ae9f
moved test code out of the train.py (into the new test.py); renamed m…
kuangzijian Feb 21, 2021
e381c68
Add todo list.
kuangzijian Feb 22, 2021
aa7ad9d
Added ROC curve in Test.
kuangzijian Feb 28, 2021
d52dfb9
Shrink Mask
kuangzijian Mar 21, 2021
31a4dbc
Merge pull request #6 from zerobox-ai/zijian
jinzishuai Apr 5, 2021
edbf1af
add .gitignore
ziyunxiao Apr 5, 2021
782a6a2
adjust files
ziyunxiao Apr 5, 2021
21bffe4
adjust files
ziyunxiao Apr 5, 2021
12fb038
cleanup files
ziyunxiao Apr 5, 2021
2d80fb1
adjust files
ziyunxiao Apr 5, 2021
e8ebb49
update readme
ziyunxiao Apr 5, 2021
0607bde
update training.py
ziyunxiao Apr 5, 2021
fe58e97
update readme
ziyunxiao Apr 5, 2021
d771ba0
update training.py
ziyunxiao Apr 5, 2021
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
Empty file added .gitattributes
Empty file.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.venv/
.vscode/
__pycache__/
dataset/
gradient_maps/
models/
transform/
weights/
logs/
work/
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# DifferNet
This project is used for experiment to train and test models on various datasets. The core function has been packaged as "[differnet-zerobox](https://github.com/zerobox-ai/pydiffernet)". Pleaser refer to the [readme](https://github.com/zerobox-ai/pydiffernet/blob/master/README.md) for how to use the package.

If you need more information about DifferNet, please reference to the official repository.

**Differnet Officical repository**
The [official repository](https://github.com/marco-rudolph/differnet) to the WACV 2021 paper "[Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows](
https://arxiv.org/abs/2008.12577)" by Marco Rudolph, Bastian Wandt and Bodo Rosenhahn.

## Getting Started

The project has been upgraded to python 3.9. Please setup python 3.9 virtual environment then do the following.

### Install torch and torch vision
In order to have proper torch and torch vision to use either GPU or CPU please follow [pytorch.org](https://pytorch.org/get-started/locally/) to install torch and torch vision

## Install rest packages with:

```
$ pip install -r requirements.txt
```

## Configure and Run

All configuration has default values from package differnet(from package differnet-zerobox).
The project can have dict based configuration to overwrite any default value.


Common settings
```
#conf/settings.conf
"differnet_work_dir": "./work", #work folder
"device": "cuda", # cuda or cpu
"device_id": 0, # the device you want to use. depends on how many GPU or CPU you have.
"verbose": True, # Set to true, when you do experiments.
"meta_epochs": 10, # traing loop
"sub_epochs": 8, # sub-loop of traing
"test_anormaly_target": 10, # threshold when run testing model to identify if a given image is good or bad

```

Traing

```
python training.py
```

Run test cases
```
python -m pytest -s
```

## Prepare new dataset
The data structure under work folder looks like this. The model folder will save trained model.
For experiment purpose, you would like to give test and validate folder with proper labled data. While, for zerobox
it only requires train folder and data. The minimum images is 16 based on the differnet paper.

```
pink1/
├── model
├── test
│   ├── defect
│   └── good
├─── validate
│ ├── defect
│ └── good
└── train
└── good
├── 01.jpg
├── 02.jpg
├── 03.jpg
├── 04.jpg
├── 05.jpg
├── 06.jpg
├── 07.jpg
├── 08.jpg
├── 09.jpg
├── 10.jpg
├── 11.jpg
├── 12.jpg
├── 13.jpg
├── 14.jpg
├── 15.jpg
└── 16.jpg
```

92 changes: 0 additions & 92 deletions Readme.md

This file was deleted.

Empty file added conf/__init__.py
Empty file.
88 changes: 88 additions & 0 deletions conf/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
DIFFERNET_CONF = {
# common settings
"differnet_work_dir": "./work",
"device": "cuda", # cuda or cpu
"device_id": 5,
"verbose": True,
"meta_epochs": 5,
"sub_epochs": 8,
"test_anormaly_target": 10,
# other settings
# "img_size": [448, 448],
# "img_dims": [3, 448, 448],
# "add_img_noise": 0.01,
# # transformation settings
# "transf_rotations": False,
# "transf_brightness": 0.5,
# "transf_contrast": 0.5,
# "transf_saturation": 0.5,
# "norm_mean": [0.485, 0.456, 0.406],
# "norm_std": [0.229, 0.224, 0.225],
# "rotation_degree": 0,
# "crop_top": 0.10,
# "crop_left": 0.10,
# "crop_bottom": 0.10,
# "crop_right": 0.10,
# network hyperparameters
# number of scales at which features are extracted, img_size is the highest - others are //2, //4,...
# "n_scales": 3,
# "clamp_alpha": 3, # see paper equation 2 for explanation
# "n_coupling_blocks": 8,
# # fc_internal : 2048 # number of neurons in hidden layers of s-t-networks
# "fc_internal": 1536, # number of neurons in hidden layers of s-t-networks
# "dropout": 0.0, # dropout in s-t-networks
# "lr_init": 2e-4,
# "n_feat": 256 * 3, # do not change except you change the feature extractor
# # dataloader parameters
# "n_transforms": 4, # number of transformations per sample in training
# "n_transforms_test": 1, # number of transformations per sample in testing
# # actual batch size is this value multiplied by n_transforms(_test)
# "batch_size": 4,
# "batch_size_test": 1,
# total epochs : meta_epochs * sub_epochs
# evaluation after <sub_epochs> epochs
# output settings
# "grad_map_viz": True,
# "hide_tqdm_bar": True,
# "save_model": True,
# "save_transformed_image": True,
# "visualization": False,
# "frame_name_is_given": False,
# "target_tpr": 0.85,
}


LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"handlers": {
"console": {
# "level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
# "file": {
# # 'level': 'DEBUG',
# "class": "logging.handlers.RotatingFileHandler",
# "filename": "logs/app.log",
# "formatter": "verbose",
# "maxBytes": 1024 * 1024 * 1, # 10MB
# "backupCount": 5,
# "formatter": "verbose",
# },
},
"loggers": {
"differnet": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
},
"root": {"level": "INFO", "handlers": ["console"]},
}
49 changes: 0 additions & 49 deletions config.py

This file was deleted.

4 changes: 0 additions & 4 deletions dummy_dataset/dummy_class/test/anomaly/.directory

This file was deleted.

Binary file removed dummy_dataset/dummy_class/test/anomaly/1.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/2.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/3png.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/4.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/5.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/6.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/7.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/anomaly/8png.png
Binary file not shown.
4 changes: 0 additions & 4 deletions dummy_dataset/dummy_class/test/good/.directory

This file was deleted.

Binary file removed dummy_dataset/dummy_class/test/good/1.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/2.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/3.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/4.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/5.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/6.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/7.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/test/good/8.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/train/good/1.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/train/good/2.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/train/good/3.png
Binary file not shown.
Binary file removed dummy_dataset/dummy_class/train/good/4.png
Binary file not shown.
Loading