anomalib.models.components.freia.framework.sequence_inn¶
Sequence INN.
Module Contents¶
Classes¶
Simpler than FrEIA.framework.GraphINN. |
- class anomalib.models.components.freia.framework.sequence_inn.SequenceINN(*dims: int, force_tuple_output=False)[source]¶
Bases:
anomalib.models.components.freia.modules.base.InvertibleModuleSimpler than FrEIA.framework.GraphINN.
Only supports a sequential series of modules (no splitting, merging, branching off). Has an append() method, to add new blocks in a more simple way than the computation-graph based approach of GraphINN. For example: .. code-block:: python
inn = SequenceINN(channels, dims_H, dims_W) for i in range(n_blocks):
inn.append(FrEIA.modules.AllInOneBlock, clamp=2.0, permute_soft=True)
inn.append(FrEIA.modules.HaarDownsampling) # and so on
- append(self, module_class, cond=None, cond_shape=None, **kwargs)[source]¶
Append a reversible block from FrEIA.modules to the network.
- Parameters
module_class – Class from FrEIA.modules.
cond (int) – index of which condition to use (conditions will be passed as list to forward()). Conditioning nodes are not needed for SequenceINN.
cond_shape (tuple[int]) – the shape of the condition tensor.
**kwargs – Further keyword arguments that are passed to the constructor of module_class (see example).
- forward(self, x_or_z: torch.Tensor, c: Iterable[torch.Tensor] = None, rev: bool = False, jac: bool = True) Tuple[torch.Tensor, torch.Tensor][source]¶
Execute the sequential INN in forward or inverse (rev=True) direction.
- Parameters
x_or_z – input tensor (in contrast to GraphINN, a list of tensors is not supported, as SequenceINN only has one input).
c – list of conditions.
rev – whether to compute the network forward or reversed.
jac – whether to compute the log jacobian
- Returns
network output. jac (Tensor): log-jacobian-determinant.
- Return type
z_or_x (Tensor)