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

some quesion about detection #16

Closed hk011 closed 11 months ago

hk011 commented 1 year ago

Hello author, I am honored to read your paper. After completing leather data set training, I tried to detect, but encountered some problems: Here is my args file:

args19.json { "img_size": [256,256], "Batch_Size": 1, "EPOCHS": 1000, "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":true, "save_vids":true, "dropout":0, "attention_resolutions":"16,8", "num_heads":2, "num_head_channels":-1, "noise_fn":"simplex", "dataset":"leather", "channels": 1 }

After the training:

  1. Error is reported in evaluation.testing() immediately after train:

File "diffusion_training.py", line 153, in train evaluation.testing(testing_dataset_loader, diffusion, ema=ema, args=args, model=model) File "/home/dell/local/HK/AnoDDPM-master/evaluation.py", line 124, in testing x = x.to(device) NameError: name 'device' is not defined

  1. When I tried detection, I entered the following command: python3 detection.py args19.json Here, args19.json is the configuration file I trained with But the following error is reported:

This is the shape of the layer for the row where the error occurred Conv2d(1, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)

Traceback (most recent call last): File "detection.py", line 959, in anomalous_metric_calculation() File "detection.py", line 226, in anomalous_metric_calculation t_distance=200, denoise_fn=args["noise_fn"] File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 354, in forward_backward out = self.sample_p(model, x, t_batch, denoise_fn) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 299, in sample_p out = self.p_mean_variance(model, x_t, t) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 279, in p_mean_variance estimate_noise = model(x_t, t) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 400, in forward h = module(h, time_embed) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 35, in forward x = layer(x) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 396, in _conv_forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight of size [128, 1, 3, 3], expected input[1, 3, 256, 256] to have 1 channels, but got 3 channels instead

I wonder if there is something wrong with my detection call (I did not change your code) : 屏幕截图 2023-06-03 134954

Maybe my question is relatively simple, but it has really caused me a lot of trouble. I would like to express my deep thanks again for troubling you.

jamdodot commented 1 year ago

Like you, I also made an error in the test after the training, but the channel of my args is 3. The problem I encountered during the test is that args["img_size"] is of float type, resulting in the following error.

Since image dtype is floating point, you must specify ' 'the data_range parameter. Please read the documentation ' 'carefully (including the note). It is recommended that ' 'you always specify the data_range anyway.

https://github.com/scikit-image/scikit-image/blob/6569fbfeb2891a7498418e2d5b8af9e851ca2102/skimage/metrics/_structural_similarity.py#LL194C30-L194C30

The outermost layer of the faulting method stack is the following line of code https://github.com/Julian-Wyatt/AnoDDPM/blob/3052f0441a472af55d6e8b1028f5d3156f3d6ed3/detection.py#L243 https://github.com/Julian-Wyatt/AnoDDPM/blob/3052f0441a472af55d6e8b1028f5d3156f3d6ed3/evaluation.py#L48

My training args are 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": 800,
  "weight_decay": 0.0,
  "save_imgs": true,
  "save_vids": false,
  "dropout": 0,
  "attention_resolutions": "16,8",
  "num_heads": 2,
  "num_head_channels": -1,
  "noise_fn": "simplex",
  "channels": 3,
  "dataset": "leather"
}
Julian-Wyatt commented 1 year ago

Like you, I also made an error in the test after the training, but the channel of my args is 3. The problem I encountered during the test is that args["img_size"] is of float type, resulting in the following error.

Since image dtype is floating point, you must specify ' 'the data_range parameter. Please read the documentation ' 'carefully (including the note). It is recommended that ' 'you always specify the data_range anyway.

https://github.com/scikit-image/scikit-image/blob/6569fbfeb2891a7498418e2d5b8af9e851ca2102/skimage/metrics/_structural_similarity.py#LL194C30-L194C30

The outermost layer of the faulting method stack is the following line of code

https://github.com/Julian-Wyatt/AnoDDPM/blob/3052f0441a472af55d6e8b1028f5d3156f3d6ed3/detection.py#L243

https://github.com/Julian-Wyatt/AnoDDPM/blob/3052f0441a472af55d6e8b1028f5d3156f3d6ed3/evaluation.py#L48

My training args are 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": 800,
  "weight_decay": 0.0,
  "save_imgs": true,
  "save_vids": false,
  "dropout": 0,
  "attention_resolutions": "16,8",
  "num_heads": 2,
  "num_head_channels": -1,
  "noise_fn": "simplex",
  "channels": 3,
  "dataset": "leather"
}

