Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

tensorboard logger asking for a detach() #195

Open
LucaMarconato opened this issue Oct 11, 2019 · 2 comments
Open

tensorboard logger asking for a detach() #195

LucaMarconato opened this issue Oct 11, 2019 · 2 comments

Comments

@LucaMarconato
Copy link

  • inferno version:
    output from conda list | grep inferno
inferno                   v0.4.0                     py_0    conda-forge
inferno-pytorch           0.4.0                    pypi_0    pypi
  • Python version:
    3.7.4
  • Operating System:
    centOS

Description

I get this error (I show only the last line of the backtrace)

  File "/home/my_username/anaconda3/envs/my_project/lib/python3.7/site-packages/inferno/trainers/callbacks/logging/tensorboard.py", line 292, in extract_images_from_batch
    batch = batch.float().numpy()
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

Produced by running the following code (I post only the part that should be relevant)

    # ...
    trainer = Trainer(vae)
    trainer.save_to_directory(folder)
    trainer.cuda()
    trainer.build_criterion(vae.loss_function())
    trainer.build_optimizer('Adam', lr=0.001)
    trainer.save_every((1, 'epochs'))
    trainer.set_max_num_epochs(100)
    trainer.build_logger(TensorboardLogger(log_scalars_every=(1, 'iteration'),
                                           log_images_every=(1, 'iteration'),
                                           log_directory=folder))
    # ...
@LucaMarconato
Copy link
Author

Blindly patching the above line by replacing

batch = batch.float().numpy()

with

batch = batch.float().detach().numpy()

fixes the problem. I do not know if this makes sense in this context, so I ask here.

@DerThorsten
Copy link
Collaborator

DerThorsten commented Oct 11, 2019

I think it makes sense what u are doing, feel free to at some kind of PR
Also I would like to ask you to try the new logger interface:

#193

Iff this is working for you and you also like this I'll merge this in master

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants