【问题标题】:What is the meaning of in-place in dropoutdropout中in-place是什么意思
【发布时间】:2020-02-23 14:42:41
【问题描述】:
def dropout(input, p=0.5, training=True, inplace=False)

就地:如果设置为True,将就地执行此操作。

想问一下dropout中in-place是什么意思。它有什么作用? 执行这些操作时性能有何变化?

谢谢

【问题讨论】:

标签: machine-learning neural-network pytorch dropout


【解决方案1】:

保持inplace=True 本身会在张量input 本身中丢弃一些值,而如果你保持inplace=False,你会将droput(input) 的结果保存在其他要检索的变量中。

例子:

import torch
import torch.nn as nn
inp = torch.tensor([1.0, 2.0, 3, 4, 5])

outplace_dropout = nn.Dropout(p=0.4)
print(inp)
output = outplace_dropout(inp)
print(output)
print(inp) # Notice that the input doesn't get changed here


inplace_droput = nn.Dropout(p=0.4, inplace=True)
inplace_droput(inp)
print(inp) # Notice that the input is changed now

PS:这与您所询问的内容无关,但尽量不要使用 input 作为变量名,因为 input 是 Python 关键字。我知道 Pytorch 文档也这样做,这很有趣。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-21
    • 2016-10-29
    • 2015-01-03
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多