greentfrapp / lucent

Lucid library adapted for PyTorch
Apache License 2.0
597 stars 89 forks source link

ValueError in Render #26

Closed tatkeller closed 3 years ago

tatkeller commented 3 years ago

Hi there,

I am trying to run the tutorial and am running into the following error:

>>> import torch
>>> from lucent.optvis import render, param, transform, objectives
>>> from lucent.modelzoo import inceptionv1
>>> device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
>>> model = inceptionv1(pretrained=True)
>>> _ = model.to(device).eval()
>>> _ = render.render_vis(model, "mixed4a:476", show_inline=True)
  0%|                                                                                       | 0/512 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tatekeller/opt/anaconda3/envs/spec/lib/python3.8/site-packages/lucent/optvis/render.py", line 113, in render_vis
    optimizer.step(closure)
  File "/Users/tatekeller/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
    return func(*args, **kwargs)
  File "/Users/tatekeller/.local/lib/python3.8/site-packages/torch/optim/adam.py", line 66, in step
    loss = closure()
  File "/Users/tatekeller/opt/anaconda3/envs/spec/lib/python3.8/site-packages/lucent/optvis/render.py", line 97, in closure
    model(transform_f(image_f()))
  File "/Users/tatekeller/opt/anaconda3/envs/spec/lib/python3.8/site-packages/lucent/optvis/transform.py", line 85, in inner
    x = transform(x)
  File "/Users/tatekeller/opt/anaconda3/envs/spec/lib/python3.8/site-packages/lucent/optvis/transform.py", line 75, in inner
    M = kornia.get_rotation_matrix2d(center, angle, scale).to(device)
  File "/Users/tatekeller/opt/anaconda3/envs/spec/lib/python3.8/site-packages/kornia/geometry/transform/imgwarp.py", line 347, in get_rotation_matrix2d
    raise ValueError("Input scale must be a B tensor. Got {}"
ValueError: Input scale must be a B tensor. Got torch.Size([1, 2])

I am using a conda environment with Python 3.8.5 and pytorch=1.7.0.

Any help regarding this error would be much appreciated!

greentfrapp commented 3 years ago

Hey @tatkeller thanks for checking out Lucent! Can I just check what version of kornia you're using?

tatkeller commented 3 years ago

Thanks for the quick response! I'm using kornia=0.3.0.

greentfrapp commented 3 years ago

There was a breaking change between kornia 0.4.0 and previous versions of kornia. I just updated lucent to be backward compatible with older version of kornia as well. If you run pip3 install --upgrade torch-lucent that should install the latest. Alternatively, upgrading kornia will help too!

tatkeller commented 3 years ago

Works now! Thanks so much!