Clamping / Clipping#

vision_architectures.utils.clamping.symmetric_tanh_clamp(x, max_value)[source]#

Clamps the input tensor to the range [-max_value, max_value] using tanh while keeping it differentiable.

Parameters:
  • x (tensor) – The input tensor to be clamped.

  • max_value (float) – The maximum absolute value to clamp to.

Return type:

tensor

Returns:

Clamped differentiable tensor.

vision_architectures.utils.clamping.floor_softplus_clamp(x, min_value)[source]#

Clamps the input tensor to be greater than or equal to min_value using softplus while keeping it differentiable.

Parameters:
  • x (tensor) – The input tensor to be clamped.

  • min_value (float) – The minimum value to clamp to.

Return type:

tensor

Returns:

Clamped differentiable tensor.

vision_architectures.utils.clamping.ceil_softplus_clamp(x, max_value)[source]#

Clamps the input tensor to be less than or equal to max_value using softplus while keeping it differentiable.

Parameters:
  • x (tensor) – The input tensor to be clamped.

  • max_value (float) – The maximum value to clamp to.

Return type:

tensor

Returns:

Clamped differentiable tensor.