关于该类:

torch.nn.Linear(in_features, out_features, bias=True)

可以对输入数据进行线性变换:

$y  = x A^T + b$

in_features: 输入数据的大小。

out_features: 输出数据的大小。

bias: 是否添加一个可学习的 bias,即上式中的 $b$。

该线性变换,只对输入的 tensor 的最后一维进行:

例如我们有一个Linear层如下:

m = nn.Linear(20, 30)

示例1:

input = torch.randn(2, 5, 8, 20)
output = m(input)
print(output.size())

结果:

torch.Size([2, 5, 8, 30])

示例2:

input = torch.randn(20)
output = m(input)
print(output.size())

结果:

torch.Size([30])

关于torch.nn.Linear的笔记的更多相关文章

  1. torch.nn.Linear()函数的理解

    import torch x = torch.randn(128, 20) # 输入的维度是(128,20)m = torch.nn.Linear(20, 30) # 20,30是指维度output ...

  2. 小白学习之pytorch框架(3)-模型训练三要素+torch.nn.Linear()

    模型训练的三要素:数据处理.损失函数.优化算法    数据处理(模块torch.utils.data) 从线性回归的的简洁实现-初始化模型参数(模块torch.nn.init)开始 from torc ...

  3. 关于torch.nn.Conv2d的笔记

    先看一下CLASS有哪些参数: torch.nn.Conv2d( in_channels, out_channels, kernel_size, stride=1, padding=0, dilati ...

  4. PyTorch官方中文文档:torch.nn

    torch.nn Parameters class torch.nn.Parameter() 艾伯特(http://www.aibbt.com/)国内第一家人工智能门户,微信公众号:aibbtcom ...

  5. [转载]Pytorch中nn.Linear module的理解

    [转载]Pytorch中nn.Linear module的理解 本文转载并援引全文纯粹是为了构建和分类自己的知识,方便自己未来的查找,没啥其他意思. 这个模块要实现的公式是:y=xAT+*b 来源:h ...

  6. PyTorch里面的torch.nn.Parameter()

    在刷官方Tutorial的时候发现了一个用法self.v = torch.nn.Parameter(torch.FloatTensor(hidden_size)),看了官方教程里面的解释也是云里雾里, ...

  7. pytorch函数之nn.Linear

    class torch.nn.Linear(in_features,out_features,bias = True )[来源] 对传入数据应用线性变换:y = A x+ b 参数: in_featu ...

  8. [pytorch笔记] torch.nn vs torch.nn.functional; model.eval() vs torch.no_grad(); nn.Sequential() vs nn.moduleList

    1. torch.nn与torch.nn.functional之间的区别和联系 https://blog.csdn.net/GZHermit/article/details/78730856 nn和n ...

  9. PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx

    PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx 在写 PyTorch 代码时,我们会发现一些功能重复的操作,比如卷积.激活.池化等操作.这些操作分别可 ...

随机推荐

  1. redis长篇介绍

    一. 简介 Redis 完全开源免费,遵守BSD协议,高性能的(NOSQL) key-value数据库 BSD 伯克利软件发行版 缓存数据集 所以都在内存上面 Redis 数据类型分为:字符串类型.散 ...

  2. Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)

    最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...

  3. hdu 3549 Flow Problem 最大流问题 (模板题)

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  4. 洛谷 P2634 聪聪可可

    题目描述 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好了,可是他们已 ...

  5. Day7 - G - Divisors POJ - 2992

    Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- or do you n ...

  6. SpringMVC 文件的上传、下载

    文件上传 (1)下载添加2个jar包 commons-fileupload.jar commons-io.jar SpringMVC的文件上传依赖于Apache的FileUpload组件,需要下载添加 ...

  7. 认识json,详解JsonConfig

    说到json 初学者很迷茫,不知json怎么为何物,以及怎么用.我简单说下我的了解 既然用了json 我们就要知其然也知其所以然.下面有几个疑问 1.为什么要用json?也就是json 的优势 2.我 ...

  8. leetcode1019 Next Greater Node In Linked List

    """ We are given a linked list with head as the first node. Let's number the nodes in ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-trash

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  10. ACM-生化武器

    Description在一个封闭的房间里,gogo给大家表演了他的屁遁术,人果然一下没影了,但是他留下的“生化武器”,却以每秒1米的速度向上下左右扩散出去.为了知道自己会不会被“毒”到,你果断写了个算 ...