当前位置:网站首页>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
边栏推荐
- Storage of C language data in memory (1)
- Raspberry pie uses the command line to configure WiFi connections
- LeetCode-297-二叉树的序列化与反序列化
- Commands related to obtaining administrator permissions
- 一碰撞就自燃,谁来关心电池安全?上汽通用有话说
- 一文让你搞懂什么是TypeScript
- Raspberry Pie 3 connected to WiFi
- Use of strtok and strError
- Common instructions of vim software
- 2. Floating point number, the difference between float and double in C language and how to choose them
猜你喜欢

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
![[C language] initial C language reflection and summary](/img/21/826d144867f7a73ec2cd8896a5250a.png)
[C language] initial C language reflection and summary

9. Pointer of C language (4) pointer and one-dimensional array, pointer operation

Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich

4. Const and difine and the problem of initializing arrays with const and define

Zfoo adds routes similar to mydog

Longest Palindromic Substring

Reverse string

Handan, Hebei: expand grassroots employment space and help college graduates obtain employment

【实验分享】CCIE—BGP反射器实验
随机推荐
C language data 3 (1)
The privatized instant messaging platform protects the security of enterprise mobile business
Implementation of memmove in C language
Longest Palindromic Substring
2、 Relationship between software operation and memory
4. Const and difine and the problem of initializing arrays with const and define
【实验分享】CCIE—BGP反射器实验
Merge sort template
C language - data storage
最大交换[贪心思想&单调栈实现]
6. Functions of C language, why functions are needed, how functions are defined, and the classification of functions
Zfoo adds routes similar to mydog
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
长轮询,iframe和sse三种web消息实时推送demo实践
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
字符设备驱动结构
Quick sort template
[C language] step jumping problem [recursion]
File lookup and file permissions
C语言简单实例 1