dome272 / Diffusion-Models-pytorch

Pytorch implementation of Diffusion Models (https://arxiv.org/pdf/2006.11239.pdf)
Apache License 2.0
1.11k stars 256 forks source link

Increase image_size for training #7

Closed s101010tw closed 1 year ago

s101010tw commented 1 year ago

Thanks for your great work!!

The code can be trained using image_size with 64, and the sampling results are OK. However, I try to use large size for training (e.g. image_size = 128), and the code cannot be trained.

Could you share how to resolve this problem. I appreciate your help very much~

ZhouHaoWa commented 1 year ago

i may answer your question, you should take care of the initialized self.size in function selfattention, which is consisitent with the image_size 64. if you use imge_size=128, make sure that modify the initialized self.size firstly.

Tungthanhlee commented 1 year ago

how would you change the size of the attention block to fit with every image_size choice?

dome272 commented 1 year ago

You would simply modify this line here: https://github.com/dome272/Diffusion-Models-pytorch/blob/be352208d0576039fec061238c0e4385a562a2d4/modules.py#L50 Instead of having a fixed resolution you would just take x.shape and use the hight and width from there and then reshape according to that. So e.g.: x = x.view(-1, self.channels, x.shape[2] * x.shape[3]).swapaxes(1, 2)

And then you can also adjust it here: https://github.com/dome272/Diffusion-Models-pytorch/blob/be352208d0576039fec061238c0e4385a562a2d4/modules.py#L55

markstent commented 1 year ago

I tried it at anything above 64, and it crashes...is this the only place you need to change things?

Aryan-Deshpande commented 1 year ago

Thanks for your great work!!

The code can be trained using image_size with 64, and the sampling results are OK. However, I try to use large size for training (e.g. image_size = 128), and the code cannot be trained.

Could you share how to resolve this problem. I appreciate your help very much~

I have the same issue, althought when i use an image with a smaller size, i recieve this error. image for reference the img_size is 6

karkay22 commented 1 year ago

Thanks for your great work!! The code can be trained using image_size with 64, and the sampling results are OK. However, I try to use large size for training (e.g. image_size = 128), and the code cannot be trained. Could you share how to resolve this problem. I appreciate your help very much~

I have the same issue, althought when i use an image with a smaller size, i recieve this error. image for reference the img_size is 6

Hello, I'm encountering the same problem when I try to train the model on 32*32 images. Did you solve it ?

Thanks

Aryan-Deshpande commented 1 year ago

@karkay22 Hey, I kind of played around with the code a little bit and I figured that it was only wise to use 64x64 images. Since a change in the image size would also require a change in the input & output dimensions for each attention block, which can be quite tedious.

A solution to this would be to try changing the attention block dimensions as well as the ConvTranspose & Upscale blocks to meet the image size transformations.

dome272 commented 1 year ago

Take a look here https://github.com/dome272/Diffusion-Models-pytorch/issues/7

egoist945402376 commented 9 months ago

Do you have detail code to show how to change img_size to 128 for your solution?