当前位置:网站首页>torch. nn. Linear() function
torch. nn. Linear() function
2022-06-12 20:57:00 【Human high quality Algorithm Engineer】
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 full connection layer in the network .
import torch
x = torch.randn(8, 3) # The input samples
fc = torch.nn.Linear(3, 5) # 20 Enter the sample size for ,30 Is the output sample size
output = fc(x)
print('fc.weight.shape:\n ', fc.weight.shape, fc.weight)
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))
The output is :
fc.weight.shape:
torch.Size([5, 3]) Parameter containing:
tensor([[-0.1878, -0.2082, 0.4506],
[ 0.3230, 0.3543, 0.3187],
[-0.0993, -0.0028, -0.1001],
[-0.0479, 0.3248, -0.4867],
[ 0.0574, 0.0451, 0.1525]], requires_grad=True)
fc.bias.shape:
torch.Size([5])
output.shape:
torch.Size([8, 5])
ans.shape:
torch.Size([8, 5])
True
Process finished with exit code 0
First ,nn.linear(3,5) Its weighted shape by (5,3), therefore x When multiplied by , use torch.t Please nn.linear The transpose , such (83)(35) Get the output dimension after the full connection layer (85), The results are also consistent with the results fc(x) Verification is consistent , torch.mm Just two matrices in mathematics Multiply .
reference :
https://blog.csdn.net/daodaipsrensheng/article/details/117259324
边栏推荐
- EditText控制从左上角开始
- new做了哪几件事
- Scala基础语法入门(三)Scala中的各种运算符
- New product release Junda intelligent integrated environmental monitoring terminal
- Circularly insert one excel column and the sum of multiple columns
- 做自媒体视频,友好的新媒体运营必备app分享
- Transaction code qs28 of SAP QM preliminary level
- To understand Devops, you must read these ten books!
- Market trend report, technical innovation and market forecast of hydraulic chain hoist in China
- 逐向双碳:东数西算中的绿色需求与竞争焦点
猜你喜欢

Lightroom 大使系列:用 Meg Loeks 捕捉怀旧之情

Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot
![Li Mu [practical machine learning] 1.4 data annotation](/img/e4/2593b1dec04476a9cc3b4af94dc189.jpg)
Li Mu [practical machine learning] 1.4 data annotation

Data visualization diagram microblog forwarding diagram

Nexus3 build local warehouse

Introduction to scala basic grammar (III) various operators in Scala
![[live streaming] understand the design of d3js and learn how to read the source code.](/img/31/53e2d267acda0f87bcef081f2ebc8b.jpg)
[live streaming] understand the design of d3js and learn how to read the source code.

Data visualization - histogram

Introduction to system mode development of rouya wechat mall

Composer version degradation
随机推荐
Detect current system language
Leetcode: 210. Programme II
Deploy etcd cluster in static pod mode
typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;
Lightroom 大使系列:用 Meg Loeks 捕捉怀旧之情
Data visualization - histogram
MySQL + PostgreSQL batch insert update insertorupdate
Halcon angle and radian interchange
Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
What did new do
入行5年从10k的功能测试到年薪40w的测试开发,花7天时间整理的超全学习路线
torch. Finfo function
Research Report on market supply and demand and strategy of China's hydraulic injection molding machine industry
EditText control starts from the upper left corner
Can flush open an account? Can you directly open the security of securities companies on the app? How to open an account online when buying stocks
How can CTCM in the inspection lot system status of SAP QM be eliminated?
Understanding of functions
Market trend report, technical innovation and market forecast of hydraulic chain hoist in China
EditText控制从左上角开始
New product release Junda intelligent integrated environmental monitoring terminal