PyTorch学习问题记录
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学习问题记录的更多相关文章
- Pytorch学习记录-torchtext和Pytorch的实例( 使用神经网络训练Seq2Seq代码)
Pytorch学习记录-torchtext和Pytorch的实例1 0. PyTorch Seq2Seq项目介绍 1. 使用神经网络训练Seq2Seq 1.1 简介,对论文中公式的解读 1.2 数据预 ...
- 【深度学习】Pytorch学习基础
目录 pytorch学习 numpy & Torch Variable 激励函数 回归 区分类型 快速搭建法 模型的保存与提取 批训练 加速神经网络训练 Optimizer优化器 CNN MN ...
- 新手必备 | 史上最全的PyTorch学习资源汇总
目录: PyTorch学习教程.手册 PyTorch视频教程 PyTorch项目资源 - NLP&PyTorch实战 - CV&PyTorch实战 PyTorch论 ...
- [深度学习] Pytorch学习(一)—— torch tensor
[深度学习] Pytorch学习(一)-- torch tensor 学习笔记 . 记录 分享 . 学习的代码环境:python3.6 torch1.3 vscode+jupyter扩展 #%% im ...
- Activiti 学习笔记记录(2016-8-31)
上一篇:Activiti 学习笔记记录(二) 导读:上一篇学习了bpmn 画图的常用图形标记.那如何用它们组成一个可用文件呢? 我们知道 bpmn 其实是一个xml 文件
- Activiti 学习笔记记录(二)
上一篇:Activiti 学习笔记记录 导读:对于工作流引擎的使用,我们都知道,需要一个业务事件,比如请假,它会去走一个流程(提交申请->领导审批---(批,不批)---->结束),Act ...
- PostgresSQL 学习资料记录处
PostgresSQL 学习资料记录处 博客:http://francs3.blog.163.com PostgreSQL9.4 中文手册:http://www.postgres.cn/docs/9 ...
- Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...
- Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...
随机推荐
- LeetCode(268) Missing Number
题目 Given an array containing n distinct numbers taken from 0, 1, 2, -, n, find the one that is missi ...
- Django 二——models(admin、ORM),一对一、一对多、多对多操作,all、values、value_list的对比
内容概要 1.关系对象映射ORM 2.admin的配置(选修) 3.all().values().value_list()的对比 4.数据库操作(一对一.一对多.多对多) 5.HttpResponse ...
- python - 接口自动化 - 接口测试基础知识
# -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_接口测试基础知识一.py@ide: PyCharm Commun ...
- Python中__get__ ,__getattr__ ,__getattribute__用法与区别?
class C(object): a = 'abc' def __getattribute__(self, *args, **kwargs): print("__getattribute__ ...
- 后台线程读取指定的web.config
//读取配置文件,订单地址修改接口地址 ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.Exe ...
- Welcome-to-Swift-24高级运算符(Advanced Operators)
除了基本操作符中所讲的运算符,Swift还有许多复杂的高级运算符,包括了C语和Objective-C中的位运算符和移位运算. 不同于C语言中的数值计算,Swift的数值计算默认是不可溢出的.溢出行为会 ...
- 二进制<2>
位运算简介及实用技巧(二):进阶篇(1) ===== 真正强的东西来了! ===== 二进制中的1有奇数个还是偶数个 我们可以用下面的代码来计算一个32位整数的二进制中1的个数的奇偶性, ...
- hdoj--2082<母函数>
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=2082题目描述:26个字母各有价值,分别是1到26:给出每个字母的个数,求单词价值不超过50 的单词 ...
- 网抓(XML Http Request、VBA)实现
第一种,先看VBA Public Function GetInfo(strMoblie As String) As String '创建对象 Dim xmlHttp As Object Set xml ...
- CF911F Tree Destruction (树的直径,贪心)
题目链接 Solution 1.先找出树的直径. 2.遍历直径沿途的每一个节点以及它的子树. 3.然后对于每个非直径节点直接统计答案,令直径的两个端点为 \(x_1,x_2\) . \[Ans=\su ...