The most likely answer here is that the code just needs a check if 3 channels are given with an edge case (there could be a nicer way but I'm not super familiar off the top of my head with the SSIM method from sklearn) - When writing my original codebase I naïvely hard coded the channels in some areas leading to issues above.

Julian-Wyatt commented 1 year ago

Hello author, I am honored to read your paper. After completing leather data set training, I tried to detect, but encountered some problems: Here is my args file:

args19.json { "img_size": [256,256], "Batch_Size": 1, "EPOCHS": 1000, "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":true, "save_vids":true, "dropout":0, "attention_resolutions":"16,8", "num_heads":2, "num_head_channels":-1, "noise_fn":"simplex", "dataset":"leather", "channels": 1 }

After the training:

  1. Error is reported in evaluation.testing() immediately after train:

File "diffusion_training.py", line 153, in train evaluation.testing(testing_dataset_loader, diffusion, ema=ema, args=args, model=model) File "/home/dell/local/HK/AnoDDPM-master/evaluation.py", line 124, in testing x = x.to(device) NameError: name 'device' is not defined

  1. When I tried detection, I entered the following command: python3 detection.py args19.json Here, args19.json is the configuration file I trained with But the following error is reported:

This is the shape of the layer for the row where the error occurred Conv2d(1, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)

Traceback (most recent call last): File "detection.py", line 959, in anomalous_metric_calculation() File "detection.py", line 226, in anomalous_metric_calculation t_distance=200, denoise_fn=args["noise_fn"] File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 354, in forward_backward out = self.sample_p(model, x, t_batch, denoise_fn) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 299, in sample_p out = self.p_mean_variance(model, x_t, t) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 279, in p_mean_variance estimate_noise = model(x_t, t) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 400, in forward h = module(h, time_embed) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 35, in forward x = layer(x) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 396, in _conv_forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight of size [128, 1, 3, 3], expected input[1, 3, 256, 256] to have 1 channels, but got 3 channels instead

I wonder if there is something wrong with my detection call (I did not change your code) : 屏幕截图 2023-06-03 134954

Maybe my question is relatively simple, but it has really caused me a lot of trouble. I would like to express my deep thanks again for troubling you.

The direct test methods had a couple of bugs towards the end of my development, so I apologise. Clearly, a device error here should be quick and easy to fix and rerun?

Regarding the second issue. It is hard to say what the specific issue is here with the model being so large. However, it is evidently a channel issue; so I would ensure that the resulting channels are as expected throughout the Simplex calculations, and when passing the image into the model. Any further issues, please feel free to reach out.

ZZZGGGG commented 1 year ago

Hello author, I am honored to read your paper. After completing leather data set training, I tried to detect, but encountered some problems: Here is my args file: args19.json { "img_size": [256,256], "Batch_Size": 1, "EPOCHS": 1000, "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":true, "save_vids":true, "dropout":0, "attention_resolutions":"16,8", "num_heads":2, "num_head_channels":-1, "noise_fn":"simplex", "dataset":"leather", "channels": 1 } After the training:

  1. Error is reported in evaluation.testing() immediately after train:

File "diffusion_training.py", line 153, in train evaluation.testing(testing_dataset_loader, diffusion, ema=ema, args=args, model=model) File "/home/dell/local/HK/AnoDDPM-master/evaluation.py", line 124, in testing x = x.to(device) NameError: name 'device' is not defined

  1. When I tried detection, I entered the following command: python3 detection.py args19.json Here, args19.json is the configuration file I trained with But the following error is reported:

This is the shape of the layer for the row where the error occurred Conv2d(1, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1) Traceback (most recent call last): File "detection.py", line 959, in anomalous_metric_calculation() File "detection.py", line 226, in anomalous_metric_calculation t_distance=200, denoise_fn=args["noise_fn"] File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 354, in forward_backward out = self.sample_p(model, x, t_batch, denoise_fn) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 299, in sample_p out = self.p_mean_variance(model, x_t, t) File "/home/dell/local/HK/AnoDDPM-master/GaussianDiffusion.py", line 279, in p_mean_variance estimate_noise = model(x_t, t) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 400, in forward h = module(h, time_embed) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "/home/dell/local/HK/AnoDDPM-master/UNet.py", line 35, in forward x = layer(x) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "/home/dell/anaconda3/envs/pytorch181/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 396, in _conv_forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight of size [128, 1, 3, 3], expected input[1, 3, 256, 256] to have 1 channels, but got 3 channels instead I wonder if there is something wrong with my detection call (I did not change your code) : 屏幕截图 2023-06-03 134954 Maybe my question is relatively simple, but it has really caused me a lot of trouble. I would like to express my deep thanks again for troubling you.

The direct test methods had a couple of bugs towards the end of my development, so I apologise. Clearly, a device error here should be quick and easy to fix and rerun?

Regarding the second issue. It is hard to say what the specific issue is here with the model being so large. However, it is evidently a channel issue; so I would ensure that the resulting channels are as expected throughout the Simplex calculations, and when passing the image into the model. Any further issues, please feel free to reach out.

Hello, Professor, your work is very wonderful, but I have some questions when I reproduce your paper, that is, why can the batchsize only be 1? When I change it to a different multiple, the model will report an error during the diffusion process

Julian-Wyatt commented 1 year ago

Hello, Professor, your work is very wonderful, but I have some questions when I reproduce your paper, that is, why can the batchsize only be 1? When I change it to a different multiple, the model will report an error during the diffusion process

Moved to new issue