plenoptic-org / plenoptic

Visualize/test models for visual representation by synthesizing images.
https://plenoptic.readthedocs.io/en/latest/
MIT License
61 stars 9 forks source link

`metamer.to` not working? #283

Closed billbrod closed 2 months ago

billbrod commented 3 months ago

Running the following produces unexpected behavior:

img = po.data.einstein()
ps = po.simul.PortillaSimoncelli(img.shape[-2:])
met = po.synth.MetamerCTF(img, ps, loss_function=po.tools.optim.l2_norm)
met.to('cuda')

This raises the following warning:

/mnt/home/wbroderick/plenoptic/src/plenoptic/synthesize/synthesis.py:211: UserWarning: model has no `to` method, so we leave it as is...
  warnings.warn("model has no `to` method, so we leave it as is...")

which should only happen if caling met.model.to raises an AttributeError`, which it doesn't.

Confusingly, met.model(met.metamer) works after this.

However, running met.synthesize() after the aboveraises ValueError: can't optimize a non-leaf Tensor, so something gets messed up with the optimizer.

I think the proper way to do this is to make use of register_buffer or similar, and then remove our definition of def to(), like we've done for the PortillaSimoncelli and SteerablePyramid modules.