比较与torch.nn.functional.dropout3d的差异

查看源文件

torch.nn.functional.dropout3d

torch.nn.functional.dropout3d(input, p=0.5, training=True, inplace=False) -> Tensor

更多内容详见torch.nn.functional.dropout3d

mindspore.ops.dropout3d

mindspore.ops.dropout3d(input, p=0.5, training=True) -> Tensor

更多内容详见mindspore.ops.dropout3d

差异对比

MindSpore此API功能与PyTorchy一致,参数支持的数据类型有差异。

PyTorch:在训练期间,dropout3d以服从伯努利分布的概率p随机将输入Tensor的某些通道归零,每个通道将会独立依据伯努利分布概率p来确定是否被清零。对输入Tensor的某些通道清零,已被证明能有效地减少过度拟合,防止神经元共适应。

MindSpore:MindSpore只支持秩为5的Tensor作为输入。

分类

子类

PyTorch

MindSpore

差异

参数

参数1

input

input

MindSpore只支持秩为5的Tensor作为输入

参数2

p

p

-

参数3

training

training

-

参数4

inplace

-

-

代码示例1

# PyTorch
import torch

input = torch.ones(2, 3, 2, 4)
output = torch.nn.functional.dropout3d(input)
print(output.shape)
# torch.Size([2, 3, 2, 4])

# MindSpore
import mindspore as ms
from mindspore import ops
from mindspore import Tensor
import numpy as np

input = Tensor(np.ones([2, 3, 2, 4]), ms.float32)
input = input.expand_dims(0)
output = ops.dropout3d(input)
output = output.squeeze(0)
print(output.shape)
# (2, 3, 2, 4)

代码示例2

# PyTorch
import torch

input = torch.ones(1, 1, 2, 3, 2, 4)
output = torch.nn.functional.dropout3d(input)
print(output.shape)
# torch.Size([1, 1, 2, 3, 2, 4])

# MindSpore
import mindspore as ms
from mindspore import ops
from mindspore import Tensor
import numpy as np

input = Tensor(np.ones([1, 1, 2, 3, 2, 4]), ms.float32)
input = input.squeeze(0)
output = ops.dropout3d(input)
output = output.expand_dims(0)
print(output.shape)
# (1, 1, 2, 3, 2, 4)