线性层的作用,类似于这边荧光绿的两层,就是fully connected layer

将1*1*4096的向量,变成1*1*1000的向量

  • 代码示例
import torch
import torchvision
from torch import nn
from torch.nn import Linear
from torch.utils.data import DataLoaderclass Module(nn.Module):def __init__(self):super().__init__()self.linear = Linear(196608,10)def forward(self, input):output = self.linear(input)return outputtest_data = torchvision.datasets.CIFAR10('dataset',train=False,transform=torchvision.transforms.ToTensor(),download=True)
# drop_last (bool, optional) – set to True to drop the last incomplete batch, if the dataset size is not divisible by the batch size.
# If False and the size of dataset is not divisible by the batch size, then the last batch will be smaller. (default: False)
# drop_last可以把最后不足64张图的batch补足
data_loader = DataLoader(test_data,batch_size=64,drop_last=True)module = Module()
for data in data_loader:images ,target =data# print(images.shape)output = torch.reshape(images,(1,1,1,-1))print(output.shape)output=module(output)print(output.shape)

  1. 另外,将向量展开成一行有一个特殊的函数:torch.flatten()

 output = torch.flatten(images)

LinearLayer相关推荐

  1. attention seq2seq transformer bert 学习总结 _20201107

    https://blog.csdn.net/weixin_44388679/article/details/102575223 Seq2Seq原理详解 一文读懂BERT(原理篇) 2018年的10月1 ...

  2. 10分钟带你深入理解Transformer原理及实现

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|深度学习这件小事 基于 Transformer<A ...

  3. Android 5.0学习之ListView升级版RecyclerView

     前言 大家都知道ListView在我们开发中很常用,Android5.0的到来,它给我们带来了一个替代 ListView的新的控件,也可以说是ListView的升级版,那就是RecyclerVi ...

  4. RecyclerView的那点事儿

    RecyclerView 控件简介 ListView的升级版 LinearLayoutManager GridLayoutManager StaggeredGridLayoutManager 定制It ...

  5. Matlab神经网络十讲(7): Adaptive Filter and Adaptive Training

    1. Adaptive Function The function adapt can change the weight and bias of a network incrementally du ...

  6. Matlab神经网络十讲(2): Create Configuration Train NeuralNet

    1. Create Neural Network Object The easiest way to create a neural network is to use one of the netw ...

  7. 【机器学习基础】使用python实现BP算法

    用pytorch跟tensorflow实现神经网络固然爽.但是想要深入学习神经网络,光学会调包是不够的,还是得亲自动手去实现一个神经网络,才能更好去理解. 一.问题介绍 传说中线性分类器无法解决的异或 ...

  8. java版本lstm_LSTM java 实现

    由于实验室事情缘故,需要将Python写的神经网络转成Java版本的,但是python中的numpy等啥包也不知道在Java里面对应的是什么工具,所以索性直接寻找一个现成可用的Java神经网络框架,于 ...

  9. 《Pytorch - 逻辑回归模型》

    2020年10月4号,依然在家学习. 今天是我写的第二个 Pytorch程序,从今天起也算是入门了. 这里是简单的实现了逻辑回归开始. 回顾线性回归,线性模型如下 y = wx + b,图画的丑了,意 ...

最新文章

  1. Apache发布Groovy 2.5正式版及3.0预览版
  2. [原]Failed to load SELinux policy. System Freezing ----redhat7or CentOS7 bug
  3. 内核中的UDP socket流程(2)——API “sys_socket”
  4. 最近使用SIFT匹配,尝试了一下从大图片中提取小图片的方法,不怎么好使
  5. 官网拉取fuchsia代码
  6. 2013计算机视觉代码合集一
  7. PHP 入门 - 9.安全
  8. fscanf不读取_思考了一天,终于把matlab的fscanf中的sizeA搞清楚了
  9. 服务器维护通宵,20150405晚上凌晨通宵进行服务器系统维护
  10. An impassioned circulation of affection(尺取+预处理)
  11. Python机器学习 集成算法实例
  12. linux中docker容器与宿主系统之间文件拷贝
  13. 安装apache重启的时候,报错端口被占用,错误1
  14. 深度学习图像分类(十三):ShuffleNet系列(V1,V2)
  15. 幻想影院添加html渲染,幻想影院无毒版-幻想影院清爽版预约 _5577安卓网
  16. 六、瞰景Smart3D三维重建
  17. 移动端(一)—— 移动端概念
  18. 病案编码员需要计算机的什么知识,病案编码员要怎么学习?
  19. Java程序员未来的三大就业方向
  20. 十年Java架构师分享

热门文章

  1. JavaScript循环语句
  2. 小米“追”华为“避”,电视开机广告是门好生意吗?
  3. go语言实现服务器与微信公众平台对接
  4. IDEA 学生无需破解免费申请(可用学生证和教育邮箱申请)
  5. 借助BetterZip自制压缩包测试小程序
  6. 对于敏捷晨会的一些思考
  7. c语言 字符映射表,字符集编码与 C/C++ 源文件字符编译乱弹(收集转载)
  8. 【转】CPU个数,核心数,线程数
  9. 苹果第二财季净利降16% 大中华区营收下滑21.5%
  10. vs全局搜索快捷键搜索失效