JuliaWolleb / diffusion-anomaly

Anomaly detection with diffusion models
MIT License
119 stars 23 forks source link

training diffusion model problem #10

Closed ejawany95 closed 1 year ago

ejawany95 commented 1 year ago

hello. I tried to train the diffusion model (image_train.py) for both brats and chexpert, however I encountered the following error.

/diffusion-anomaly-main/guided_diffusion/unet.py", line 647, in forward assert (y is not None) == (self.num_classes is not None), "must specify y if and only if the model is class-conditional" AssertionError: must specify y if and only if the model is class-conditional

May I know if I missed anything?

JuliaWolleb commented 1 year ago

Hi How did you set the flag class_cond? Is it True or False? If you set it to true, you must specify the class label y. If you set it to False, y must be None.

Bhavay-2001 commented 1 year ago

Hi @JuliaWolleb, What should be the value for the class label y and how to specify it as cmd argument?

JuliaWolleb commented 1 year ago

Hi The class label should be y=0 for healthy images, and y=1 for diseased images. You specify this in the dataloader : https://github.com/JuliaWolleb/diffusion-anomaly/blob/90497770394a4c05b6e86cbe309573b0335686a1/guided_diffusion/bratsloader.py#L67

Bhavay-2001 commented 1 year ago

Hi @JuliaWolleb , thanks for your help. I also had one query that in the gaussian_diffusion.py file, there are only 2 categories for model_var_type i.e. [ModelVarType.LEARNED, ModelVarType.LEARNED_RANGE], whereas when I ran the code, the model_var_type was printed as "ModelVarType.FIXED_LARGE". Can you tell what am I doing wrong, why is this happening and how can I correct this?

JuliaWolleb commented 1 year ago

Hi I guess you refer to this line: https://github.com/JuliaWolleb/diffusion-anomaly/blob/509643c3c15fc5af7d4712aa7b1e8ba8a06214ff/guided_diffusion/gaussian_diffusion.py#LL285C9-L285C17

This is an if-statement, which you won't enter if you have "ModelVarType.FIXED_LARGE". Moreover, we will pick the DDIM sampling scheme, where the variance scheme will be dropped anyway. Please refer to the paper "Diffusion Models Beat GANs on Image Synthesis" for the for the theoretical background.

Bhavay-2001 commented 1 year ago

Hi, I figured out that I was not passing the learn_sigma argument due to which the var type of the model was soo. Thanks for the comments and I'll check the paper to strengthen my understanding of the diffusion concept