当前位置:网站首页>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
边栏推荐
- EU officially released the data act, Ukraine was attacked by DDoS again, kitchen appliance giant Meiya was attacked, internal data leakage network security weekly
- HR SaaS unicorn is about to emerge. Will the employee experience be the next explosive point?
- How to improve communication efficiency during home office | community essay solicitation
- 多机房动环状态网络触摸屏监控解决方案
- Library cache lock brought by add trandata
- typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;
- Summary of machine learning materials
- Let Google browser fofa plug-in come alive
- EditText control starts from the upper left corner
- 做自媒体视频,友好的新媒体运营必备app分享
猜你喜欢

Listener in JSP

A Zhu and Xu Baobao's high-rise game - difference

Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring

JSP中的监听器

金融信创爆发年!袋鼠云数栈DTinsight全线产品通过信通院信创专项测试

竣达技术丨适用于“科士达”智能精密空调网络监控

Introduction to scala basic grammar (III) various operators in Scala

Event distribution mechanism of view

Scope and scope chain

shell语言
随机推荐
Summary of machine learning materials
Centos7 installing MySQL 5.7
[leetcode 7 solution] integer inversion
InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY EB3E94ADBE1229CF
Go -- monitor file changes
服务端口不通排查
Research Report on hydraulic solenoid valve industry - market status analysis and development prospect forecast
Data visualization - histogram
Data visualization - broken line area chart
Scala基础语法入门(三)Scala中的各种运算符
Allegro Xile technology, a developer of distributed cloud services, received millions of dollars of angel round financing and was independently invested by Yaotu capital
Lightroom 大使系列:用 Meg Loeks 捕捉怀旧之情
Introduction to scala basic grammar (III) various operators in Scala
跳槽前恶补面试题,金三成功上岸腾讯,拿到30k的测开offer
阿里前辈给我推荐的软件测试人员必读书籍(附电子书),让我受益匪浅...
没有学历,自学软件测试,找到一份月入过万的测试工作真的有可能吗?
MySQL field truncation principle and source code analysis
Unauthorized rce in VMware vCenter
JS中如何实现重载
JSON file handles object Tags