LilitYolyan / CutPaste

Unofficial implementation of Google "CutPaste: Self-Supervised Learning for Anomaly Detection and Localization" in PyTorch
MIT License
114 stars 25 forks source link

Issue with the code CutPaste Anomaly detection #21

Open Chichiviriche opened 2 years ago

Chichiviriche commented 2 years ago

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,

xaioffff commented 2 years ago

I have the same problem. At first, I thought the system was incompatible. Could we discuss ? 2398632840@qq.com Screenshot from 2022-04-07 09-23-52

LilitYolyan commented 2 years ago

I can't reproduce the error, I don't get the error during the training. If you can give me more info, I'll check @xaioffff @Chichiviriche

LilitYolyan commented 2 years ago

@xaioffff @Chichiviriche Also check if the dataset structure is exact the same as here: https://github.com/LilitYolyan/CutPaste/issues/20#issuecomment-1087144630 Check if your bottle/train folder has this structure:

bottle └─── train | | └─── good

mouxinyue1 commented 2 years ago

I have the same problem. At first, I thought the system was incompatible. Could we discuss ? 2398632840@qq.com Screenshot from 2022-04-07 09-23-52

Hello, I have encountered the same problem, may I ask if you have solved it

Chichiviriche commented 2 years ago

yes, my dataset structure is Ok otherwise I get another type of error. Could you guide us ? the code is quite complex, what king of info would help to find the cause of the error ? Kind regards,

Chichiviriche commented 2 years ago

I made some progress: when i did git clone https://github.com/LilitYolyan/CutPaste.git, the train.py has not the def get_args(): part in the code. After adding those lines, I have now only a single error, which is; File "/home/laurent/.local/bin/.virtualenvs/pytorch/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 102, in init raise ValueError("num_samples should be a positive integer " ValueError: num_samples should be a positive integer value, but got num_samples=0 Any idea ? Thanks

Chichiviriche commented 2 years ago

also, you have to be sure that you specify the full path to your dataset. python train.py --dataset_path /bottle/train --num_class 3 --> leads to an error even if you are in the directory where bootle is python train.py --dataset_path /home/laurent/CutPaste/bottle/train --num_class 3 is starting correctly Regards,

sarmientoj24 commented 2 years ago

@LilitYolyan

    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.

sarmientoj24 commented 2 years ago

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?