| @@ -408,7 +408,7 @@ class Sigmoid(Cell): | |||||
| Applies sigmoid-type activation element-wise. | Applies sigmoid-type activation element-wise. | ||||
| Sigmoid function is defined as: | Sigmoid function is defined as: | ||||
| :math:`\text{sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)}`, where :math:`x_i` is the element of the input. | |||||
| :math:`\text{sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)}`, where :math:`x_i` is the element of the input. | |||||
| Inputs: | Inputs: | ||||
| - **input_data** (Tensor) - The input of Tanh. | - **input_data** (Tensor) - The input of Tanh. | ||||
| @@ -98,7 +98,7 @@ class Dropout(Cell): | |||||
| Note: | Note: | ||||
| Each channel will be zeroed out independently on every construct call. | Each channel will be zeroed out independently on every construct call. | ||||
| The outputs are scaled by a factor of :math:`\frac{1}{keep\_prob}` during training so | |||||
| The outputs are scaled by a factor of :math:`\frac{1}{keep\_prob}` during training so | |||||
| that the output layer remains at a similar scale. During inference, this | that the output layer remains at a similar scale. During inference, this | ||||
| layer returns the same tensor as the input. | layer returns the same tensor as the input. | ||||
| @@ -176,11 +176,8 @@ class EmbeddingLookup(Cell): | |||||
| Examples: | Examples: | ||||
| >>> input_indices = Tensor(np.array([[1, 0], [3, 2]]), mindspore.int32) | >>> input_indices = Tensor(np.array([[1, 0], [3, 2]]), mindspore.int32) | ||||
| >>> result = nn.EmbeddingLookup(4,2)(input_indices) | >>> result = nn.EmbeddingLookup(4,2)(input_indices) | ||||
| >>> print(result) | |||||
| [[[ 0.00856617 0.01039034] | |||||
| [ 0.00196276 -0.00094072]] | |||||
| [[ 0.01279703 0.00078912] | |||||
| [ 0.00084863 -0.00742412]]] | |||||
| >>> print(result.shape) | |||||
| (2, 2, 2) | |||||
| """ | """ | ||||
| BATCH_SLICE = "batch_slice" | BATCH_SLICE = "batch_slice" | ||||
| FIELD_SLICE = "field_slice" | FIELD_SLICE = "field_slice" | ||||
| @@ -350,11 +347,8 @@ class MultiFieldEmbeddingLookup(EmbeddingLookup): | |||||
| >>> field_ids = Tensor([[0, 1, 1, 0, 0], [0, 0, 1, 0, 0]], mindspore.int32) | >>> field_ids = Tensor([[0, 1, 1, 0, 0], [0, 0, 1, 0, 0]], mindspore.int32) | ||||
| >>> net = nn.MultiFieldEmbeddingLookup(10, 2, field_size=2, operator='SUM') | >>> net = nn.MultiFieldEmbeddingLookup(10, 2, field_size=2, operator='SUM') | ||||
| >>> out = net(input_indices, input_values, field_ids) | >>> out = net(input_indices, input_values, field_ids) | ||||
| >>> print(out) | |||||
| [[[-0.00478983 -0.00772568] | |||||
| [-0.00968955 -0.00064902]] | |||||
| [[-0.01251151 -0.01251151] | |||||
| [-0.00196387 -0.00196387] | |||||
| >>> print(out.shape) | |||||
| (2, 2, 2) | |||||
| """ | """ | ||||
| OPERATOR_SUM = 'SUM' | OPERATOR_SUM = 'SUM' | ||||
| OPERATOR_MEAN = 'MEAN' | OPERATOR_MEAN = 'MEAN' | ||||
| @@ -219,11 +219,12 @@ class SSIM(Cell): | |||||
| Examples: | Examples: | ||||
| >>> net = nn.SSIM() | >>> net = nn.SSIM() | ||||
| >>> np.random.seed(0) | |||||
| >>> img1 = Tensor(np.random.random((1, 3, 16, 16)), mindspore.float32) | >>> img1 = Tensor(np.random.random((1, 3, 16, 16)), mindspore.float32) | ||||
| >>> img2 = Tensor(np.random.random((1, 3, 16, 16)), mindspore.float32) | >>> img2 = Tensor(np.random.random((1, 3, 16, 16)), mindspore.float32) | ||||
| >>> output = net(img1, img2) | >>> output = net(img1, img2) | ||||
| >>> print(output) | >>> print(output) | ||||
| [0.12174469] | |||||
| [-0.15189075] | |||||
| """ | """ | ||||
| def __init__(self, max_val=1.0, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03): | def __init__(self, max_val=1.0, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03): | ||||
| super(SSIM, self).__init__() | super(SSIM, self).__init__() | ||||
| @@ -315,6 +315,7 @@ class DiGamma(Cell): | |||||
| >>> input_x = Tensor(np.array([2, 3, 4]).astype(np.float32)) | >>> input_x = Tensor(np.array([2, 3, 4]).astype(np.float32)) | ||||
| >>> op = nn.DiGamma() | >>> op = nn.DiGamma() | ||||
| >>> output = op(input_x) | >>> output = op(input_x) | ||||
| >>> print(output) | |||||
| [0.42278463 0.92278427 1.2561178] | [0.42278463 0.92278427 1.2561178] | ||||
| """ | """ | ||||
| @@ -661,7 +662,7 @@ class LBeta(Cell): | |||||
| >>> input_y = Tensor(np.array([2.0, 3.0, 14.0, 15.0]).astype(np.float32)) | >>> input_y = Tensor(np.array([2.0, 3.0, 14.0, 15.0]).astype(np.float32)) | ||||
| >>> lbeta = nn.LBeta() | >>> lbeta = nn.LBeta() | ||||
| >>> output = lbeta(input_y, input_x) | >>> output = lbeta(input_y, input_x) | ||||
| >>> print (output) | |||||
| >>> print(output) | |||||
| [-1.7917596 -4.094345 -12.000229 -14.754799] | [-1.7917596 -4.094345 -12.000229 -14.754799] | ||||
| """ | """ | ||||
| @@ -716,6 +716,8 @@ class MatMul(PrimitiveWithInfer): | |||||
| >>> input_x2 = Tensor(np.ones(shape=[3, 4]), mindspore.float32) | >>> input_x2 = Tensor(np.ones(shape=[3, 4]), mindspore.float32) | ||||
| >>> matmul = ops.MatMul() | >>> matmul = ops.MatMul() | ||||
| >>> output = matmul(input_x1, input_x2) | >>> output = matmul(input_x1, input_x2) | ||||
| >>> print(output) | |||||
| [[3. 3. 3. 3.]] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||
| @@ -2368,6 +2370,8 @@ class Acosh(PrimitiveWithInfer): | |||||
| >>> acosh = ops.Acosh() | >>> acosh = ops.Acosh() | ||||
| >>> input_x = Tensor(np.array([1.0, 1.5, 3.0, 100.0]), mindspore.float32) | >>> input_x = Tensor(np.array([1.0, 1.5, 3.0, 100.0]), mindspore.float32) | ||||
| >>> output = acosh(input_x) | >>> output = acosh(input_x) | ||||
| >>> print(output) | |||||
| [0. 0.9624236 1.7627472 5.298292] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||
| @@ -2522,7 +2526,7 @@ class Equal(_LogicBinaryOp): | |||||
| >>> equal = ops.Equal() | >>> equal = ops.Equal() | ||||
| >>> output = equal(input_x, 2.0) | >>> output = equal(input_x, 2.0) | ||||
| >>> print(output) | >>> print(output) | ||||
| Tensor(shape=[3], dtype=Bool, value= [False, True, False]) | |||||
| [False True False] | |||||
| >>> | >>> | ||||
| >>> input_x = Tensor(np.array([1, 2, 3]), mindspore.int32) | >>> input_x = Tensor(np.array([1, 2, 3]), mindspore.int32) | ||||
| >>> input_y = Tensor(np.array([1, 2, 4]), mindspore.int32) | >>> input_y = Tensor(np.array([1, 2, 4]), mindspore.int32) | ||||
| @@ -3246,6 +3250,8 @@ class ACos(PrimitiveWithInfer): | |||||
| >>> acos = ops.ACos() | >>> acos = ops.ACos() | ||||
| >>> input_x = Tensor(np.array([0.74, 0.04, 0.30, 0.56]), mindspore.float32) | >>> input_x = Tensor(np.array([0.74, 0.04, 0.30, 0.56]), mindspore.float32) | ||||
| >>> output = acos(input_x) | >>> output = acos(input_x) | ||||
| >>> print(output) | |||||
| [0.7377037 1.5307858 1.2661037 0.97641146] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||
| @@ -3360,12 +3366,15 @@ class NMSWithMask(PrimitiveWithInfer): | |||||
| ``Ascend`` ``GPU`` | ``Ascend`` ``GPU`` | ||||
| Examples: | Examples: | ||||
| >>> bbox = np.random.rand(128, 5) | |||||
| >>> bbox = np.array([[0.4, 0.2, 0.4, 0.3, 0.1], [0.4, 0.3, 0.6, 0.8, 0.7]]) | |||||
| >>> bbox[:, 2] += bbox[:, 0] | >>> bbox[:, 2] += bbox[:, 0] | ||||
| >>> bbox[:, 3] += bbox[:, 1] | >>> bbox[:, 3] += bbox[:, 1] | ||||
| >>> inputs = Tensor(bbox, mindspore.float32) | >>> inputs = Tensor(bbox, mindspore.float32) | ||||
| >>> nms = ops.NMSWithMask(0.5) | >>> nms = ops.NMSWithMask(0.5) | ||||
| >>> output_boxes, indices, mask = nms(inputs) | >>> output_boxes, indices, mask = nms(inputs) | ||||
| >>> print(output_boxes) | |||||
| [[0.39990234 0.19995117 0.7998047 0.5 0.09997559] | |||||
| [0.39990234 0.30004883 1. 1.0996094 0.7001953 ]] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||
| @@ -3520,6 +3529,7 @@ class Tan(PrimitiveWithInfer): | |||||
| >>> tan = ops.Tan() | >>> tan = ops.Tan() | ||||
| >>> input_x = Tensor(np.array([-1.0, 0.0, 1.0]), mindspore.float32) | >>> input_x = Tensor(np.array([-1.0, 0.0, 1.0]), mindspore.float32) | ||||
| >>> output = tan(input_x) | >>> output = tan(input_x) | ||||
| >>> print(output) | |||||
| [-1.5574081 0. 1.5574081] | [-1.5574081 0. 1.5574081] | ||||
| """ | """ | ||||
| @@ -3733,7 +3743,7 @@ class BitwiseOr(_BitwiseBinaryOp): | |||||
| >>> input_x1 = Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mindspore.int16) | >>> input_x1 = Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mindspore.int16) | ||||
| >>> input_x2 = Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mindspore.int16) | >>> input_x2 = Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mindspore.int16) | ||||
| >>> bitwise_or = ops.BitwiseOr() | >>> bitwise_or = ops.BitwiseOr() | ||||
| >>> boutput = itwise_or(input_x1, input_x2) | |||||
| >>> output = bitwise_or(input_x1, input_x2) | |||||
| >>> print(output) | >>> print(output) | ||||
| [ 0 1 1 -1 -1 3 3] | [ 0 1 1 -1 -1 3 3] | ||||
| """ | """ | ||||
| @@ -3159,16 +3159,12 @@ class LSTM(PrimitiveWithInfer): | |||||
| >>> print(output) | >>> print(output) | ||||
| [[[0.9640267 0.9640267 ] | [[[0.9640267 0.9640267 ] | ||||
| [0.9640267 0.9640267 ]] | [0.9640267 0.9640267 ]] | ||||
| [[0.9950539 0.9950539 ] | [[0.9950539 0.9950539 ] | ||||
| [0.9950539 0.9950539 ]] | [0.9950539 0.9950539 ]] | ||||
| [[0.99932843 0.99932843] | [[0.99932843 0.99932843] | ||||
| [0.99932843 0.99932843]] | [0.99932843 0.99932843]] | ||||
| [[0.9999084 0.9999084 ] | [[0.9999084 0.9999084 ] | ||||
| [0.9999084 0.9999084 ]] | [0.9999084 0.9999084 ]] | ||||
| [[0.9999869 0.9999869 ] | [[0.9999869 0.9999869 ] | ||||
| [0.9999869 0.9999869 ]]] | [0.9999869 0.9999869 ]]] | ||||
| """ | """ | ||||