Pytorch
SisyphusY
这个作者很懒,什么都没留下…
展开
-
pytorch如何在不引入额外参数的情况下在forward函数中判断模型是否处于训练状态
知识来自于https://www.cnblogs.com/hellcat/p/8509351.html 前置知识: 当模型使用train()函数进入训练状态时,Module.__dict__字典中的‘training’ 对应的值将会变为True,反之,当模型进入eval模式时,'training'对应的值将会变为False pytorch中nn.Module的模块重写了__getattr__...原创 2019-11-26 20:17:40 · 1214 阅读 · 0 评论 -
pytorch的可重复问题
首先在程序的开头设置: torch.manual_seed(0) torch.cuda.manual_seed(0) torch.cuda.manual_seed_all(0) # 为所有GPU设置随机种子 np.random.seed(0) random.seed(0) 以保证随机数一致 然后在定义DataLoador前,添加如下函数: def worker_init_fn(wo...原创 2019-05-31 17:10:37 · 367 阅读 · 0 评论