Q1:def train() 中的model.train()的作用是什么?为什么要写?

A1:class torch.nn.Module中 train(mode=True)

  Sets the module in training mode. This has any effect only on modules such as Dropout or BatchNorm.

  参看 http://pytorch.org/docs/master/nn.html

Q2:torch.gather()函数的功能是什么?

 t = torch.Tensor([[1, 2], [3, 4]])
print(t)
a = torch.gather(t, 1, torch.LongTensor([[0,0], [1,0]]))
print(a)
'''
1 2
3 4
[torch.FloatTensor of size 2x2] 1 1
4 3
[torch.FloatTensor of size 2x2]
'''

A2:

out[i][j][k] = input[index[i][j][k]][j][k]    # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k]    # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]]    # if dim == 2

out[i][j] = input[index[i][j]][j]
out[i][j] = input[i][index[i][j]]

out[0][0] = input[0][index[0][0]] = input[0][0] = 1
out[0][1] = input[0][index[0][1]] = input[0][0] = 1
out[1][0] = input[1][index[1][0]] = input[1][1] = 4

out[1][1] = input[1][index[1][1]] = input[1][0] = 3

Q3:torch.norm() 函数的功能是什么?

 a = torch.FloatTensor([[1, 2], [3, 4]])
b = torch.norm(a)
print(a)
print(b)
'''
1 2
3 4
[torch.FloatTensor of size 2x2] 5.477225575051661
'''

A3:

norm() 函数是求范数,一般默认是2范数。平方和开根号。

参考博文:几种范数的简单介绍

normal() 函数是求正太分布。

Q4: topk()函数

  • torch.Tensor.topk (Python method, in torch.Tensor) ||topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
  • torch.topk (Python function, in torch) ||torch.topk(input, k, dim=None, largest=True, sorted=True, out=None) -> (Tensor, LongTensor)
1 topi = torch.LongTensor([5])        # [torch.LongTensor of size 1]
2 topii = torch.LongTensor([[5]]) # [torch.LongTensor of size 1x1]
3 ni = topi[0]
4 nii = topii[0][0]
5 print(ni, nii) # 5 5

Q5:

 loss = Variable(torch.FloatTensor([1]))
print(loss.data) # 1 [torch.FloatTensor of size 1]
print(loss.data[0]) # 1.0

PyTorch学习问题记录的更多相关文章

  1. Pytorch学习记录-torchtext和Pytorch的实例( 使用神经网络训练Seq2Seq代码)

    Pytorch学习记录-torchtext和Pytorch的实例1 0. PyTorch Seq2Seq项目介绍 1. 使用神经网络训练Seq2Seq 1.1 简介,对论文中公式的解读 1.2 数据预 ...

  2. 【深度学习】Pytorch学习基础

    目录 pytorch学习 numpy & Torch Variable 激励函数 回归 区分类型 快速搭建法 模型的保存与提取 批训练 加速神经网络训练 Optimizer优化器 CNN MN ...

  3. 新手必备 | 史上最全的PyTorch学习资源汇总

    目录: PyTorch学习教程.手册 PyTorch视频教程 PyTorch项目资源      - NLP&PyTorch实战      - CV&PyTorch实战 PyTorch论 ...

  4. [深度学习] Pytorch学习(一)—— torch tensor

    [深度学习] Pytorch学习(一)-- torch tensor 学习笔记 . 记录 分享 . 学习的代码环境:python3.6 torch1.3 vscode+jupyter扩展 #%% im ...

  5. Activiti 学习笔记记录(2016-8-31)

    上一篇:Activiti 学习笔记记录(二) 导读:上一篇学习了bpmn 画图的常用图形标记.那如何用它们组成一个可用文件呢? 我们知道 bpmn 其实是一个xml 文件

  6. Activiti 学习笔记记录(二)

    上一篇:Activiti 学习笔记记录 导读:对于工作流引擎的使用,我们都知道,需要一个业务事件,比如请假,它会去走一个流程(提交申请->领导审批---(批,不批)---->结束),Act ...

  7. PostgresSQL 学习资料记录处

    PostgresSQL 学习资料记录处  博客:http://francs3.blog.163.com PostgreSQL9.4 中文手册:http://www.postgres.cn/docs/9 ...

  8. Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

  9. Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

随机推荐

  1. Python并发编程之多进程(实战)

    一.multiprocessing和Process multiprocessing提供了支持子进程.通信和数据共享.执行不同形式的同步,提供了Process.Queue.Pipe.Lock等组件 创建 ...

  2. IDEA常用快捷键(不全)

    这里使用的是默认的idea快捷键,如果修改了keymap为其他,那么不适用. 1.格式化代码:Ctrl+Alt+L(可能与QQ的冲突,建议QQ只保留方便的截图,皮) 2.在当前行最后添加分号,或自动补 ...

  3. LeetCode(155) Min Stack

    题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ...

  4. phpMyAdmin关于PHP 5.5+ is required. Currently installed version is: 5.4.16问题

    出现这个提示PHP 5.5+ is required. Currently installed version is: 5.4.16原因可能是: phpmyadmin 版本太新,最小需要php5.5. ...

  5. Linux学习-灾难复原的考虑

    硬件损毁,且具有完整备份的数据时 由于是硬件损毁,所以我们不需要考虑系统软件的不稳定问题,所以可以直接将完整的系统复原回去 即可. 由于软件的问题产生的被攻破资安事件 由于系统的损毁是因为被攻击,此时 ...

  6. Linux学习-软件磁盘阵列 (Software RAID)

    什么是 RAID 磁盘阵列全名是『 Redundant Arrays of Inexpensive Disks, RAID 』,英翻中的意思是:容错式廉价磁盘阵列.RAID 可以透过一个技术(软件或硬 ...

  7. TextView设置缩略显示

    1.代码设置 textview.setSingleLine(); textview.setEllipsiz(TextUtils.TruncateAt.valueOf("END")) ...

  8. Githun&HEXO建站小记

    title: 建站小记 date: 2018-03-04 11:10:54 updated: 2018-03-06 12:00:00 tags: [hexo,next,建站,学习,前端技术,折腾,博客 ...

  9. 哪里是Maven的中央存储库?

    当你建立了一个Maven工程,Maven会检查你的pom.xml文件,确定要下载的依赖.首先,Maven将从您的本地库Maven查找,如果没有找到,Maven会从中央存储库-http://repo1. ...

  10. 大数据学习——sparkSql对接hive

    1.   安装mysql 2.   上传.解压.重命名 2.1.  上传 在随便一台有hadoop环境的机器上上传安装文件 su - hadoop rz –y 2.2.  解压 解压缩:apache- ...