Model requirements#
plenoptic provides a model-based synthesis framework, and therefore we require several things of the models used with the package (the validate_model function provides a convenient way to check whether your model meets the following requirements, and see Models for some examples). Your model:
should inherit
torch.nn.Module(this is not strictly necessary, but will make meeting the other requirements easier).must be callable, be able to accept a
torch.Tensoras input, and return atorch.Tensoras output.If you inherit
torch.nn.Module, implementing theforwardmethod will make your model callable.Otherwise, implement the
__call__method.
the above transformation must be differentiable by torch. In practice, this generally means you perform all computations using torch functions (unless you want to write a custom
backwardmethod).must not have any learnable parameters. This is largely to save time by avoiding calculation of unnecessary gradients, but synthesis is performed with a fixed model — we are optimizing the input, not the model parameters. You can use the helper function
remove_gradto detach all parameters. Similarly, your model should probably be in evaluation mode (i.e., callmodel.eval), though this is not strictly required. See the pytorch documentation for the difference between evaluation mode and disabling gradient computation.finally, your model inputs and outputs should be real- or complex-valued and should be interpretable for all possible values (within some range). The intention of stimulus synthesis is to facilitate model understanding — if the synthesized stimulus are meaningless, this defeats the purpose. (Note that domain restrictions, such as requiring integer-valued inputs, can probably be accomplished by adding a penalty to an objective function, but will make optimization harder.)
Compatibility with coarse-to-fine synthesis#
MetamerCTF implements
coarse-to-fine synthesis, as described in Portilla and Simoncelli, 2000. To make use of coarse-to-fine synthesis, your model must meet the following additional requirements (use the validate_coarse_to_fine function to check and see PortillaSimoncelli for an example):
the model must have a
scalesattribute.addition to a
torch.Tensor, theforwardmethod must also be able to accept an optionalscalesargument (equivalently, when calling the model, if the model does not inherittorch.nn.Module).that argument should be a list, containing one or more values from
model.scales, and the shape of the output should change whenscalesis a strict subset of all possible values.
Metric requirements#
MADCompetition uses metrics, rather than models, which have the following requirements (use the validate_metric function to check whether your metric meets the following requirements and see Metrics for some examples):
a metric must be callable, accept two
torch.Tensorobjects as inputs, and return a scalar as output. It can be atorch.nn.Moduleobject or other callable object, like models, as well as a function.when called on two identical inputs, the metric must return a value less than
5e-7(effectively, zero).it must always return a non-negative number.