!40593 delete drop parameter type

Merge pull request !40593 from changzherui/del_drop_type
This commit is contained in:
i-robot 2022-08-29 18:31:17 +00:00 committed by Gitee
commit c443ef283a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 38 additions and 118 deletions

View File

@ -11,6 +11,7 @@ mindspore.nn.Dropout
.. note::
训练过程中每步对同一通道(或神经元)独立进行丢弃。
`dtype` 参数会在未来版本删除,不建议使用这个参数。
参数:
- **keep_prob** (float) - 输入神经元保留率数值范围在0到1之间。例如rate=0.9删除10%的神经元。默认值0.5。

View File

@ -20,7 +20,7 @@ import math
import numpy as np
import mindspore.common.dtype as mstype
from mindspore import context
from mindspore import context, log as logger
from mindspore.ops.composite.multitype_ops import _constexpr_utils as const_utils
from mindspore.common.seed import _get_graph_seed
from mindspore.common.tensor import Tensor
@ -119,6 +119,7 @@ class Dropout(Cell):
Note:
Each channel will be zeroed out independently on every construct call.
Parameter `dtype` will be removed in a future version. It is not recommended to define this parameter.
Args:
keep_prob (float): The keep rate, greater than 0 and less equal than 1. E.g. rate=0.9,
@ -159,6 +160,8 @@ class Dropout(Cell):
raise ValueError(f"For '{self.cls_name}', the 'keep_prob' must be a number in range (0, 1], "
f"but got {keep_prob}.")
Validator.check_subclass("dtype", dtype, mstype.number_type, self.cls_name)
if dtype != mstype.float32:
logger.info("This parameter `dtype` will be deleted or invisible in the future. Please don't use it.")
self.keep_prob = keep_prob
seed0, seed1 = _get_graph_seed(0, "dropout")
self.seed0 = seed0

View File

@ -59,10 +59,10 @@ class _Conv(Cell):
self.pad_mode = pad_mode
self.weight_init = weight_init
self.bias_init = bias_init
self.format = Validator.check_string(data_format, ['NCHW', 'NHWC', 'NCDHW'], 'format', self.cls_name)
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
self.data_format = Validator.check_string(data_format, ['NCHW', 'NHWC', 'NCDHW'], 'format', self.cls_name)
if context.get_context("device_target") != "GPU" and self.data_format == "NHWC":
raise ValueError(f"For '{self.cls_name}', the \"NHWC\" format only support in GPU target, "
f"but got the 'format' is {self.format} and "
f"but got the 'format' is {self.data_format} and "
f"the platform is {context.get_context('device_target')}.")
if isinstance(padding, int):
Validator.check_non_negative_int(padding, 'padding', self.cls_name)
@ -93,7 +93,7 @@ class _Conv(Cell):
if transposed:
shape = [in_channels, out_channels // group, *kernel_size]
else:
shape = [out_channels, *kernel_size, in_channels // group] if self.format == "NHWC" else \
shape = [out_channels, *kernel_size, in_channels // group] if self.data_format == "NHWC" else \
[out_channels, in_channels // group, *kernel_size]
self.weight = Parameter(initializer(self.weight_init, shape), name='weight')
@ -108,6 +108,25 @@ class _Conv(Cell):
"""Must be overridden by all subclasses."""
raise NotImplementedError
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}, format={}'.format(
self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init,
self.data_format)
return s
class Conv2d(_Conv):
r"""
@ -283,8 +302,8 @@ class Conv2d(_Conv):
stride=self.stride,
dilation=self.dilation,
group=self.group,
data_format=self.format)
self.bias_add = P.BiasAdd(data_format=self.format)
data_format=self.data_format)
self.bias_add = P.BiasAdd(data_format=self.data_format)
def construct(self, x):
output = self.conv2d(x, self.weight)
@ -292,25 +311,6 @@ class Conv2d(_Conv):
output = self.bias_add(output, self.bias)
return output
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}, format={}'.format(
self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init,
self.format)
return s
@constexpr
def _check_input_3d(input_shape, op_name):
@ -490,24 +490,6 @@ class Conv1d(_Conv):
output = self.squeeze(output)
return output
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}'.format(
self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init)
return s
@constexpr
def _check_input_5dims(input_shape, op_name):
@ -696,8 +678,8 @@ class Conv3d(_Conv):
stride=self.stride,
dilation=self.dilation,
group=self.group,
data_format=self.format)
self.bias_add = P.BiasAdd(data_format=self.format)
data_format=self.data_format)
self.bias_add = P.BiasAdd(data_format=self.data_format)
self.shape = P.Shape()
def construct(self, x):
@ -708,25 +690,6 @@ class Conv3d(_Conv):
output = self.bias_add(output, self.bias)
return output
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}, format={}'.format(
self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init,
self.format)
return s
class Conv3dTranspose(_Conv):
r"""
@ -910,8 +873,8 @@ class Conv3dTranspose(_Conv):
dilation=self.dilation,
group=self.group,
output_padding=self.output_padding,
data_format=self.format)
self.bias_add = P.BiasAdd(data_format=self.format)
data_format=self.data_format)
self.bias_add = P.BiasAdd(data_format=self.data_format)
self.shape = P.Shape()
def construct(self, x):
@ -922,23 +885,6 @@ class Conv3dTranspose(_Conv):
output = self.bias_add(output, self.bias)
return output
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}'.format(self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init)
return s
def _deconv_output_length(is_valid, is_same, is_pad, input_length, filter_size, stride_size, dilation_size, padding):
"""Calculate the width and height of output."""
@ -1149,23 +1095,6 @@ class Conv2dTranspose(_Conv):
self.bias)
return self.conv2d_transpose(x, self.weight, (n, self.out_channels, h_out, w_out))
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}'.format(self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init)
return s
class Conv1dTranspose(_Conv):
r"""
@ -1351,20 +1280,3 @@ class Conv1dTranspose(_Conv):
output = self.squeeze(output)
return output
def extend_repr(self):
s = 'input_channels={}, output_channels={}, kernel_size={}, ' \
'stride={}, pad_mode={}, padding={}, dilation={}, ' \
'group={}, has_bias={}, ' \
'weight_init={}, bias_init={}'.format(self.in_channels,
self.out_channels,
self.kernel_size,
self.stride,
self.pad_mode,
self.padding,
self.dilation,
self.group,
self.has_bias,
self.weight_init,
self.bias_init)
return s

View File

@ -3197,6 +3197,10 @@ class SGD(PrimitiveWithCheck):
initialization and momentum in deep learning <http://proceedings.mlr.press/v28/sutskever13.html>`_.
Note:
If parameters are not grouped, the `weight_decay` in optimizer will be applied on the network parameters without
'beta' or 'gamma' in their names. Users can group parameters to change the strategy of decaying weight. When
parameters are grouped, each group can set `weight_decay`. If not, the `weight_decay` in optimizer will be
applied.
For more details, please refer to :class:`mindspore.nn.SGD`.
Args: