deeprob.flows package

Subpackages

Submodules

deeprob.flows.utils module

deeprob.flows.utils.squeeze_depth2d(x)[source]

Squeeze operation (as in RealNVP).

Parameters

x (Tensor) – The input tensor of size [N, C, H, W].

Returns

The output tensor of size [N, C * 4, H // 2, W // 2].

Return type

Tensor

deeprob.flows.utils.unsqueeze_depth2d(x)[source]

Un-squeeze operation (as in RealNVP).

Parameters

x (Tensor) – The input tensor of size [N, C * 4, H // 2, W // 2].

Returns

The output tensor of size [N, C, H, W].

Return type

Tensor

class deeprob.flows.utils.Bijector(in_features)[source]

Bases: ABC, Module

Initialize a bijector module.

Parameters

in_features (Union[int, Tuple[int, int, int]]) – The number of input features.

Raises

ValueError – If the number of input features is invalid.

forward(x, backward=False)[source]

Apply the bijector transformation.

Parameters
  • x (Tensor) – The inputs.

  • backward (bool) – Whether to apply the backward transformation.

Returns

The transformed samples and the corresponding log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

abstract apply_backward(x)[source]

Apply the backward transformation.

Parameters

x (Tensor) – The inputs.

Returns

The transformed samples and the backward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

abstract apply_forward(u)[source]

Apply the forward transformation.

Parameters

u (Tensor) – The inputs.

Returns

The transformed samples and the forward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

training: bool
class deeprob.flows.utils.BatchNormLayer1d(in_features, momentum=0.9, eps=1e-05)[source]

Bases: Bijector

Build a Batch Normalization 1D layer.

Parameters
  • in_features (int) – The number of input features.

  • momentum (float) – The momentum used to update the running parameters.

  • eps (float) – Epsilon value, an arbitrarily small value.

Raises

ValueError – If a parameter is out of domain.

apply_backward(x)[source]

Apply the backward transformation.

Parameters

x (Tensor) – The inputs.

Returns

The transformed samples and the backward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

apply_forward(u)[source]

Apply the forward transformation.

Parameters

u (Tensor) – The inputs.

Returns

The transformed samples and the forward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

training: bool
class deeprob.flows.utils.BatchNormLayer2d(in_features, momentum=0.9, eps=1e-05)[source]

Bases: Bijector

Build a Batch Normalization 2D layer.

Parameters
  • in_features (int) – The number of input features.

  • momentum (float) – The momentum used to update the running parameters.

  • eps (float) – An arbitrarily small value.

Raises

ValueError – If a parameter is out of domain.

apply_backward(x)[source]

Apply the backward transformation.

Parameters

x (Tensor) – The inputs.

Returns

The transformed samples and the backward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

apply_forward(u)[source]

Apply the forward transformation.

Parameters

u (Tensor) – The inputs.

Returns

The transformed samples and the forward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

training: bool
class deeprob.flows.utils.DequantizeLayer(in_features, n_bits=8)[source]

Bases: Bijector

Build a Dequantization transformation layer.

Parameters
  • in_features (Union[int, Tuple[int, int, int]]) – The number of input features.

  • n_bits (int) – The number of bits to use.

Raises

ValueError – If a parameter is out of domain.

apply_backward(x)[source]

Apply the backward transformation.

Parameters

x (Tensor) – The inputs.

Returns

The transformed samples and the backward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

apply_forward(u)[source]

Apply the forward transformation.

Parameters

u (Tensor) – The inputs.

Returns

The transformed samples and the forward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

training: bool
class deeprob.flows.utils.LogitLayer(in_features, alpha=0.05)[source]

Bases: Bijector

Build a Logit transformation layer.

Parameters
  • in_features (Union[int, Tuple[int, int, int]]) – The number of input features.

  • alpha (float) – The alpha parameter for logit transformation.

Raises

ValueError – If a parameter is out of domain.

apply_backward(x)[source]

Apply the backward transformation.

Parameters

x (Tensor) – The inputs.

Returns

The transformed samples and the backward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

apply_forward(u)[source]

Apply the forward transformation.

Parameters

u (Tensor) – The inputs.

Returns

The transformed samples and the forward log-det-jacobian.

Return type

Tuple[Tensor, Tensor]

training: bool

Module contents