lilityolyan / cutpaste Goto Github PK
View Code? Open in Web Editor NEWUnofficial implementation of Google "CutPaste: Self-Supervised Learning for Anomaly Detection and Localization" in PyTorch
License: MIT License
Unofficial implementation of Google "CutPaste: Self-Supervised Learning for Anomaly Detection and Localization" in PyTorch
License: MIT License
hi, great work.
There seems to be a bug in
image_patches = unfold(image).squeeze(0).reshape(-1, 3, *self.kernel_dim )
it's not unfolding correctly.
This worked for me
image_patches = unfold(image).squeeze(0).permute(1,0).reshape(-1, 3, *self.kernel_dim )
btw, KDE is used for anomaly detection in the code, but in my experiments it's not necessary and slow. A simple Gaussian estimation using sklearn's mixture of gaussian estimator is fast and working fine. Just a suggestion.
hello! Thank you for your code contribution!I follow the setup instruction to run train.py , But I encountered the following problems:
$ python train.py --dataset_path cutpaste/mvtec/bottle/train --num_class 3
Missing logger folder: tb_logs/exp1
Traceback (most recent call last):
File "train.py", line 103, in model = CutPaste(hparams = args)
File "train.py", line 19, in init self.model = CutPasteNet(encoder = hparams.encoder, pretrained = hparams.pretrained, dims = hparams.dims, num_class = hparams.num_class)
File "/home/lwz/CutPaste-Li/model.py", line 49, in init super().init(encoder, pretrained, dims, num_class) File "/home/lwz/CutPaste-Li/model.py", line 23, in init self.out = nn.Linear(dims[-1], num_class)
File "/home/lwz/.conda/envs/cutpasteli/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 85, in init self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
(tuple of ints size, *, tuple of names names, torch.memory_format memory_format, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
(tuple of ints size, *, torch.memory_format memory_format, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
I am really confused about that, could you please give me some advice? Is this a problem with the installation package version?
Have you solved the problem yet? Can you give me some advice?
Thanks for your code!It's very nice. I want to know how to use localization.py. I run it but it cannot produce the heatmap.
Thanks again!!
Hello, can you help:
heatmap_on_image() in the final line of code of localization.py has 3 arguments, but while defining it, there were only 2 arguments.
Also visualize_heatmap() is not defined
Thanks
hello!
Thank you for your code contribution!I follow the setup instruction to run train.py , But I encountered the following problems:
$ python train.py --dataset_path CutPaste-Li/mvtec/bottle --num_class 3
Missing logger folder: tb_logs/exp1
Traceback (most recent call last):
File "train.py", line 103, in
model = CutPaste(hparams = args)
File "train.py", line 19, in init
self.model = CutPasteNet(encoder = hparams.encoder, pretrained = hparams.pretrained, dims = hparams.dims, num_class = hparams.num_class)
File "/home/lwz/CutPaste-Li/model.py", line 49, in init
super().init(encoder, pretrained, dims, num_class)
File "/home/lwz/CutPaste-Li/model.py", line 23, in init
self.out = nn.Linear(dims[-1], num_class)
File "/home/lwz/.conda/envs/cutpasteli/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 85, in init
self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
I am really confused about that, could you please give me some advice?
Is this a problem with the installation package version?
Hi~
The GDE model should be built with pure embeddings of normal samples.
However, in anomaly_detection.py, you build GDE model with embeddings of training samples. Some of these training samples have been transformed by CutPaste, which should be considered as anomalies.
So I wonder whether there are some problems.
Thank you very much for your contribution to the code, the code is very well written, I have a few questions and confusion? I hope you can find time to reply,I got the original heat map。
After the heat map and the original map are superimposed with a certain weight, is
I'm confused why? Which layer is the network of feature extraction, is the result of that layer
Hello,
First of all, thank you for your neat work!
I managed to run your code on the bottle class of the Mvtec dataset by running the command:
python train.py --dataset_path /home/username1/data/datasets/mvtec/bottle/train --num_class 3
However when I tried to run the anomaly_detection.py, using the following command:
python anomaly_detection.py --checkpoint ./tb_logs/exp1/version_3/checkpoints --data /data/username1/datasets/mvtec/bottle/test
I did not obtain any results, the problem is that the all_checkpoint
list in the main part of the anomaly_detection.py
contains only the checkpoint I specified in the command above, which makes me wonder whether I am doing something wrong when specifying the command above and also I wonder whether you have a different dataset organization on your side. Because for now, I am having the following organization (the original):
mvtec
│ readme.
│ license.txt
│
└─── bottle
│ │ readme.txt
│ │ lisence.txt
│ │
│ └─── ground_truth
│ | └─── broken_large
│ | └─── broken_small
│ | └─── contamination
│ |
| └─── train
| | └─── good
| | | 000.png
| | | ...
│ |
| └─── test
| | └─── broken_large
| | | | 000.png
| | | | ...
| | └─── broken_small
| | | | 000.png
| | | | ...
| | └─── contamination
| | | | 000.png
| | | | ...
| | └─── good
| | | | 000.png
| | | | ...
└─── cable
| ...
└─── zipper
Can you please tell me whether you used a different organization?
Because when I look at mvtec_anomaly_detection
function I see that you build a path using the defect name + "train" and you do the same for "test".
Thank you for your help.
Hi,
In train.py, there is a localization option shown like,
parser.add_argument('--localization', default='False', choices=('True', 'False'), help='If True train on (64,64) cropped patches')
However, if 'False'
actually means True because 'False'
is seen as string.
So, the localization option is always True.
Normally, the Cutpaste(3-way) result should be higher than the Cutpaste result.
Hey,
Thank you for the implementation!
Do you know why is there such a large gap between the results from the paper and the ones you get in this repo?
Also, is the localization code working?
Thanks,
Eliahu
Getting problems on this.
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (12x2048 and 512x512)
I am getting this error with the ff command
python train.py --dataset_path ../data/train --encoder resnet50 --pretrained --num_gpus 1
My ../data/train
is just composed of jpg images.
I would just want to do self-supervised pretraining without annotations/labels.
Seems like it has soemthing to do with this dims
def __init__(self, encoder='resnet18', pretrained=True, dims=[512, 512, 512, 512, 512, 512, 512, 512, 128], num_class=3):
What would be the dims for resnet50?
Hello,
first off all, thanks for that very interesting work.
I've tried to reproduce these experiments. I'm under Ubuntu 20.04, python 3.8. I've installed all the requirements successfully.
I've downloaded the bottle and wood dataset, Ok
But none of the training is working :
python train.py --dataset_path /CutPaste/bottle/train --num_class 3 gives me the error :
File "/home/laurent/.local/bin/.virtualenvs/pytorch/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 85, in init
self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
python train.py --dataset_path /CutPaste/bottle/train --encoder efficientnet_b4 gives me the error :
File "/home/laurent/.local/bin/.virtualenvs/pytorch/lib/python3.8/site-packages/torch/nn/functional.py", line 1848, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (12x1792 and 512x512)
Can you help ? Is you code fully running ? Is there something I forgot in the configuration ? The bottle images are 900x900, the wood images are 1024x1024
Kind Regards,
Hello, First of all, thank you for your neat work! I managed to run your code on the bottle class of the Mvtec dataset by running the command:
python train.py --dataset_path /home/username1/data/datasets/mvtec/bottle/train --num_class 3
However when I tried to run the anomaly_detection.py, using the following command:
python anomaly_detection.py --checkpoint ./tb_logs/exp1/version_3/checkpoints --data /data/username1/datasets/mvtec/bottle/test
I did not obtain any results, the problem is that the
all_checkpoint
list in the main part of theanomaly_detection.py
contains only the checkpoint I specified in the command above, which makes me wonder whether I am doing something wrong when specifying the command above and also I wonder whether you have a different dataset organization on your side. Because for now, I am having the following organization (the original):mvtec │ readme. │ license.txt │ └─── bottle │ │ readme.txt │ │ lisence.txt │ │ │ └─── ground_truth │ | └─── broken_large │ | └─── broken_small │ | └─── contamination │ | | └─── train | | └─── good | | | 000.png | | | ... │ | | └─── test | | └─── broken_large | | | | 000.png | | | | ... | | └─── broken_small | | | | 000.png | | | | ... | | └─── contamination | | | | 000.png | | | | ... | | └─── good | | | | 000.png | | | | ... └─── cable | ... └─── zipper
Can you please tell me whether you used a different organization? Because when I look at
mvtec_anomaly_detection
function I see that you build a path using the defect name + "train" and you do the same for "test". Thank you for your help.
Hello, How did you solve this problem?
did you change the folders?
Originally posted by @farzadips in #14 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.