当前位置:网站首页>Torch. NN. Linear() function
Torch. NN. Linear() function
2022-07-28 20:21:00 【LifeBackwards】
torch.nn.
Linear
(in_features, out_features, bias=True) Function is a linear transformation function :
among ,in_features Enter the sample size for ,out_features Is the size of the output sample ,bias The default is true. If you set bias = false Then this layer will not learn an additive bias .
Linear()
Function is usually used to set the Fully connected layer .
Use cases :
import torch
x = torch.randn(128, 20) # The input samples
fc = torch.nn.Linear(20, 30) # 20 Enter the sample size for ,30 Is the output sample size
output = fc(x)
print('fc.weight.shape:\n ', fc.weight.shape)
print('fc.bias.shape:\n', fc.bias.shape)
print('output.shape:\n', output.shape)
ans = torch.mm(x,torch.t(fc.weight))+fc.bias # The results are in agreement with fc(x) identical
print('ans.shape:\n', ans.shape)
print(torch.equal(ans, output))
Running results :
m.weight.shape:
torch.Size([30, 20])
m.bias.shape:
torch.Size([30])
output.shape:
torch.Size([128, 30])
ans.shape:
torch.Size([128, 30])
true
边栏推荐
- Related concepts of multitasking programming
- Sequential linear table - practice in class
- Scene thread allocation in MMO real-time combat games
- flask_ Mail source code error
- [C language] Hanoi Tower problem [recursion]
- What is the process of swing event processing?
- How to automatically store email attachments in SharePoint
- Rand function generates pseudo-random numbers
- 七种轮询介绍(后附实践链接)
- The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
猜你喜欢
How can Plato obtain premium income through elephant swap in a bear market?
Windows系统下Mysql数据库定时备份
WFST decoding process
Handan, Hebei: expand grassroots employment space and help college graduates obtain employment
CM4 development cross compilation tool chain production
为什么客户支持对SaaS公司很重要?
Solve the cookie splitting problem (DP)
七种轮询介绍(后附实践链接)
5. Difference between break and continue (easy to understand version)
Raspberrypico serial communication
随机推荐
Solve the cookie splitting problem (DP)
有哪个老哥知道flinksql 日志很大要怎么解决吗
[C language] Hanoi Tower problem [recursion]
robobrowser的简单使用
[C language] use function pointers to make a different calculator
Multi-Modal Knowledge Graph Construction and Application: A Survey
树行表达方式
Item exception handling in SSM
Durham High Lord (classic DP)
C语言数据 3(1)
Implementation of memmove in C language
一文让你搞懂什么是TypeScript
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
Zfoo adds routes similar to mydog
CM4 development cross compilation tool chain production
Raspberry pie 3b ffmpeg RTMP streaming
七种轮询介绍(后附实践链接)
Simple example of C language 1
Longest Palindromic Substring
Basic knowledge of communication network 01