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
modelhas ascalesattribute (AttributeError).Whether
model.forwardaccepts ascaleskeyword argument (TypeError).Whether the output of
model.forwardchanges shape when thescaleskeyword 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 formodel, use this to specify the expected shape. IfNone, 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
modeldoes not have ascalesattribute.TypeError – If
model.forwarddoes not accept ascaleskeyword argument.ValueError – If
model.forwardoutput does not change shape whenscaleskeyword 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 ...