PyTorch使用技巧1:F.dropout加self.training、F.log_softmax

在这里插入图片描述

1、self.training

dropout方法是将输入Tensor的元素按伯努利分布随机置0,具体原理此处不赘,以后待补。总之就是训练的时候要用dropout,验证/测试的时候要关dropout。

以下介绍Module的training属性,F(torch.nn.functional).dropout 和 nn(torch.nn).Dropout 中相应操作的实现方式,以及Module的training属性受train()和eval()方法影响而改变的机制。

方法来自论文:https://www.jmlr.org/papers/volume15/srivastava14a/srivastava14a.pdf

参考:https://blog.csdn.net/PolarisRisingWar/article/details/117754981

2、F.log_softmax

F.softmax作用:
按照行或者列来做归一化的
F.softmax函数语言格式:

# 0是对列做归一化,1是对行做归一化

F.softmax作用:按照行或者列来做归一化的
F.softmax函数语言格式:

# 0是对列做归一化,1是对行做归一化


F.softmax(x,dim=1) 或者 F.softmax(x,dim=0)

F.log_softmax作用:

在softmax的结果上再做多一次log运算

F.log_softmax函数语言格式:

F.log_softmax(x,dim=1) 或者 F.log_softmax(x,dim=0)

原文链接:https://blog.csdn.net/m0_51004308/article/details/118001835
参考:https://blog.csdn.net/m0_51004308/article/details/118001835

猜你喜欢

转载自blog.csdn.net/weixin_41194129/article/details/125655508
F