anomalib.models.fastflow.torch_model¶
FastFlow Torch Model Implementation.
Module Contents¶
Classes¶
FastFlow. |
Functions¶
|
Subnet Convolutional Function. |
|
Create NF Fast Flow Block. |
- anomalib.models.fastflow.torch_model.subnet_conv_func(kernel_size: int, hidden_ratio: float) Callable[source]¶
Subnet Convolutional Function.
- Callable class or function
f, called asf(channels_in, channels_out)and should return a torch.nn.Module. Predicts coupling coefficients \(s, t\).
- Parameters
kernel_size (int) – Kernel Size
hidden_ratio (float) – Hidden ratio to compute number of hidden channels.
- Returns
Sequential for the subnet constructor.
- Return type
Callable
- Callable class or function
- anomalib.models.fastflow.torch_model.create_fast_flow_block(input_dimensions: List[int], conv3x3_only: bool, hidden_ratio: float, flow_steps: int, clamp: float = 2.0) anomalib.models.components.freia.framework.SequenceINN[source]¶
Create NF Fast Flow Block.
This is to create Normalizing Flow (NF) Fast Flow model block based on Figure 2 and Section 3.3 in the paper.
- Parameters
input_dimensions (List[int]) – Input dimensions (Channel, Height, Width)
conv3x3_only (bool) – Boolean whether to use conv3x3 only or conv3x3 and conv1x1.
hidden_ratio (float) – Ratio for the hidden layer channels.
flow_steps (int) – Flow steps.
clamp (float, optional) – Clamp. Defaults to 2.0.
- Returns
FastFlow Block.
- Return type
- class anomalib.models.fastflow.torch_model.FastflowModel(input_size: Tuple[int, int], backbone: str, flow_steps: int, conv3x3_only: bool = False, hidden_ratio: float = 1.0)[source]¶
Bases:
torch.nn.ModuleFastFlow.
Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows.
- Parameters
input_size (Tuple[int, int]) – Model input size.
backbone (str) – Backbone CNN network
flow_steps (int) – Flow steps.
conv3x3_only (bool, optinoal) – Use only conv3x3 in fast_flow model. Defaults to False.
hidden_ratio (float, optional) – Ratio to calculate hidden var channels. Defaults to 1.0.
- Raises
ValueError – When the backbone is not supported.
- forward(self, input_tensor: torch.Tensor) Union[Tuple[List[torch.Tensor], List[torch.Tensor]], torch.Tensor][source]¶
Forward-Pass the input to the FastFlow Model.
- Parameters
input_tensor (Tensor) – Input tensor.
- Returns
- During training, return
(hidden_variables, log-of-the-jacobian-determinants). During the validation/test, return the anomaly map.
- Return type
Union[Tuple[Tensor, Tensor], Tensor]
- _get_cnn_features(self, input_tensor: torch.Tensor) List[torch.Tensor][source]¶
Get CNN-based features.
- Parameters
input_tensor (Tensor) – Input Tensor.
- Returns
List of features.
- Return type
List[Tensor]