Julian-Wyatt / AnoDDPM

CVPR Workshop paper - AnoDDPM: Anomaly Detection with Denoising Diffusion Probabilistic Models using Simplex Noise
https://julianwyatt.co.uk/anoddpm
MIT License
174 stars 28 forks source link

Please Asking about size mismatch!! #6

Closed abegon-ta closed 1 year ago

abegon-ta commented 2 years ago

Hi I tried to run the introduced model using MVtec dataset according to READ.ME, but I got the following error in detection.py. I don't know how to solve this problem. Please help me to solve this problem.

The test_arg I used is as follows

{ "img_size": [ 256, 256 ], "Batch_Size": 1, "EPOCHS": 3000, "T": 1000, "base_channels": 128, "beta_schedule": "linear", "channel_mults": "", "loss-type": "l2", "loss_weight": "none", "train_start": true, "lr": 1e-4, "random_slice": true, "sample_distance": 600, "weight_decay": 0.0, "save_imgs": false, "save_vids": true, "dropout": 0, "attention_resolutions": "16,8", "num_heads": 2, "num_head_channels": -1, "noise_fn": "gauss", "dataset": "leather", "channels": 3 }

The error statement is as follows. RuntimeError: Error(s) in loading state_dict for UNetModel: size mismatch for down.0.0.weight: copying a param with shape torch.Size([128, 3, 3, 3]) from checkpoint, the shape in current model is torch. size mismatch for out.2.weight: copying a param with shape torch.Size([3, 128, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([1, 128, 3, 3]). size mismatch for out.2.bias: copying a param with shape torch.Size([3]) from checkpoint, the shape in current model is torch.Size([1]).

Waiting for a solution.

Julian-Wyatt commented 2 years ago

Hi - I will have a quick look, but note my paper does not cover anomaly detection across RGB images which can be analysed further in future work.

Julian-Wyatt commented 2 years ago

Did the model train ok? How were the output images / videos?

The error you have sent is caused in the model loading process not in the detection process - which I would struggle to test myself as I don't have a dedicated GPU (and I no longer have access to the university server which trained my models)

Julian-Wyatt commented 2 years ago

I can't seem to replicate the problem on my end - I've been able to load in a checkpoint with those arguments - it would be great if you could provide more information

abegon-ta commented 2 years ago

I am running the run with RGB set to True, do you think that could be affecting it? Thanks for the solution! Perhaps TRAIN is working well. The reason for this is that, as you can see in the image below, a movie is created that generates an image of the original leather dataset from the noise.

image

I am running the run with RGB set to True, do you think that could be affecting it?

zideliu commented 2 years ago

I am running the run with RGB set to True, do you think that could be affecting it? Thanks for the solution! Perhaps TRAIN is working well. The reason for this is that, as you can see in the image below, a movie is created that generates an image of the original leather dataset from the noise. image

I am running the run with RGB set to True, do you think that could be affecting it?

How long to train an Epoch? I'm stuck at the first epoch for many hours And if possible, could you share your python environment?

zideliu commented 2 years ago

Hi I tried to run the introduced model using MVtec dataset according to READ.ME, but I got the following error in detection.py. I don't know how to solve this problem. Please help me to solve this problem.

The test_arg I used is as follows

{ "img_size": [ 256, 256 ], "Batch_Size": 1, "EPOCHS": 3000, "T": 1000, "base_channels": 128, "beta_schedule": "linear", "channel_mults": "", "loss-type": "l2", "loss_weight": "none", "train_start": true, "lr": 1e-4, "random_slice": true, "sample_distance": 600, "weight_decay": 0.0, "save_imgs": false, "save_vids": true, "dropout": 0, "attention_resolutions": "16,8", "num_heads": 2, "num_head_channels": -1, "noise_fn": "gauss", "dataset": "leather", "channels": 3 }

The error statement is as follows. RuntimeError: Error(s) in loading state_dict for UNetModel: size mismatch for down.0.0.weight: copying a param with shape torch.Size([128, 3, 3, 3]) from checkpoint, the shape in current model is torch. size mismatch for out.2.weight: copying a param with shape torch.Size([3, 128, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([1, 128, 3, 3]). size mismatch for out.2.bias: copying a param with shape torch.Size([3]) from checkpoint, the shape in current model is torch.Size([1]).

Waiting for a solution.

Do you know how to use detection.py? I want to get the result image of detection through this file, but I don't know how to get this image I would really appreciate it if I could get a reply

Julian-Wyatt commented 2 years ago

Hi,

Apologies for not replying sooner, I've been incredibly busy and I'm the sole contributor to this repo.

I am running the run with RGB set to True, do you think that could be affecting it? Thanks for the solution! Perhaps TRAIN is working well. The reason for this is that, as you can see in the image below, a movie is created that generates an image of the original leather dataset from the noise. image

I am running the run with RGB set to True, do you think that could be affecting it?

It will be affecting it, I wrote bits of code to test this when I was at the late end of writing the paper and likely have not properly reverted it. Running the code with RGB channels will require a bit more work to revert this back to fully working; I don't quite have enough time now to sort this (plus I don't have the same hardware anymore).

How long to train an Epoch? I'm stuck at the first epoch for many hours And if possible, could you share your python environment?

A GPU is basically required for a model of this size, a single iteration (not epoch) on my MacBook Pro (running with cpu) does not even finish in an hour. From memory, the paper was generated on an NVIDIA RTX 2080 series (I believe it's noted in the paper). I believe I provided a requirements.txt to another issue if you wish to view that.

Do you know how to use detection.py? I want to get the result image of detection through this file, but I don't know how to get this image I would really appreciate it if I could get a reply

If all you would like is result images; generate_images.py is far easier to understand and does exactly that. detection.py was primarily used for metric gathering and consequently looping across the whole dataset and concatenating results to form AUC, dice and iou graphs.

Does this help?

Julian-Wyatt commented 1 year ago

Closing due to no responses