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. ogre3D学习基础6---场景管理器的使用

    场景管理器的使用 最常使用的坐标系统空间(同时也是Ogre程序所能提供的)即是世界空间(World).父节点空间(Parent)以及本地空间(Local). 1.世界空间 就是物体所存在的地方,当我们 ...

  2. Python socket粘包问题(初级解决办法)

    server端配置: import socket,subprocess,struct from socket import * server=socket(AF_INET,SOCK_STREAM) s ...

  3. git status 下中文显示乱码问题解决

      $ git status -s                 ?? "\350\257\264\346\230\216.txt\n                 $ printf & ...

  4. iOS学习笔记02-UIScrollView

    父类UIView方法 // autoresizingMask - 现在基本弃用,改用autoLayout typedef NS_OPTIONS(NSUInteger, UIViewAutoresizi ...

  5. Python之自动单元测试之一(unittest使用实例)

    软件的测试是一件非常乏味的事情,在测试别人编写的软件时尤其如此,程序员通常都只对编写代码感兴趣,而不喜欢文档编写和软件测试这类"没有创新"的工作.既然如此,为什么不让程序员在编写软 ...

  6. HDU——1073Online Judge(string类以及其对应函数)

    Online Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  7. [BZOJ2678][Usaco2012 Open]Bookshelf

    P.S. 偶然间发现可以用 markdown... [BZOJ2678][Usaco2012 Open]Bookshelf 试题描述 When Farmer John isn't milking co ...

  8. 刷题总结——维护数列(NOI2005 bzoj1500 splay)

    题目: 题目背景 NOI2005 DAY1 T2 题目描述 请写一个程序,要求维护一个数列,支持以下 6 种操作:(请注意,格式栏中的下划线‘_’表示实际输入文件中的空格)

  9. java面试题之wait(),notify()和suspend(),resume()之间的区别

    wait()方法和notify()方法的区别: 这两个方法都是属于Object类中的,也是配套使用的,当调用这两个方法阻塞时要释放占用的锁,而锁是任何对象都具有的,调用任意对象的wait()方法导致线 ...

  10. input标签不能设置height

    首先input是内联标签(inline) inline元素设置width.height属性无效 可以通过设置display:inline-block ,则内联标签可以设置width和height,但是 ...