anomalib.models.components.freia.framework

Framework.

Submodules

Package Contents

Classes

SequenceINN

Simpler than FrEIA.framework.GraphINN.

class anomalib.models.components.freia.framework.SequenceINN(*dims: int, force_tuple_output=False)[source]

Bases: anomalib.models.components.freia.modules.base.InvertibleModule

Simpler 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)

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).

__getitem__(self, item)

Get item.

__len__(self)

Get length.

__iter__(self)

Iter.

output_dims(self, input_dims: List[Tuple[int]]) List[Tuple[int]]

Output Dims.

forward(self, x_or_z: torch.Tensor, c: Iterable[torch.Tensor] = None, rev: bool = False, jac: bool = True) Tuple[torch.Tensor, torch.Tensor]

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)