Pytorch之日常整理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010626937/article/details/81215854

1、tensor.view()的作用

torch.Tensor.view会返回具有相同数据但大小不同的新张量。 返回的张量必须有与原张量相同的数据和相同数量的元素,但可以有不同的大小。一个张量必须是连续contiguous()的才能被查看。类似于Numpynp.reshape()

2、torch.manual_seed()
torch.manual_seed(args.seed) #为CPU设置种子用于生成随机数,以使得结果是确定的
if args.cuda:
torch.cuda.manual_seed(args.seed)#为当前GPU设置随机种子;如果使用多个GPU,应该使用torch.cuda.manual_seed_all()为所有的GPU设置种子。

3、unsqueeze 和 squeeze
squeeze压缩的意思 就是在第几维为1 去掉;
unsqueeze 解缩 在第几维增加 变成*1。

4、pytorch函数之torch.normal()

Returns a Tensor of random numbers drawn from separate normal distributions who’s mean and standard deviation are given.

这个是官网给出的解释,大意是返回一个张量,张量里面的随机数是从相互独立的正态分布中随机生成的。

5、Variable

猜你喜欢

转载自blog.csdn.net/u010626937/article/details/81215854