Browse Source

add examples for ops

Conv2D
Conv2dBackpropInput
SigmoidCrossEntropyWithLogits
SoftmaxCrossEntropyWithLogits
SparseSoftmaxCrossEntropyWithLogits
SparseApplyAdagrad
tags/v0.3.0-alpha
zhaozhenlong 5 years ago
parent
commit
2265669d32
1 changed files with 33 additions and 0 deletions
  1. +33
    -0
      mindspore/ops/operations/nn_ops.py

+ 33
- 0
mindspore/ops/operations/nn_ops.py View File

@@ -634,6 +634,12 @@ class Conv2D(PrimitiveWithInfer):


Outputs: Outputs:
Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`. Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`.

Examples:
>>> input = Tensor(np.ones([10, 32, 32, 32]), mindspore.float32)
>>> weight = Tensor(np.ones([32, 32, 3, 3]), mindspore.float32)
>>> conv2d = P.Conv2D(out_channel=32, kernel_size=3)
>>> conv2d(input, weight)
""" """


@prim_attr_register @prim_attr_register
@@ -1090,6 +1096,13 @@ class Conv2DBackpropInput(PrimitiveWithInfer):


Returns: Returns:
Tensor, the gradients of convolution. Tensor, the gradients of convolution.

Examples:
>>> dout = Tensor(np.ones([10, 32, 30, 30]), mindspore.float32)
>>> weight = Tensor(np.ones([32, 32, 3, 3]), mindspore.float32)
>>> x = Tensor(np.ones([10, 32, 32, 32]))
>>> conv2d_backprop_input = P.Conv2DBackpropInput(out_channel=32, kernel_size=3)
>>> conv2d_backprop_input(dout, weight, F.shape(x))
""" """


@prim_attr_register @prim_attr_register
@@ -1262,6 +1275,9 @@ class SoftmaxCrossEntropyWithLogits(PrimitiveWithInfer):


Outputs: Outputs:
Tuple of 2 Tensor, the loss shape is `(N,)`, and the dlogits with the same shape as `logits`. Tuple of 2 Tensor, the loss shape is `(N,)`, and the dlogits with the same shape as `logits`.

Examples:
Please refer to the usage in nn.SoftmaxCrossEntropyWithLogits source code.
""" """


@prim_attr_register @prim_attr_register
@@ -1306,6 +1322,9 @@ class SparseSoftmaxCrossEntropyWithLogits(PrimitiveWithInfer):
Outputs: Outputs:
Tensor, if `is_grad` is False, the output tensor is the value of loss which is a scalar tensor; Tensor, if `is_grad` is False, the output tensor is the value of loss which is a scalar tensor;
if `is_grad` is True, the output tensor is the gradient of input with the same shape as `logits`. if `is_grad` is True, the output tensor is the gradient of input with the same shape as `logits`.

Examples:
Please refer to the usage in nn.SoftmaxCrossEntropyWithLogits source code.
""" """


@prim_attr_register @prim_attr_register
@@ -2117,6 +2136,12 @@ class SigmoidCrossEntropyWithLogits(PrimitiveWithInfer):


Outputs: Outputs:
Tensor, with the same shape and type as input `logits`. Tensor, with the same shape and type as input `logits`.

Examples:
>>> logits = Tensor(np.random.randn(2, 3).astype(np.float16))
>>> labels = Tensor(np.random.randn(2, 3).astype(np.float16))
>>> sigmoid = P.SigmoidCrossEntropyWithLogits()
>>> sigmoid(logits, labels)
""" """


@prim_attr_register @prim_attr_register
@@ -2471,6 +2496,14 @@ class SparseApplyAdagrad(PrimitiveWithInfer):


Outputs: Outputs:
Tensor, has the same shape and type as `var`. Tensor, has the same shape and type as `var`.

Examples:
var = Tensor(np.random.random((3, 3)), mindspore.float32)
accum = Tensor(np.random.random((3, 3)), mindspore.float32)
grad = Tensor(np.random.random((3, 3)), mindspore.float32)
indices = Tensor(np.ones((3,), np.int32))
sparse_apply_ada_grad = P.SparseApplyAdagrad(0.5)
sparse_apply_ada_grad(var, accum, grad, indices)
""" """


@prim_attr_register @prim_attr_register


Loading…
Cancel
Save