Skip to main content
Version: 0.2.3

Interface: Transforms

torchlive/torchvision.Transforms

Transforms are common image transformations available in the torchvision.transforms module.

https://pytorch.org/vision/0.12/transforms.html

Methods​

centerCrop​

▸ centerCrop(size): Transform

Crops the image Tensor at the center. It is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions. If image size is smaller than output size along any edge, image is padded with 0 and then center cropped.

https://pytorch.org/vision/0.12/generated/torchvision.transforms.CenterCrop.html

Parameters​

NameTypeDescription
sizenumber | [number] | [number, number]Desired output size of the crop. If size is an int instead of sequence like (h, w), a square crop (size, size) is made. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).

Returns​

Transform


grayscale​

▸ grayscale(numOutputChannels?): Transform

Convert image to grayscale. It is expected to have […, 3, H, W] shape, where … means an arbitrary number of leading dimensions.

https://pytorch.org/vision/0.12/generated/torchvision.transforms.Grayscale.html

Parameters​

NameTypeDescription
numOutputChannels?1 | 3Number of channels desired for output image.

Returns​

Transform


normalize​

▸ normalize(mean, std, inplace?): Transform

Normalize a tensor image with mean and standard deviation. Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for n channels, this transform will normalize each channel of the input torch.

Tensor i.e., output[channel] = (input[channel] - mean[channel]) / std[channel].

https://pytorch.org/vision/0.12/generated/torchvision.transforms.Normalize.html

Parameters​

NameTypeDescription
meannumber[]Sequence of means for each channel.
stdnumber[]Sequence of standard deviations for each channel.
inplace?booleanBool to make this operation in-place.

Returns​

Transform


resize​

▸ resize(size, interpolation?, maxSize?, antialias?): Transform

Resize the input tensor image to the given size. It is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions.

https://pytorch.org/vision/0.12/generated/torchvision.transforms.Resize.html

Parameters​

NameTypeDescription
sizenumber | [number] | [number, number]Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).
interpolation?InterpolationModeDesired interpolation enum.
maxSize?numberThe maximum allowed for the longer edge of the resized image.
antialias?booleanAntialias flag. The flag is false by default and can be set to true for InterpolationMode.BILINEAR only mode.

Returns​

Transform