美文网首页
pytorch记录

pytorch记录

作者: ccccxxxxcccc | 来源:发表于2019-07-10 17:48 被阅读0次

from torch.autograd import Variable

自动求导

参考:

https://github.com/apachecn/pytorch-doc-zh/blob/master/docs/1.0/autograd.md


import argparse

解析参数

参考:

https://www.jianshu.com/p/aac9f8079a53


torch.manual_seed(args.seed) 

#为CPU设置种子用于生成随机数,以使得结果是确定的

if args.cuda:

torch.cuda.manual_seed(args.seed)

#为当前GPU设置随机种子;

如果使用多个GPU,应该使用

torch.cuda.manual_seed_all()

为所有的GPU设置种子。


args,kwargs

https://blog.csdn.net/callinglove/article/details/45483097

原文:https://www.agiliq.com/blog/2012/06/understanding-args-and-kwargs/


model.modules()和model.children()的区别:

model.modules()和model.children()均为迭代器,model.modules()会遍历model中所有的子层,而model.children()仅会遍历当前层。

使用:

for key in model.modules():

    print(key)

# model.modules()类似于 [[1, 2], 3],其遍历结果为:

[[1, 2], 3], [1, 2], 1, 2, 3

# model.children()类似于 [[1, 2], 3],其遍历结果为:

[1, 2], 3

也就是说,用model.children()进行初始化参数时,可能会漏掉部分,用model.modules()会遍历所有层

更多参考:

https://discuss.pytorch.org/t/module-children-vs-module-modules/4551


isinstance函数

https://blog.csdn.net/HS_blog/article/details/81396664


enumerate函数

https://www.runoob.com/python/python-func-enumerate.html


pytorch常用函数
https://blog.csdn.net/LemonTree_Summer/article/details/83416604


Pytorch - torch.nn.modules.upsampling 和 interpolate 函数

https://www.aiuai.cn/aifarm605.html

官网资料

https://pytorch.org/docs/master/_modules/torch/nn/modules/upsampling.html


pytorch的包

https://ptorch.com/docs/1/torchlists


.permute函数

https://blog.csdn.net/york1996/article/details/81876886

.view函数

https://blog.csdn.net/york1996/article/details/81949843

.contiguous函数

https://blog.csdn.net/appleml/article/details/80143212?utm_source=blogxgwz0


相关文章

网友评论

      本文标题:pytorch记录

      本文链接:https://www.haomeiwen.com/subject/asehkctx.html