Skip to content

DeepPainterlyHarmonization notebook error: IndexError: too many indices for tensor of dimension 1 #6

@lishali

Description

@lishali

Hi Sylvain, thanks for the awesome exposition in your DeepPainterlyHarmonization notebook. I am however running into an issue during the second training phase. Not changing anything, was able to reproduce the code up until In[84].
With the following warning:

IndexError: too many indices for tensor of dimension 1

Here's the detailed warning:


IndexError Traceback (most recent call last)
in ()
1 n_iter=0
----> 2 while n_iter <= max_iter: optimizer.step(partial(step,final_loss))

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/optim/lbfgs.py in step(self, closure)
101
102 # evaluate initial f(x) and df/dx
--> 103 orig_loss = closure()
104 loss = float(orig_loss)
105 current_evals = 1

in step(loss_fn)
2 global n_iter
3 optimizer.zero_grad()
----> 4 loss = loss_fn(opt_img_v)
5 loss.backward()
6 n_iter += 1

in final_loss(opt_img_v)
4 c_loss = content_loss(out_ftrs[-1])
5 s_loss = style_loss(out_ftrs)
----> 6 h_loss = hist_loss([out_ftrs[0], out_ftrs[3]])
7 t_loss = tv_loss(opt_img_v[0])
8 return c_loss + w_s * s_loss + w_h * h_loss + w_tv * t_loss

in hist_loss(out_ftrs)
6 mask = V(torch.Tensor(mf).contiguous().view(1, -1), requires_grad=False)
7 of_masked = of * mask
----> 8 of_masked = torch.cat([of_masked[i][mask>=0.1].unsqueeze(0) for i in range(of_masked.size(0))])
9 loss += F.mse_loss(of_masked, V(remap_hist(of_masked, sh), requires_grad=False))
10 return loss / 2

in (.0)
6 mask = V(torch.Tensor(mf).contiguous().view(1, -1), requires_grad=False)
7 of_masked = of * mask
----> 8 of_masked = torch.cat([of_masked[i][mask>=0.1].unsqueeze(0) for i in range(of_masked.size(0))])
9 loss += F.mse_loss(of_masked, V(remap_hist(of_masked, sh), requires_grad=False))
10 return loss / 2

IndexError: too many indices for tensor of dimension 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions