当前位置:网站首页>[pytorch] the most common function of view
[pytorch] the most common function of view
2022-07-25 07:21:00 【Beauty of algorithm and programming】
problem
PyTorch Programming , Everywhere view, What does it mean ?
Method
view The core function of is to refactor Tensor Of size, The case is as follows :
import torch
# view The function of is reconstruction tensor Of 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())
When we want to be lazy , When you don't want to calculate one of the dimensions , It can be used -1 Instead of , Be careful , Only lazy here 1 Dimensions .
The practical application
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
Conclusion
view It is widely used , Do you fully understand and master its usage ?
边栏推荐
- QT6 with vs Code: compiling source code and basic configuration
- Devops has been practiced for many years. What is the most painful thing?
- Hierarchical reinforcement learning: a comprehensive survey
- [notes] search rotation sort array
- 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)
- Decrypting numpy is a key difficulty in solving the gradient
- Servlet常用类剖析
- Learn when playing No 7 | don't study this holiday, study only
- 曼哈顿距离简介
- 2022天工杯CTF---crypto1 wp
猜你喜欢

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

Day by day, month by month | Shenzhen potential technology released the extreme accelerated version of molecular docking engine uni docking

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

OpenAtom XuperChain 开源双周报 |2022.7.11-2022.7.22

BOM overview

leetcode刷题:动态规划06(整数拆分)
![[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!](/img/11/24f92b4362026ec2c01492d195560b.png)
[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!

Openatom xuprechain open source biweekly report | 2022.7.11-2022.7.22

PADS导出gerber文件

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)
随机推荐
Bingbing's learning notes: classes and objects (Part 1)
Boiling short drama Jianghu: nine of the ten production teams are shooting, with a head sharing fund of more than 30million, and users are addicted to paying routines
Can interface debugging still play like this?
【程序员2公务员】三、资源搜集
一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking
Learn when playing No 7 | don't study this holiday, study only
Pads export Gerber file
【刷题笔记】搜索旋转排序数组
vulnhub CyberSploit: 1
Leave the factory and sell insurance
Servlet常用类剖析
各位老板 问一下 就是我们mysql cdc保存的是配置数据 然后kafka里面堆积的有历史
QT学习日记20——飞机大战项目
DJI push code (one code for one use, limited time push)
【SemiDrive源码分析】【驱动BringUp】39 - Touch Panel 触摸屏调试
Rust standard library - implement a TCP service, and rust uses sockets
Vscode saves setting configuration parameters to the difference between users and workspaces
【程序员2公务员】关于体制调研的一些常见问题总结
SAP queries open Po (open purchase order)
RPC communication principle and project technology selection