plenoptic.validate.validate_input#

plenoptic.validate.validate_input(input_tensor, no_batch=False)[source]#

Determine whether input_tensor can be used for synthesis.

In particular, this function:

  • Checks if input_tensor has a float or complex dtype (TypeError).

  • If no_batch is True, check whether input_tensor.shape[0] == 1 or input_tensor.ndimension()==1 (ValueError).

Additionally, if input_tensor is not 4d, or of it is outside the range (0, 1), raises a UserWarning.

Parameters:
  • input_tensor (Tensor) – The tensor to validate.

  • no_batch (bool (default: False)) – If True, raise a ValueError if the batch dimension of input_tensor is greater than 1.

Raises:
  • ValueError – If no_batch is True and the batch dimension of input_tensor is greater than 1.

  • TypeError – If input_tensor does not have a float or complex dtype.

Warns:
  • UserWarning – If input_tensor is not 4d

  • UserWarning – If input_tensor has values outside (0, 1).

Examples

Check that our built-in images work:

>>> import plenoptic as po
>>> po.validate.validate_input(po.data.einstein())

Intentionally fail:

>>> import plenoptic as po
>>> img = torch.randint(low=0, high=255, size=(1, 1, 32, 32))
>>> po.validate.validate_input(img)
Traceback (most recent call last):
TypeError: Only float or complex dtypes are allowed ...