当前位置:网站首页>【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应用极其广泛,你是否完全了解掌握了其用法呢?
边栏推荐
- 新库上线| CnOpenDataA股上市公司股东信息数据
- BOM overview
- Kubernates-1.24.2 (latest version) + containerd + nexus
- Default value of dart variable
- DJI内推码(一码一用,限时内推)
- Decrypting numpy is a key difficulty in solving the gradient
- Paper reading: UNET 3+: a full-scale connected UNET for medical image segmentation
- Summary of learning notes of deep learning application development (II)
- The idea of the regular crawler of the scratch
- Electronic Association C language level 2 60, integer parity sort (real question in June 2021)
猜你喜欢

Million level element optimization: real-time vector tile service based on PG and PostGIS

New tea, start "fighting in groups"

9 best engineering construction project management systems

With apple not making money, the 2trillion "fruit chain" abandons "fruit" and embraces "special"

Can interface debugging still play like this?

2022 Tiangong cup ctf--- crypto1 WP

Security compliance, non-stop discounts! High quality travel service, "enjoy the road" for you

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

Summary of differences between data submission type request payload and form data

File operation-
随机推荐
First, how about qifujin
阿里云镜像地址&网易云镜像
3. Promise
微信小程序wx.request接口
[notes for question brushing] search the insertion position (flexible use of dichotomy)
When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
Price reduction, game, bitterness, etc., vc/pe rushed to queue up and quit in 2022
Devops has been practiced for many years. What is the most painful thing?
Ask the bosses: MySQL CDC stores configuration data, and Kafka has history
Robot Framework移动端自动化测试----01环境安装
Ideal L9, can't cross a pit on the road?
How to use network installation to deploy multiple virtual servers in KVM environment
【刷题笔记】搜索旋转排序数组
New tea, start "fighting in groups"
做好项目管理的10个关键点和5大措施
Scavenging vultures or woodpeckers? How to correctly understand short selling
What are the types of financial products in 2022? Which is suitable for beginners?
Openatom xuprechain open source biweekly report | 2022.7.11-2022.7.22
[OBS] DTS sent by video packet_ USEC calculation
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)