HighwayWu / ImageInpainting

36 stars 8 forks source link

batchsize=2,error #12

Open lrn1314 opened 1 year ago

lrn1314 commented 1 year ago

Hello,

Thank you for such a great job and for releasing your code. I want to train your network using a custom dataset. When I looked at the options.py file, the batch_size parameter is set to 1 and has not changed anywhere in other training files.

batchSize=2,Traceback (most recent call last): File "E:\LBP_idea\gabor+dense\gabor-test-dense\main.py", line 234, in train() File "E:\LBP_idea\gabor+dense\gabor-test-dense\main.py", line 151, in train I_g, I_o, loss_G = model.optimize_parameters() File "E:\LBP_idea\gabor+dense\gabor-test-dense\model.py", line 291, in optimize_parameters self.forward() File "E:\LBPidea\gabor+dense\gabor-test-dense\model.py", line 186, in forward , self.I_FEA = self.netG(self.I_g, self.L_g, self.mask) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, kwargs) File "E:\LBP_idea\gabor+dense\gabor-test-dense\networks.py", line 265, in forward up31 = self.myattention(up31[:, :256, :, :], up31[:, 256:, :, :], mask) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, *kwargs) File "E:\LBP_idea\gabor+dense\gabor-test-dense\attention.py", line 13, in forward return MyAttentionFunction.apply(generated, known, mask, self.device) File "D:\Anaconda\envs\pytorch_3.8\lib\site-packages\torch\autograd\function.py", line 506, in apply return super().apply(args, kwargs) # type: ignore[misc] File "E:\LBP_idea\gabor+dense\gabor-test-dense\attention.py", line 27, in forward patches = patches_all[ctx.flag == 1] IndexError: The shape of the mask [1, 2048] at index 0 does not match the shape of the indexed tensor [2, 1024, 256] at index 0

Process finished with exit code 1

HighwayWu commented 1 year ago

Thanks for your question. The attention module is designed for batch size = 1, and may not applied to > 2. This is because the number of known and unknown patches is different for each image, and they can't be processed in group. An additional 'for' loop may handle this problem.

lrn1314 commented 1 year ago

Hello, thank you for your answer. Because I am a student who has just completed my graduate exam, your article has helped me a lot. How should I write an extra ‘for’ loop? For some basic training details, such as the celebA-HQ dataset of 27,000 images, what should I do if there are not so many irregular masks? Thank you very much for your prompt answer.

HighwayWu commented 1 year ago

The current attention is an inner loop, and the outer loop should obtain the feature for each input, and after processing, the features should be merged together.

BTW, I suggest you to ignore the attention module at beginning, and only train the standard U-Net.

lrn1314 commented 1 year ago

Hello, very sorry to ask you again, how should this extra "for" loop be written? Where to add?

Rahaf37 commented 3 months ago

Hello, how I should ignore the attention module?