plenoptic.validate.validate_coarse_to_fine#

plenoptic.validate.validate_coarse_to_fine(model, image_shape=None, device='cpu')[source]#

Determine whether a model can be used for coarse-to-fine synthesis.

In particular, this function checks the following (with associated errors):

  • Whether model has a scales attribute (AttributeError).

  • Whether model.forward accepts a scales keyword argument (TypeError).

  • Whether the output of model.forward changes shape when the scales keyword argument is set (ValueError).

Parameters:
  • model (Module) – The model to validate.

  • image_shape (tuple[int, int, int, int] | None (default: None)) – Some models (e.g., the steerable pyramid) can only accept inputs of a certain shape. If that’s the case for model, use this to specify the expected shape. If None, we use an image of shape (1,1,16,16).

  • device (str | device (default: 'cpu')) – Which device to place the test image on.

Raises:
  • AttributeError – If model does not have a scales attribute.

  • TypeError – If model.forward does not accept a scales keyword argument.

  • ValueError – If model.forward output does not change shape when scales keyword argument is set.

Examples

Check that one of our built-in models work:

>>> import plenoptic as po
>>> model = po.models.PortillaSimoncelli((256, 256))
>>> po.validate.validate_coarse_to_fine(model, image_shape=(1, 1, 256, 256))

Intentionally fail:

>>> import plenoptic as po
>>> import torch
>>> # this fails because it's missing the scales attribute
>>> class FailureModel(torch.nn.Module):
...     def __init__(self):
...         super().__init__()
...         self.model = po.models.PortillaSimoncelli((256, 256))
...
...     def forward(self, x):
...         return self.model(x)
>>> shape = (1, 1, 256, 256)
>>> model = FailureModel()
>>> po.validate.validate_coarse_to_fine(model, shape)
Traceback (most recent call last):
AttributeError: model has no scales attribute ...