dgs.utils.validation.validate_image¶
- dgs.utils.validation.validate_image(images: torchvision.tv_tensors.Image | torch.Tensor | torch.Tensor, length: int | None = None, dims: int | None = 4) torchvision.tv_tensors.Image | torch.Tensor [source]¶
Given one single image or a stacked batch images, validate them and return a torchvision-tensor image.
- Parameters:
images – torch tensor or tv_tensor.Image object
length – The number of items or batch-size the tensor should have. Default None does not validate the length.
dims – Number of dimensions img should have. Use None to not force any number of dimensions. Defaults to four dimensions with the image dimensions as
[B x C x H x W]
.
- Returns:
The images as tv_tensor.Image object with exactly dims dimensions.
- Return type:
Image
- Raises:
TypeError – If images is not a Tensor or cannot be cast to one.
ValueError – If the dimension of the images channels is wrong.