inferno icon indicating copy to clipboard operation
inferno copied to clipboard

tensorboard logger asking for a detach()

Open LucaMarconato opened this issue 5 years ago • 2 comments

  • 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 avatar Oct 11 '19 13:10 LucaMarconato

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.

LucaMarconato avatar Oct 11 '19 13:10 LucaMarconato

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:

https://github.com/inferno-pytorch/inferno/pull/193

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

DerThorsten avatar Oct 11 '19 13:10 DerThorsten