pytorch之Resize()函數


Resize函數用於對PIL圖像的預處理,它的包在:

from torchvision.transforms import Compose, CenterCrop, ToTensor, Resize

使用如:

def input_transform(crop_size, upscale_factor):
    return Compose([
        CenterCrop(crop_size),
        Resize(crop_size // upscale_factor),
        ToTensor(),
    ])

 

而Resize函數有兩個參數,

CLASS torchvision.transforms.Resize(size, interpolation=2)
size (sequence or int) – 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 (int, optional) – Desired interpolation. Default is PIL.Image.BILINEAR

 

size : 獲取輸出圖像的大小

interpolation : 插值,默認的  PIL.Image.BILINEAR, 一共有4中的插值方法

Image.BICUBIC,PIL.Image.LANCZOS,PIL.Image.BILINEAR,PIL.Image.NEAREST

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM