当前位置:网站首页>【PyTorch】最常见的view的作用
【PyTorch】最常见的view的作用
2022-07-25 07:19:00 【算法与编程之美】
问题
PyTorch编程中,随处可见的view,其含义是什么?
方法
view的核心作用是重构Tensor的size,案例如下:
import torch
# view的作用是重构tensor的size
a = torch.randn(100,)
print(a.size()) #torch.Size([100])
b = a.view(5, -1)
print(b.size()) # torch.Size([5, 20])
c = a.view(2, 5, -1) # torch.Size([2, 5, 10])
print(c.size())
当我们想偷懒,不想计算其中的一个维度时,可以用-1代替,注意,此处仅限偷懒1个维度。
实际应用
def forward(self, x):
x = self.feature(x)
x = nn.AvgPool2d(2)(x)
x = x.view(x.size(0), -1)
y = self.classifier(x)
return y
结语
view应用极其广泛,你是否完全了解掌握了其用法呢?
边栏推荐
- 2022 Tiangong cup ctf--- crypto1 WP
- Learn no when playing 9 | enterprise knowledge management is so simple because it uses
- Tp5.1 foreach adds a new field in the controller record, and there is no need to write all the other fields again without changing them (not operating in the template) (paging)
- Hierarchical reinforcement learning: a comprehensive survey
- List derivation
- When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
- [programmer 2 Civil Servant] IV. common problems
- Wechat applet request requests to carry cookies to verify whether it has logged in
- Dynamic memory management
- 《游戏机图鉴》:一份献给游戏玩家的回忆录
猜你喜欢

【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了

"Wei Lai Cup" 2022 Niuke summer multi school training camp 1 supplementary problem solution (incomplete)

BOM概述

一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking

CTF Crypto---RSA KCS1_ Oaep mode

新库上线| CnOpenDataA股上市公司股东信息数据

Ideal L9, can't cross a pit on the road?

QT actual combat case (53) -- using qdrag to realize the drag puzzle function

Beijing internal promotion | Microsoft STCA recruits nlp/ir/dl research interns (remote)

Wechat applet switchtab transmit parameters and receive parameters
随机推荐
批量导入数据,一直提示 “失败原因:SQL解析失败:解析文件失败::null”怎么回事?
scrapy定时爬虫的思路
3. Promise
CTF Crypto---RSA KCS1_ Oaep mode
Enable the free pan domain SSL certificate for kubesphere cluster and realize the automatic update and distribution of certificates
Scavenging vultures or woodpeckers? How to correctly understand short selling
Servlet常用类剖析
阿里云镜像地址&网易云镜像
RPC通信原理与项目技术选型
PADS导出gerber文件
【obs】视频包发送的dts_usec 计算
RPC communication principle and project technology selection
【电脑讲解】去电脑维修店修电脑需要注意什么?
NLP hotspots from ACL 2022 onsite experience
Leave the factory and sell insurance
【程序员2公务员】四、常见问题
Luo min's backwater battle in qudian
Wechat applet request requests to carry cookies to verify whether it has logged in
Decrypting numpy is a key difficulty in solving the gradient
List derivation