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
最新文章
- Ruby--学习记录(实时更新)
- [Doxygen]Doxygen
- hadoop rpc基础
- php上传$_FILES 无法取值
- WPF中多个RadioButton绑定到一个属性
- 入门Linux
- squid判断文件是否修改机制分析
- 三、freemarker数据、模版指令
- Migration from Zend Framework v2 to v3
- [HAOI2007]上升序列
- AIROBOT系统 之 私人存储 和 DLNA 智能电视云
- sort和uniq去重操作【转】
- c# 数据结构 ArrayList
- django补充和form组件
- wamp设置自定义域名访问php网站
- mysql创建utf8数据库
- Linux进程间通信(消息队列/信号量+共享内存)
- linux下mysql 启动命令
- SQL优化:清理生产环境中已失效字段基本步骤
- JavaScript实现的3D球面标签云效果