torch.nn.functional
1. 非线性激活函数
- torch.nn.functional.threshold(input, threshold, value, inplace=False)
- torch.nn.functional.relu(input, inplace=False)
- torch.nn.functional.relu6(input, inplace=False)
- torch.nn.functional.elu(input, alpha=1.0, inplace=False)
- torch.nn.functional.leaky_relu(input, negative_slope=0.01, inplace=False)
- torch.nn.functional.prelu(input, weight)
- torch.nn.functional.rrelu(input, lower=0.125, upper=0.3333333333333333, training=False, inplace=False)
- torch.nn.functional.logsigmoid(input)
- torch.nn.functional.softmax(input)
- torch.nn.functional.log_softmax(input)
- torch.nn.functional.tanh(input)
- torch.nn.functional.sigmoid(input)
2. 填充和放缩
torch.nn.functional.pad(input, pad, mode=‘constant’, value=0)
对数据集图像或中间层特征进行维度扩充。
参数:
- input:需要扩充的tensor,可以是图像数据,抑或是特征矩阵数据
- pad:扩充维度
- mod:扩充方法,’constant‘, ‘reflect’ or ‘replicate’三种模式,分别表示常量,反射,复制
- value:扩充时指定补充值,但是value只在mode='constant’有效,即使用value填充在扩充出的新维度位置,而在’reflect’和’replicate’模式下,value不可赋值
import torch
import torch.nn.functional as Ft4d = torch.empty(1, 3, 5, 3)p1d_ = (1, 2, 0, 0)
t1 = F.pad(t4d, p1d_, 'constant', 1) # 对图像的左边填充1列,右边填充2列p2d = (1, 2, 3, 4)
t2 = F.pad(t4d, p2d, 'constant', 2) # 对图像的左边填充1列,右边填充2列,上边填充3行,下边填充4行p3d = (1, 2, 3, 4, 5, 6)
t3 = F.pad(t4d, p3d, 'constant', 3) # 对图像的左边填充1列,右边填充2列,上边填充3行,下边填充4行,对通道方向的前面填充5层,对通道方向的后面填充6层。
torch.nn.functional.interpolate(input, size=None, scale_factor=None, mode=‘nearest’, align_corners=None, recompute_scale_factor=None, antialias=False) -> Tensor
torch.nn.functional.upsample(input, size=None, scale_factor=None, mode=‘nearest’, align_corners=None)
3. 网格采样
torch.meshgrid(*tensors, indexing=None)
创建由 tensors 中的一维输入
指定的坐标网格。
torch.nn.functional.grid_sample(input, grid, mode=‘bilinear’, padding_mode=‘zeros’, align_corners=None)
给定输入和网格,使用输入值和网格中的像素位置计算输出。目前,仅支持空间 (4-D) 和体积 (5-D) 输入。
此函数通常与 affine_grid()
结合使用来构建Spatial Transformer Networks
。
注意:girid 指定由输入空间维度
归一化
的采样像素位置。 因此,它应该具有 [-1, 1] 范围内的大多数值。 例如,值 x = -1, y = -1 是输入的左上角像素,值 x = 1, y = 1 是输入的右下角像素。
torch.nn.functional.affine_grid(theta, size, align_corners=None)
给定一批仿射矩阵 theta
,生成 2D 或 3D 采样网格。
此函数通常与 grid_sample()
结合使用来构建Spatial Transformer Networks
。
例子请移步:Pytorch中的仿射变换(affine_grid)
torch.nn.functional相关推荐
- torch.nn.functional.cross_entropy.ignore_index
ignore_index表示计算交叉熵时,自动忽略的标签值,example: import torch import torch.nn.functional as F pred = [] pred.a ...
- 【pytorch】torch.nn.functional.pad的使用
torch.nn.functional.pad 是对Tensor做padding,输入的参数必须的torch的Tensor 一般地,习惯上会做如下声明 import torch.nn.function ...
- torch.nn.functional.pad
作用 用来对一个tensor进行填充.最典型的就是图片了,原来是2*2的,现在想要变成3*3的,那么就需要填充,此时有很多选择,例如是在原来的右上进行填充还是左下?又或者是左上?等等. 这个函数就可以 ...
- PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx
PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx 在写 PyTorch 代码时,我们会发现在 torch.nn.xxx 和 torch.nn.funct ...
- pytorch笔记:torch.nn.functional.pad
1 torch.nn.functional.pad函数 torch.nn.functional.pad是pytorch内置的tensor扩充函数,便于对数据集图像或中间层特征进行维度扩充 torch. ...
- torch.nn.functional.pad(input, pad, mode=‘constant‘, value=0)
torch.nn.functional.pad(input, pad, mode='constant', value=0) 填充Tensor. 填充大小: 填充input的某些维度的填充大小从最后一个 ...
- 剖析 | torch.nn.functional.softmax维度详解
写代码,看代码都要心中有数,输入是什么,输出是什么,结果是如何计算出来的. 一维数据: # -*- coding: utf-8 -*- import torch import numpy as np ...
- 基于torch.nn.functional.conv2d实现CNN
在我们之前的实验中,我们一直用torch.nn.Conv2D来实现卷积神经网络,但是torch.nn.Conv2D在实现中是以torch.nn.functional.conv2d为基础的,这两者的区别 ...
- PyTorch 1.0 中文文档:torch.nn.functional
译者:hijkzzz 卷积函数 conv1d torch.nn.functional.conv1d(input, weight, bias=None, stride=1, padding=0, dil ...
- pytorch: torch.nn.functional.affine_grid(theta,size)
# 仍有部分疑惑 torch.nn.functional.affine_grid(theta,size): 给定一组仿射矩阵(theta),生成一个2d的流场.通常与 grid_sample() 结 ...
最新文章
- LeetCode实战:逆波兰表达式求值
- 水稻微生物组时间序列分析4-随机森林回归
- linux一个进程通知另外一个进程,Linux进程通信学习笔记
- Multi-band Blending
- Web 静态文件版本升级代码
- linux系统下的grep命令功能与正则表达式详解
- ide硬盘接口图 sata硬盘接口图 SCSI硬盘接口图
- mutex的加锁与解锁问题
- javafx中css选择器_JavaFX技巧12:在CSS中定义图标
- ftp put 550 Access is denied
- python按照时间timestramp切分网络前向流与后向流
- all方法 手写promise_我团队的一年前端实现Promise所有方法
- UI设计灵感|手机钱包App怎样设计才更便捷?
- Android Studio 3.1无法导入模块的解决办法
- Java线程池(ThreadPool)详解
- Unity3D 下载与安装
- 【计算机网络】TCP协议详解
- 《算法艺术与信息学竞赛》之 递推 例一 月亮之眼 vijos 1540
- 广义根轨迹 matlab,根轨迹心得体会
- 完美解决 iOS 中只旋转自己想要旋转的屏幕