1. 程式人生 > 程式設計 >pytorch之Resize()函式具體使用詳解

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

到此這篇關於pytorch之Resize()函式具體使用詳解的文章就介紹到這了,更多相關pytorch Resize() 內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!