|
|
|
@ -8670,10 +8670,6 @@ def random_crop(x, shape, seed=None):
|
|
|
|
|
|
|
|
|
|
def log(x, name=None):
|
|
|
|
|
"""
|
|
|
|
|
:alias_main: paddle.log
|
|
|
|
|
:alias: paddle.log,paddle.tensor.log,paddle.tensor.math.log
|
|
|
|
|
:old_api: paddle.fluid.layers.log
|
|
|
|
|
|
|
|
|
|
Calculates the natural log of the given input tensor, element-wise.
|
|
|
|
|
|
|
|
|
|
.. math::
|
|
|
|
@ -8681,31 +8677,23 @@ def log(x, name=None):
|
|
|
|
|
Out = \\ln(x)
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
x (Variable): Input LoDTensor or Tensor. Must be one of the following types: float32, float64.
|
|
|
|
|
x (Tensor): Input Tensor. Must be one of the following types: float32, float64.
|
|
|
|
|
name (str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Variable: The natural log of the input LoDTensor or Tensor computed element-wise.
|
|
|
|
|
Tensor: The natural log of the input Tensor computed element-wise.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
# Graph Organizing
|
|
|
|
|
x = fluid.layers.data(name="x", shape=[1], dtype="float32")
|
|
|
|
|
res = fluid.layers.log(x)
|
|
|
|
|
|
|
|
|
|
# Create an executor using CPU as an example
|
|
|
|
|
exe = fluid.Executor(fluid.CPUPlace())
|
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
|
|
# Execute
|
|
|
|
|
x_i = np.array([[1], [2]]).astype(np.float32)
|
|
|
|
|
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i}, fetch_list=[res])
|
|
|
|
|
print(res_val) # [[0.], [0.6931472]]
|
|
|
|
|
x = [[2,3,4], [7,8,9]]
|
|
|
|
|
x = paddle.to_tensor(x, dtype='float32')
|
|
|
|
|
res = paddle.log(x)
|
|
|
|
|
# [[0.693147, 1.09861, 1.38629], [1.94591, 2.07944, 2.19722]]
|
|
|
|
|
"""
|
|
|
|
|
if in_dygraph_mode():
|
|
|
|
|
return core.ops.log(x)
|
|
|
|
@ -8846,33 +8834,36 @@ def mean_iou(input, label, num_classes):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
input (Variable): A n-D Tensor of prediction results for semantic labels with type int32 or int64.
|
|
|
|
|
label (Variable): A Tensor of ground truth labels with type int32 or int64.
|
|
|
|
|
input (Tensor): A n-D Tensor of prediction results for semantic labels with type int32 or int64.
|
|
|
|
|
label (Tensor): A Tensor of ground truth labels with type int32 or int64.
|
|
|
|
|
Its shape should be the same as input.
|
|
|
|
|
num_classes (int32): The possible number of labels.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Three Variables.
|
|
|
|
|
Three Tensors.
|
|
|
|
|
|
|
|
|
|
- mean_iou(Variable) : A 1-D Tensor representing the mean intersection-over-union with shape [1]. \
|
|
|
|
|
- mean_iou(Tensor) : A 1-D Tensor representing the mean intersection-over-union with shape [1]. \
|
|
|
|
|
Data type is float32.
|
|
|
|
|
- out_wrong(Variable) : A 1-D Tensor with shape [num_classes]. Data type is int32. \
|
|
|
|
|
- out_wrong(Tensor) : A 1-D Tensor with shape [num_classes]. Data type is int32. \
|
|
|
|
|
The wrong numbers of each class.
|
|
|
|
|
- out_correct(Variable): A 1-D Tensor with shape [num_classes]. Data type is int32. The correct numbers of each class.
|
|
|
|
|
- out_correct(Tensor): A 1-D Tensor with shape [num_classes]. Data type is int32. The correct numbers of each class.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
iou_shape = [None, 32, 32]
|
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
|
|
iou_shape = [64, 32, 32]
|
|
|
|
|
num_classes = 5
|
|
|
|
|
predict = fluid.data(name='predict', shape=iou_shape, dtype='int64')
|
|
|
|
|
label = fluid.data(name='label', shape=iou_shape, dtype='int64')
|
|
|
|
|
mean_iou, out_wrong, out_correct = fluid.layers.mean_iou(predict, label,
|
|
|
|
|
num_classes)
|
|
|
|
|
predict = paddle.randint(low=0, high=255, shape=iou_shape, dtype='int64')
|
|
|
|
|
label = paddle.randint(low=0, high=255, shape=iou_shape, dtype='int64')
|
|
|
|
|
mean_iou, out_wrong, out_correct = paddle.metric.mean_iou(predict, label, num_classes)
|
|
|
|
|
"""
|
|
|
|
|
if in_dygraph_mode():
|
|
|
|
|
return core.ops.mean_iou(input, label, 'num_classes', num_classes)
|
|
|
|
|
|
|
|
|
|
helper = LayerHelper('mean_iou', **locals())
|
|
|
|
|
check_variable_and_dtype(input, 'Predictions', ['int32', 'int64'],
|
|
|
|
|
'mean_iou')
|
|
|
|
@ -11387,10 +11378,6 @@ def _elementwise_op(helper):
|
|
|
|
|
|
|
|
|
|
def scale(x, scale=1.0, bias=0.0, bias_after_scale=True, act=None, name=None):
|
|
|
|
|
"""
|
|
|
|
|
:alias_main: paddle.scale
|
|
|
|
|
:alias: paddle.scale,paddle.tensor.scale,paddle.tensor.math.scale
|
|
|
|
|
:old_api: paddle.fluid.layers.scale
|
|
|
|
|
|
|
|
|
|
Scale operator.
|
|
|
|
|
|
|
|
|
|
Putting scale and bias to the input Tensor as following:
|
|
|
|
@ -11406,52 +11393,33 @@ def scale(x, scale=1.0, bias=0.0, bias_after_scale=True, act=None, name=None):
|
|
|
|
|
Out=scale*(X+bias)
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
x(Variable): Input N-D Tensor of scale operator. Data type can be float32, float64, int8, int16, int32, int64, uint8.
|
|
|
|
|
scale(float|Variable): The scale factor of the input, it should be a float number or a Variable with shape [1] and data type as float32.
|
|
|
|
|
x(Tensor): Input N-D Tensor of scale operator. Data type can be float32, float64, int8, int16, int32, int64, uint8.
|
|
|
|
|
scale(float|Tensor): The scale factor of the input, it should be a float number or a Tensor with shape [1] and data type as float32.
|
|
|
|
|
bias(float): The bias to be put on the input.
|
|
|
|
|
bias_after_scale(bool): Apply bias addition after or before scaling. It is useful for numeric stability in some circumstances.
|
|
|
|
|
act(str, optional): Activation applied to the output such as tanh, softmax, sigmoid, relu.
|
|
|
|
|
name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Variable(Tensor|LoDTensor): Output tensor of scale operator, with shape and data type same as input.
|
|
|
|
|
Tensor: Output tensor of scale operator, with shape and data type same as input.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# scale as a float32 number
|
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
inputs = fluid.layers.data(name="x", shape=[2, 3], dtype='float32')
|
|
|
|
|
output = fluid.layers.scale(inputs, scale = 2.0, bias = 1.0)
|
|
|
|
|
|
|
|
|
|
exe = fluid.Executor(fluid.CPUPlace())
|
|
|
|
|
exe.run(fluid.default_startup_program())
|
|
|
|
|
|
|
|
|
|
img = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
|
|
|
|
|
print(res) # [array([[ 3., 5., 7.], [ 9., 11., 13.]], dtype=float32)]
|
|
|
|
|
data = paddle.randn(shape=[2,3], dtype='float32')
|
|
|
|
|
res = paddle.scale(data, scale=2.0, bias=1.0)
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# scale with parameter scale as Variable
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
inputs = fluid.layers.data(name="x", shape=[2, 3], dtype='float32')
|
|
|
|
|
scale = fluid.layers.data(name="scale", shape=[1], dtype='float32',
|
|
|
|
|
append_batch_size=False)
|
|
|
|
|
output = fluid.layers.scale(inputs, scale = scale, bias = 1.0)
|
|
|
|
|
|
|
|
|
|
exe = fluid.Executor(fluid.CPUPlace())
|
|
|
|
|
exe.run(fluid.default_startup_program())
|
|
|
|
|
|
|
|
|
|
img = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
|
|
|
|
|
scale_np = np.array([2.]).astype(np.float32)
|
|
|
|
|
# scale with parameter scale as a Tensor
|
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
|
|
res = exe.run(fluid.default_main_program(), feed={'x':img, 'scale':scale_np}, fetch_list=[output])
|
|
|
|
|
print(res) # [array([[ 3., 5., 7.], [ 9., 11., 13.]], dtype=float32)]
|
|
|
|
|
data = paddle.randn(shape=[2, 3], dtype='float32')
|
|
|
|
|
factor = paddle.to_tensor([2], dtype='float32')
|
|
|
|
|
res = paddle.scale(data, scale=factor, bias=1.0)
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|