实例:
import torch
from torch import nn
from torch.nn import functional as F
img = torch.randint(0, 255, (3, 2, 2)) # 默认为torch.int64类型
img = img.type(torch.float32) # 使用F.interpolate函数前需要将img转成float32类型
img = img.unsqueeze(0) # 需要将三维图片(C, H, W)变为四维(N, C, H, W),必须有批量N
img_ = F.interpolate(img, size=(4, 4), mode='nearest') # size是img_的尺寸大小
print("img: \n", img)
print("img_: \n", img_)
网友评论