perceptor.transforms

class perceptor.transforms.ClampWithGrad(min=0, max=1)[source]

Bases: TransformInterface

decode(tensor)[source]
encode(tensor)[source]
training: bool
class perceptor.transforms.DynamicThreshold(quantile=0.95)[source]

Bases: TransformInterface

decode(images)[source]
encode(images, quantile=None)[source]
training: bool
class perceptor.transforms.SuperResolution(name='x4', half=False)[source]

Bases: TransformInterface

decode(upsampled_images, size=None)[source]
encode(images)[source]
training: bool
perceptor.transforms.clamp_with_grad(tensor, min=0.0, max=1.0)[source]
perceptor.transforms.dynamic_threshold(images, quantile=0.95)[source]
perceptor.transforms.resize(input, scale_factors: Optional[float] = None, out_shape: Optional[Tuple[int, int]] = None, resample: Optional[str] = None, support_sz: Optional[int] = None, antialiasing: bool = True, by_convs: bool = False, scale_tolerance: Optional[float] = None, max_numerator: int = 10, pad_mode: str = 'constant')[source]

Alternative resize method. May be useful but pytorch 1.11 has added optional antialiasing too.

Parameters
  • input – the input image/tensor, a Numpy or Torch tensor.

  • scale_factors – can be specified as 1. one scalar scale - then it will be assumed that you want to resize first two dims with this scale for Numpy or last two dims for PyTorch. 2. a list or tuple of scales - one for each dimension you want to resize. note: if length of the list is L then first L dims will be rescaled for Numpy and last L for PyTorch. 3. not specified - then it will be calculated using output_size. this is not recomended (see advantage 3 in the list above).

  • out_shape

  • first/last (A list or tuple. if shorter than input.shape then only the) –

  • resample

  • interpolation_methods.py. (The type of interpolation used to calculate the weights. this is a scalar to scalar function that can be applied to tensors pointwise. The classical methods are implemented and can be found in) –

  • specified (If not) –

  • downsampling. (then bicubic is used for upsampling and laczos2 for) –

  • support_sz

  • function (This is the support of the interpolation) –

  • 4 (laczos2) –

  • 2 (linear) –

  • 4

  • 6 (lanczos3) –

  • 1. (box) –

  • antialiasing

  • aliasing (This is an option similar to MATLAB's default. Only relevant for downscaling. If true it basically means that the kernel is stretched with 1/scale_factor to prevent) –

  • by_convs – This determines whether to allow efficient calculation using convolutions according to tolerance. This feature should be used when scale_factor is rational with a numerator low enough (or close enough to being an integer) and the tensors are big (batches or high-resolution).

  • scale_tolerance – This is the allowed distance between the M/N closest frac to the float scale_factore provided. If the frac is closer than this distance, then it will be used and efficient convolution calculation will take place.

  • max_numerator – When by_convs is on, the scale_factor is translated to a rational frac M/N. Where M is limited by this parameter. The goal is to make the calculation more efficient. The number of convolutions used is the size of the numerator.

  • pad_mode – This can be used according to the padding methods of each framework. PyTorch: ‘constant’, ‘reflect’, ‘replicate’, ‘circular’. Numpy: ‘constant’, ‘edge’, ‘linear_ramp’, ‘maximum’, ‘mean, ‘median’, ‘minimum’, ‘reflect’, ‘symmetric’, ‘wrap’, ‘empty’