码迷,mamicode.com
首页 > 其他好文 > 详细

PyTorch学习问题记录

时间:2017-07-28 20:09:29      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:modules   his   long   this   code   log   module   name   des   

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() 和 torch.norm() 函数的功能是什么?

 1 t = torch.Tensor([[1, 2], [3, 4]])
 2 print(t)
 3 a = torch.gather(t, 1, torch.LongTensor([[0,0], [1,0]]))
 4 print(a)
 5 ‘‘‘
 6  1  2
 7  3  4
 8 [torch.FloatTensor of size 2x2]
 9 
10  1  1
11  4  3
12 [torch.FloatTensor of size 2x2]
13 ‘‘‘

 1 a = torch.FloatTensor([[1, 2], [3, 4]])
 2 b = torch.norm(a)
 3 print(a)
 4 print(b)
 5 ‘‘‘
 6  1  2
 7  3  4
 8 [torch.FloatTensor of size 2x2]
 9 
10 5.477225575051661
11 ‘‘‘

 

PyTorch学习问题记录

标签:modules   his   long   this   code   log   module   name   des   

原文地址:http://www.cnblogs.com/Joyce-song94/p/7252206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!