ClassificationData.batch_to_images#
- abstract ClassificationData.batch_to_images(batch) Sequence[ndarray] [source]#
Transform a batch of data to images in the accpeted format.
- Parameters
- batchtorch.Tensor
Batch of data to transform to images.
- Returns
- Sequence[np.ndarray]
List of images in the accepted format. Each image in the iterable must be a [H, W, C] 3D numpy array. See notes for more details. :func: batch_to_images must be implemented in a subclass.
Notes
Each image in the iterable must be a [H, W, C] 3D numpy array. The first dimension must be the image height (y axis), the second being the image width (x axis), and the third being the number of channels. The numbers in the array should be in the range [0, 255]. Color images should be in RGB format and have 3 channels, while grayscale images should have 1 channel.
Examples
>>> import numpy as np ... ... ... def batch_to_images(self, batch): ... # Converts a batch of normalized images to rgb images with range [0, 255] ... inp = batch[0].detach().numpy().transpose((0, 2, 3, 1)) ... mean = [0.485, 0.456, 0.406] ... std = [0.229, 0.224, 0.225] ... inp = std * inp + mean ... inp = np.clip(inp, 0, 1) ... return inp * 255