runinho / pytorch-cutpaste Goto Github PK
View Code? Open in Web Editor NEWunoffical and work in progress PyTorch implementation of CutPaste
Home Page: https://runinho.github.io/pytorch-cutpaste/
unoffical and work in progress PyTorch implementation of CutPaste
Home Page: https://runinho.github.io/pytorch-cutpaste/
Thank you for your great effort of the codes. During the evaluation phase, there are only roc_plot and TSNE results in the eval folder. How can I get the patch heatmap of defect images.
RuntimeError: Error(s) in loading state_dict for ProjectionNet:
I change the order ( model.load_state_dict(weights)) to ( model.load_state_dict(weights,False),meaningless
Is there any code available for visualizing test images?
If so, I'd appreciate it.
what does the argument --no-pretrained mean, please?
does it train a model from scratch, or is it a kind of transfer learning?
can I use --no-pretrained arg, training with CPU, instead of GPU?
Hi, I'm tring to evaluate model by eval.py and confusing why the test_tranform missing 'ColorJitter' step?
test_transform = transforms.Compose([])
# why missing this part in test phase.
# test_transform.transforms.append(transforms.ColorJitter(brightness=0.1, contrast=0.1, saturation=0.1, hue=0.1))
test_transform.transforms.append(transforms.Resize((size, size)))
test_transform.transforms.append(transforms.ToTensor())
test_transform.transforms.append(transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]))
In training phase:
after_cutpaste_transform = transforms.Compose([])
after_cutpaste_transform.transforms.append(transforms.ToTensor())
after_cutpaste_transform.transforms.append(transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]))
train_transform = transforms.Compose([])
train_transform.transforms.append(transforms.ColorJitter(brightness=0.1, contrast=0.1, saturation=0.1, hue=0.1))
train_transform.transforms.append(transforms.Resize((size, size)))
train_transform.transforms.append(cutpate_type(transform = after_cutpaste_transform))
Thanks for your contribution. I found some interesting results.
Experiment setting: resnet18(pretrained), from scratch no finetune.
I fixed the seed during training, when i train only one class such as 'cable' and train all types(include 'cable'), the evaluated AUC of cable is not the same(floating between 3% and 7%),so i think the random operation in Cutpaste cause. But when i trained only one class still 'cabel ' twice, the floating of evaluated AUC is very very small.
According to the paper in section 4.2, it said
We further evaluate the pixel-wise localization AUC, achieving 88.3.
and
We report a localization AUC in Table 2. Our patch-based model achieves 96.0 AUC.
Also in section 2.4,
In Section 4.2, we visualize a heatmap using patch-level detector for defect localization, along with that of an image-level detector using visual explanation techniques such as GradCAM.
And the training objectives defined in formulas (1) and (3) are different.
Does CutPaste need to train two models for defect detection and localization?
It seems that they trained an image-level detector (3-way), the detection result achieves 95.2 while localization result only achieves 88.3.
And they need to train another model using patches as input to get localization result of 96.0.
Please correct me if I was wrong.
In eval: numpy.linalg.LinAlgError: unrecoverable internal error
I train a model of wood using the command:
python run_training.py --head_layer 2 --type wood
Then in the evaluate process, is use the model to evaluate the type of bottle , I got a surprisingly excellent result:
AUC: 0.9949454642192073
Is there any problem here?
I just used the following hard code to evaluate (in eval.py line 258):
roc_auc = eval_model(model_name, 'bottle', save_plots=args.save_plots, device=device, head_layer=args.head_layer, density=density())
Thanks!
Hey!
Got this warning:
UserWarning: This DataLoader will create 8 worker processes in total
I need to reduce the number of workers from 8, to 4.
How do i change this variable in run_training.py?
Thanks!
您好!
我想问一下,每次训练得到的模型,得到的结果,差别都很大。(是不是因为 每次都是随机在一张图里cut,paste,导致的?),
比如 bottle这个类,我用相同的参数分别训练两次,得到两个模型model1和model2。
测试的时候,model1 得到的结果是AUC1 = 99.444, model2得到的结果是AUC2 = 99.841.
虽然有误差,但是这相差的也太多了。。。。。
有什么办法可以改善吗?
谢谢
Hopefully, the author can provide some tips.
Thanks for your effort on this paper recurrence^_^and the code runs functionally.
I was wondering if you have any plan for the rest of the section in this paper(localization section)~
sincerely,
F
Dear Runinho,
I found that you use " h = img.size[0] w = img.size[1]" in the cutpaste.py. I think it should be " w = img.size[0]
h = img.size[1]" here. the reason the bug haven't been triggered is that the images used in this dataet have same width and height.
Amending the bug is appreciated.
Thanks and Best Regards.
I coud train and evaluate the generated model for the MVTec hazelnut class dataset in my
PC, by erasing the rest of the classes in all_types = , and just let : all_types = ['hazelnut']
inside run_training.py, and eval.py.
Being my path to hazelnut this:
C:\Users\libro\pytorch-cutpaste\Data\hazelnut.
Then i was trying to execute run_training.py from googles colab, to speed up
the training cause i have no GPU, but run_training.py, can not find the images.
Already tried two aproches to upload the Data folder to colab:
1_Uploaded that folder as is in my PC, to my goggle drive C: path.
2_ forked your repository, and added the Data/hazelnut etc folders to my version of your repository .
I can see my pictures at colab in: /content/pytorch-cutpaste/Data/hazelnut/train/good
when i clone my repo version.
And at: /content/drive/MyDrive/Data/hazelnut/train/good when I clone your repo original version .
In both cases i got this errror:
!python run_training.py --model_dir models --head_layer 2
Namespace(type='all', epochs=256, model_dir='models', pretrained=True, test_epochs=10, freeze_resnet=20, lr=0.03, optim='sgd', batch_size=64, head_layer=2, variant='3way', cuda=False, workers=8)
using device: cpu
training hazelnut
loading images
loaded 0 images
I was lucky reading and saveing one picture from hazelnut....good folder in colab
by adding this to dataset.py to be sure that i was able to access to the good folder
that is needed during training.
###################################################################
import cv2
root_dir = "/content/drive/MyDrive/Data"
img = cv2.imread(root_dir + "/hazelnut/train/good/aume0.PNG")
cv2.imwrite(root_dir + "/hazelnut/train/good/saveit!.PNG", img)
root_dir1 = "/content/pytorch-cutpaste/Data"
img1 = cv2.imread(root_dir + "/hazelnut/train/good/aume1.PNG")
cv2.imwrite(root_dir1 + "/hazelnut/train/good/saveit1!.PNG", img1)
####################################################################
How can I to make dataset.py, to retrieve my pictures from colab, being MyDrive, the
favorite option?
Hi,
I am confusing about how to determine if an image is anomalous or not because model has two output: classification prediction and GDE scores.
Should I use a threshold for GDE scores to check and ignore model prediction ?
Thank you for your work and your reply :)
The label during training is consistant, namely 000...111...
I'm wondering whether the consistant label will achieve trivial solution of CNN.
No matter what the inputs are, the CNN outputs 000...111...
hi, I test the pretrained ResNet18 model(https://download.pytorch.org/models/resnet18-f37072fd.pth) with your code of eval_model(). Surprisingly, I get the results as shown below. The average auc 0.908 is almost the same as Li et al. CutPaste 0.909.
Therefore, I'm quite confused about the effectness of CutPaste. Did you notice this? How to explain it? Thanks~
only image level (i.e., classification results, good and bad), no pixel level (i.e., detection, defect location)
Do you have any good suggestions?
When run run_training.py,the epoch is 10000.Is it necessary?10000 is too large,and the MVTec is small.I worry about overfit.Can i set epoch smaller?for example,set epoch 4000?
Thanks!
Traceback (most recent call last):
File "run_training.py", line 263, in
workers=args.workers)
File "run_training.py", line 104, in run_training
batch_idx, data = next(dataloader_inf)
File "run_training.py", line 93, in get_data_inf
for out in enumerate(dataloader):
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in next
data = self._next_data()
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
return self._process_data(data)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
data.reraise()
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise
raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/work/Anomaly_det/pytorch-cutpaste-master/dataset.py", line 43, in getitem
img = self.transform(img)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 67, in call
img = t(img)
File "/home/work/Anomaly_det/pytorch-cutpaste-master/cutpaste.py", line 143, in call
org, cutpaste_normal = self.normal(img)
File "/home/work/Anomaly_det/pytorch-cutpaste-master/cutpaste.py", line 68, in call
patch = self.colorJitter(patch)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 1115, in forward
img = F.adjust_hue(img, hue_factor)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 712, in adjust_hue
return F_pil.adjust_hue(img, hue_factor)
File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/functional_pil.py", line 197, in adjust_hue
np_h = np.array(h, dtype=np.uint8)
TypeError: array() takes 1 positional argument but 2 were given
Is this your preliminary version? I tried to run code on the MVTec-AD, and there are so many bugs, do you have a specific pytorch version? There are unexpected parameters in dataloader. Although, these are small bugs, I have solved these and run it successfully. Hope you to accomplish it!
Thank you!
Thanks for creating this project!
Would you please add a license file so your users would know how you allow to use it?
Maybe you could consider using the BSD-style license pytorch license or using one of the other good alternatives
Hi, thank you for your codes.
It seems that you uncommented the code which used KernelDensity from Sklearn but used mahalanobis_distance to predict the anomaly score (or distance ?). Why did not you use KernelDensity?
Thank you very much.
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.