当前位置:网站首页>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
边栏推荐
- Maximum exchange [greedy thought & monotonic stack implementation]
- Using typedef in C language to change the name of data type
- 【实验分享】CCIE—BGP反射器实验
- Simple example of C language 1
- Raspberrypico serial communication
- The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
- WPF--实现WebSocket服务端
- Using Lex (Flex) to generate lexical analyzer of PL language
- ssm中项目异常处理
- 读取json配置文件,实现数据驱动测试
猜你喜欢
![[C language] random number generation and `include < time. H > 'learning](/img/bb/3e47bf2e3b25653d9048884d65cda3.png)
[C language] random number generation and `include < time. H > 'learning

Can China make a breakthrough in the future development of the meta universe and occupy the highland?

弹出模态框

A chip company fell in round B

C语言简单实例 1

Solve the cookie splitting problem (DP)

JVM(二十四) -- 性能监控与调优(五) -- 分析GC日志

Durham High Lord (classic DP)

3、 Are formal and actual parameters in a programming language variables?
![最大交换[贪心思想&单调栈实现]](/img/ad/8f0914f23648f37e1d1ce69086fd2e.png)
最大交换[贪心思想&单调栈实现]
随机推荐
[C language] guessing numbers game
Solve the kangaroo crossing problem (DP)
MySQL command statement (personal summary)
C language - data type
Solve flask integration_ Error reporting in restplus
mmo及时战斗游戏中的场景线程分配
NEIL: Extracting Visual Knowledge from Web Data
[C language] Fibonacci sequence [recursion and iteration]
C language - data storage
Raspberry pie 4B parsing PWM
6. Functions of C language, why functions are needed, how functions are defined, and the classification of functions
2、 Relationship between software operation and memory
Scene thread allocation in MMO real-time combat games
zfoo增加类似于mydog的路由
[C language] use function pointers to make a different calculator
[C language] step jumping problem [recursion]
[C language] header file of complex number four operations and complex number operations
XOR operation and its usage
C language implementation of strncpy
C语言数据 3(2)