HighwayWu / ImageInpainting

36 stars 8 forks source link

RuntimeError: selected index k out of range #7

Closed asdj32n12dk closed 3 years ago

asdj32n12dk commented 3 years ago

Hello, I'm getting this error, using my masks and images:

Traceback (most recent call last): P:31.99, M:0.0248
  File "main.py", line 226, in <module>
    test()
  File "main.py", line 209, in test
    I_g, I_o, val_loss_G = model.optimize_parameters(val=True)
  File "/app/model.py", line 269, in optimize_parameters
    self.forward()
  File "/app/model.py", line 184, in forward
    _, self.I_FEA = self.netG(self.I_g, self.L_g, self.mask)
  File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/app/networks.py", line 211, in forward
    up31 = self.myattention(up31[:, :256, :, :], up31[:, 256:, :, :], mask)
  File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/app/attention.py", line 13, in forward
    return MyAttentionFunction.apply(generated, known, mask, self.device)
  File "/app/attention.py", line 45, in forward
    weight1, indexes1 = torch.topk(cosine1, k, dim=2)
RuntimeError: selected index k out of range

Also is using torch==1.5.1 okay? As I can't figure out how to install tf==1.8.0 and torch==1.6.0 - because they require different cuda versions.

Thanks!

HighwayWu commented 3 years ago

Hi, asdj32n12dk.

This may be because your input mask has too few white regions (the inpainting regions), thus the attention module could not select 2 of the most-relevant patches from the inpainting regions.

Btw, I'm not sure whether the torch==1.5.1 is okay or not, as I didn't test them on the other environments.