Parameters and usage of RandomResizedCrop() in Pytorch

When I was looking at some codes recently, I found that the functions I learned before were somewhat forgotten. I will review them here and hope to bring you some useful knowledge.

This RandomResizedCrop() function is the same as ToTensor(), the transforms in torchvision

inside the bag. Generally speaking, it is used for preprocess and data augmentation of pictures.

import torchvision

trans = torchvision.transforms.RandomResizedCrop((224,224),scale=(0.8,1.0),ratio=(1.0,1.0))

The function RandomResizeCrop(), the three most commonly used parameters are size, scale, and ratio

First of all, size is the final size of your picture after passing this function; if you only fill in this parameter with an int, then the final size of the picture is (int, int), if you fill in a tuple of (int, int), then the width and height of the picture after this function is (int, int)

Let’s talk about scale again. If you write “scale=(0.8, 1.0)” for this parameter, it means that when this function randomly samples the picture, it must cover at least 80% of the picture and keep the picture unchanged at most.

Then let’s talk about ratio. If you fill in “ratio=(0.5, 1.0)” for this parameter, it means that the ratio of width to height of randomly sampled images is 0.5:1.

In general, this function will first randomly sample the image according to the scale and ratio you set, then reconstruct the image according to the size you set, and then output it.

Guess you like

Origin blog.csdn.net/qq_43438974/article/details/127598815