Using Dropout in Pytorch: nn.Dropout vs. F.dropout

前端 未结 3 1217
感情败类
感情败类 2020-12-13 04:08

By using pyTorch there is two ways to dropout torch.nn.Dropout and torch.nn.functional.Dropout.

I struggle to see the difference between t

3条回答
  •  没有蜡笔的小新
    2020-12-13 04:53

    Check torch.nn.functional's implementation:

     if p < 0. or p > 1.:
            raise ValueError("dropout probability has to be between 0 and 1, "
                             "but got {}".format(p))
        return (_VF.dropout_(input, p, training)
                if inplace
                else _VF.dropout(input, p, training))
    

    Check: torch.nn.dropout's implementation:

    def forward(self, input):
            return F.dropout(input, self.p, self.training, self.inplace)
    

    So: their internal operation is the same. Interfaces are different. As for _VF, I guess that's some C/C++ code.

提交回复
热议问题