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() 内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • pytorch AvgPool2d函数使用详解

    我就废话不多说了,直接上代码吧! import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable import numpy as np input = Variable(torch.Tensor([[[1, 3, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]], [[1, 3, 3, 4, 5, 6, 7], [1, 2, 3

  • 使用Pytorch来拟合函数方式

    其实各大深度学习框架背后的原理都可以理解为拟合一个参数数量特别庞大的函数,所以各框架都能用来拟合任意函数,Pytorch也能. 在这篇博客中,就以拟合y = ax + b为例(a和b为需要拟合的参数),说明在Pytorch中如何拟合一个函数. 一.定义拟合网络 1.观察普通的神经网络的优化流程 # 定义网络 net = ... # 定义优化器 optimizer = torch.optim.Adam(net.parameters(), lr=0.001, weight_decay=0.0005)

  • Pytorch mask_select 函数的用法详解

    非常简单的函数,但是官网的介绍令人(令我)迷惑,所以稍加解释. mask_select会将满足mask(掩码.遮罩等等,随便翻译)的指示,将满足条件的点选出来. 根据掩码张量mask中的二元值,取输入张量中的指定项( mask为一个 ByteTensor),将取值返回到一个新的1D张量, 张量 mask须跟input张量有相同数量的元素数目,但形状或维度不需要相同 x = torch.randn(3, 4) x 1.2045 2.4084 0.4001 1.1372 0.5596 1.5677

  • PyTorch中topk函数的用法详解

    听名字就知道这个函数是用来求tensor中某个dim的前k大或者前k小的值以及对应的index. 用法 torch.topk(input, k, dim=None, largest=True, sorted=True, out=None) -> (Tensor, LongTensor) input:一个tensor数据 k:指明是得到前k个数据以及其index dim: 指定在哪个维度上排序, 默认是最后一个维度 largest:如果为True,按照大到小排序: 如果为False,按照小到大排序

  • PyTorch中常用的激活函数的方法示例

    神经网络只是由两个或多个线性网络层叠加,并不能学到新的东西,简单地堆叠网络层,不经过非线性激活函数激活,学到的仍然是线性关系. 但是加入激活函数可以学到非线性的关系,就具有更强的能力去进行特征提取. 构造数据 import torch import torch.nn.functional as F from torch.autograd import Variable import matplotlib.pyplot as plt x = torch.linspace(-5, 5, 200) #

  • pytorch 中pad函数toch.nn.functional.pad()的用法

    padding操作是给图像外围加像素点. 为了实际说明操作过程,这里我们使用一张实际的图片来做一下处理. 这张图片是大小是(256,256),使用pad来给它加上一个黑色的边框.具体代码如下: import torch.nn,functional as F import torch from PIL import Image im=Image.open("heibai.jpg",'r') X=torch.Tensor(np.asarray(im)) print("shape:

  • PyTorch笔记之scatter()函数的使用

    scatter() 和 scatter_() 的作用是一样的,只不过 scatter() 不会直接修改原来的 Tensor,而 scatter_() 会 PyTorch 中,一般函数加下划线代表直接在原来的 Tensor 上修改 scatter(dim, index, src) 的参数有 3 个 dim:沿着哪个维度进行索引 index:用来 scatter 的元素索引 src:用来 scatter 的源元素,可以是一个标量或一个张量 这个 scatter可以理解成放置元素或者修改元素 简单说就

  • Pytorch 的损失函数Loss function使用详解

    1.损失函数 损失函数,又叫目标函数,是编译一个神经网络模型必须的两个要素之一.另一个必不可少的要素是优化器. 损失函数是指用于计算标签值和预测值之间差异的函数,在机器学习过程中,有多种损失函数可供选择,典型的有距离向量,绝对值向量等. 损失Loss必须是标量,因为向量无法比较大小(向量本身需要通过范数等标量来比较). 损失函数一般分为4种,平方损失函数,对数损失函数,HingeLoss 0-1 损失函数,绝对值损失函数. 我们先定义两个二维数组,然后用不同的损失函数计算其损失值. import

  • Pytorch中index_select() 函数的实现理解

    函数形式: index_select( dim, index ) 参数: dim:表示从第几维挑选数据,类型为int值: index:表示从第一个参数维度中的哪个位置挑选数据,类型为torch.Tensor类的实例: 刚开始学习pytorch,遇到了index_select(),一开始不太明白几个参数的意思,后来查了一下资料,算是明白了一点. a = torch.linspace(1, 12, steps=12).view(3, 4) print(a) b = torch.index_selec

  • pytorch方法测试——激活函数(ReLU)详解

    测试代码: import torch import torch.nn as nn #inplace为True,将会改变输入的数据 ,否则不会改变原输入,只会产生新的输出 m = nn.ReLU(inplace=True) input = torch.randn(7) print("输入处理前图片:") print(input) output = m(input) print("ReLU输出:") print(output) print("输出的尺度:&qu

随机推荐