未验证 提交 8ba38e07 编写于 作者: L Leo Chen 提交者: GitHub

update 1.8 apis, test=develop (#2052)

* update 1.8 apis, test=develop

* udpate contents, test=develop
上级 63694b5f
......@@ -7,6 +7,7 @@ fluid.dygraph
dygraph/BackwardStrategy.rst
dygraph/BatchNorm.rst
dygraph/BCELoss.rst
dygraph/BilinearTensorProduct.rst
dygraph/Conv2D.rst
dygraph/Conv2DTranspose.rst
......@@ -27,17 +28,22 @@ fluid.dygraph
dygraph/ExponentialDecay.rst
dygraph/grad.rst
dygraph/GroupNorm.rst
dygraph/GRUCell.rst
dygraph/GRUUnit.rst
dygraph/guard.rst
dygraph/InstanceNorm.rst
dygraph/InverseTimeDecay.rst
dygraph/L1Loss.rst
dygraph/Layer.rst
dygraph/LayerList.rst
dygraph/LayerNorm.rst
dygraph/Linear.rst
dygraph/load_dygraph.rst
dygraph/LSTMCell.rst
dygraph/MSELoss.rst
dygraph/NaturalExpDecay.rst
dygraph/NCE.rst
dygraph/NLLLoss.rst
dygraph/no_grad.rst
dygraph/NoamDecay.rst
dygraph/ParallelEnv.rst
......
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_BCELoss:
BCELoss
-------
.. autoclass:: paddle.fluid.dygraph.BCELoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_InstanceNorm:
InstanceNorm
------------
.. autoclass:: paddle.fluid.dygraph.InstanceNorm
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_nn_loss_L1Loss:
.. _api_fluid_dygraph_L1Loss:
L1Loss
------
.. autoclass:: paddle.nn.loss.L1Loss
.. autoclass:: paddle.fluid.dygraph.L1Loss
:members:
:inherited-members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_MSELoss:
MSELoss
-------
.. autoclass:: paddle.fluid.dygraph.MSELoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_NLLLoss:
NLLLoss
-------
.. autoclass:: paddle.fluid.dygraph.NLLLoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_ProgramTranslator:
ProgramTranslator
-----------------
.. autoclass:: paddle.fluid.dygraph.ProgramTranslator
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_declarative:
declarative
-----------
.. autofunction:: paddle.fluid.dygraph.declarative
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_elementwise_sum:
.. _api_fluid_ComplexVariable:
elementwise_sum
ComplexVariable
---------------
.. autofunction:: paddle.tensor.math.elementwise_sum
.. autoclass:: paddle.fluid.ComplexVariable
:members:
:inherited-members:
:noindex:
......@@ -10,33 +10,6 @@ done
python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_name fluid --to_multiple_files True
python gen_module_index.py fluid fluid
# tensor
for module in math random stat
do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name tensor --to_multiple_files True --output_dir tensor
python gen_module_index.py tensor.${module} ${module}
done
python gen_module_index.py tensor paddle.tensor
for module in math manipulation
do
python gen_doc.py --module_name tensor.${module} --module_prefix tensor.${module} --output tensor/${module} --output_name complex --to_multiple_files True --output_dir complex
python gen_module_index.py complex.tensor.${module} ${module}
done
python gen_module_index.py complex.tensor tensor
python gen_module_index.py complex paddle.complex
# nn
for module in loss
do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name nn --to_multiple_files True --output_dir nn
python gen_module_index.py nn.${module} ${module}
done
python gen_doc.py --module_name "" --module_prefix "" --output nn --output_name nn --to_multiple_files True
python gen_module_index.py nn paddle.nn
# index.rst
python gen_index.py
......
......@@ -6,9 +6,6 @@ API Reference
:maxdepth: 1
../api_guides/index_en.rst
complex.rst
nn.rst
tensor.rst
fluid.rst
backward.rst
clip.rst
......@@ -17,7 +14,6 @@ API Reference
dataset.rst
dygraph.rst
executor.rst
index.rst
initializer.rst
io.rst
layers.rst
......
......@@ -11,9 +11,13 @@ fluid.layers
layers/adaptive_pool2d.rst
layers/adaptive_pool3d.rst
layers/add_position_encoding.rst
layers/addcmul.rst
layers/addmm.rst
layers/affine_channel.rst
layers/affine_grid.rst
layers/allclose.rst
layers/anchor_generator.rst
layers/arange.rst
layers/argmax.rst
layers/argmin.rst
layers/argsort.rst
......@@ -32,6 +36,7 @@ fluid.layers
layers/BeamSearchDecoder.rst
layers/bilinear_tensor_product.rst
layers/bipartite_match.rst
layers/bmm.rst
layers/box_clip.rst
layers/box_coder.rst
layers/box_decoder_and_assign.rst
......@@ -43,6 +48,7 @@ fluid.layers
layers/ceil.rst
layers/center_loss.rst
layers/chunk_eval.rst
layers/clamp.rst
layers/clip.rst
layers/clip_by_norm.rst
layers/collect_fpn_proposals.rst
......@@ -64,6 +70,7 @@ fluid.layers
layers/crf_decoding.rst
layers/crop.rst
layers/crop_tensor.rst
layers/cross.rst
layers/cross_entropy.rst
layers/ctc_greedy_decoder.rst
layers/cumsum.rst
......@@ -76,8 +83,11 @@ fluid.layers
layers/density_prior_box.rst
layers/detection_output.rst
layers/diag.rst
layers/diag_embed.rst
layers/dice_loss.rst
layers/dist.rst
layers/distribute_fpn_proposals.rst
layers/dot.rst
layers/double_buffer.rst
layers/dropout.rst
layers/dynamic_decode.rst
......@@ -88,6 +98,7 @@ fluid.layers
layers/edit_distance.rst
layers/elementwise_add.rst
layers/elementwise_div.rst
layers/elementwise_equal.rst
layers/elementwise_floordiv.rst
layers/elementwise_max.rst
layers/elementwise_min.rst
......@@ -109,8 +120,11 @@ fluid.layers
layers/fill_constant_batch_size_like.rst
layers/filter_by_instag.rst
layers/flatten.rst
layers/flip.rst
layers/floor.rst
layers/fsp_matrix.rst
layers/full.rst
layers/full_like.rst
layers/gather.rst
layers/gather_nd.rst
layers/gather_tree.rst
......@@ -141,13 +155,16 @@ fluid.layers
layers/image_resize.rst
layers/image_resize_short.rst
layers/increment.rst
layers/index_select.rst
layers/inplace_abn.rst
layers/instance_norm.rst
layers/interpolate.rst
layers/inverse_time_decay.rst
layers/iou_similarity.rst
layers/is_empty.rst
layers/isfinite.rst
layers/kldiv_loss.rst
layers/kron.rst
layers/l2_normalize.rst
layers/label_smooth.rst
layers/layer_norm.rst
......@@ -162,12 +179,15 @@ fluid.layers
layers/lod_append.rst
layers/lod_reset.rst
layers/log.rst
layers/log1p.rst
layers/log_loss.rst
layers/log_softmax.rst
layers/logical_and.rst
layers/logical_not.rst
layers/logical_or.rst
layers/logical_xor.rst
layers/logsigmoid.rst
layers/logsumexp.rst
layers/lrn.rst
layers/lstm.rst
layers/lstm_unit.rst
......@@ -178,6 +198,7 @@ fluid.layers
layers/mean.rst
layers/mean_iou.rst
layers/merge_selected_rows.rst
layers/meshgrid.rst
layers/mse_loss.rst
layers/mul.rst
layers/multi_box_head.rst
......@@ -187,6 +208,7 @@ fluid.layers
layers/natural_exp_decay.rst
layers/nce.rst
layers/noam_decay.rst
layers/nonzero.rst
layers/Normal.rst
layers/not_equal.rst
layers/npair_loss.rst
......@@ -210,7 +232,10 @@ fluid.layers
layers/psroi_pool.rst
layers/py_func.rst
layers/py_reader.rst
layers/randint.rst
layers/randn.rst
layers/random_crop.rst
layers/randperm.rst
layers/range.rst
layers/rank.rst
layers/rank_loss.rst
......@@ -238,6 +263,7 @@ fluid.layers
layers/roi_align.rst
layers/roi_perspective_transform.rst
layers/roi_pool.rst
layers/roll.rst
layers/round.rst
layers/row_conv.rst
layers/rpn_target_assign.rst
......@@ -301,6 +327,7 @@ fluid.layers
layers/swish.rst
layers/Switch.rst
layers/switch_case.rst
layers/t.rst
layers/tanh.rst
layers/tanh_shrink.rst
layers/target_assign.rst
......@@ -309,8 +336,11 @@ fluid.layers
layers/tensor_array_to_tensor.rst
layers/thresholded_relu.rst
layers/topk.rst
layers/trace.rst
layers/TrainingHelper.rst
layers/transpose.rst
layers/tril.rst
layers/triu.rst
layers/unfold.rst
layers/Uniform.rst
layers/uniform_random.rst
......
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_addcmul:
addcmul
-------
.. autofunction:: paddle.fluid.layers.addcmul
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_div:
.. _api_fluid_layers_addmm:
div
---
addmm
-----
.. autofunction:: paddle.tensor.math.div
.. autofunction:: paddle.fluid.layers.addmm
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_linalg_dist:
.. _api_fluid_layers_allclose:
dist
allclose
--------
.. autofunction:: paddle.tensor.linalg.dist
.. autofunction:: paddle.fluid.layers.allclose
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_arange:
arange
------
.. autofunction:: paddle.fluid.layers.arange
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_pow:
.. _api_fluid_layers_bmm:
pow
bmm
---
.. autofunction:: paddle.tensor.math.pow
.. autofunction:: paddle.fluid.layers.bmm
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_clamp:
clamp
-----
.. autofunction:: paddle.fluid.layers.clamp
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_cross:
cross
-----
.. autofunction:: paddle.fluid.layers.cross
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_diag_embed:
diag_embed
----------
.. autofunction:: paddle.fluid.layers.diag_embed
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_sqrt:
.. _api_fluid_layers_dist:
sqrt
dist
----
.. autofunction:: paddle.tensor.math.sqrt
.. autofunction:: paddle.fluid.layers.dist
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_add:
.. _api_fluid_layers_dot:
add
dot
---
.. autofunction:: paddle.tensor.math.add
.. autofunction:: paddle.fluid.layers.dot
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_elementwise_equal:
elementwise_equal
-----------------
.. autofunction:: paddle.fluid.layers.elementwise_equal
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_tanh:
.. _api_fluid_layers_flip:
tanh
flip
----
.. autofunction:: paddle.tensor.math.tanh
.. autofunction:: paddle.fluid.layers.flip
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_atan:
.. _api_fluid_layers_full:
atan
full
----
.. autofunction:: paddle.tensor.math.atan
.. autofunction:: paddle.fluid.layers.full
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_full_like:
full_like
---------
.. autofunction:: paddle.fluid.layers.full_like
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_index_select:
index_select
------------
.. autofunction:: paddle.fluid.layers.index_select
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_interpolate:
interpolate
-----------
.. autofunction:: paddle.fluid.layers.interpolate
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_random_rand:
.. _api_fluid_layers_kron:
rand
kron
----
.. autofunction:: paddle.tensor.random.rand
.. autofunction:: paddle.fluid.layers.kron
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_log1p:
log1p
-----
.. autofunction:: paddle.fluid.layers.log1p
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_log_softmax:
log_softmax
-----------
.. autofunction:: paddle.fluid.layers.log_softmax
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_logsumexp:
logsumexp
---------
.. autofunction:: paddle.fluid.layers.logsumexp
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_meshgrid:
meshgrid
--------
.. autofunction:: paddle.fluid.layers.meshgrid
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_nonzero:
nonzero
-------
.. autofunction:: paddle.fluid.layers.nonzero
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_random_randint:
.. _api_fluid_layers_randint:
randint
-------
.. autofunction:: paddle.tensor.random.randint
.. autofunction:: paddle.fluid.layers.randint
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_randn:
randn
-----
.. autofunction:: paddle.fluid.layers.randn
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_random_randperm:
.. _api_fluid_layers_randperm:
randperm
--------
.. autofunction:: paddle.tensor.random.randperm
.. autofunction:: paddle.fluid.layers.randperm
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_roll:
roll
----
.. autofunction:: paddle.fluid.layers.roll
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_mm:
.. _api_fluid_layers_t:
mm
--
t
-
.. autofunction:: paddle.tensor.math.mm
.. autofunction:: paddle.fluid.layers.t
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_trace:
trace
-----
.. autofunction:: paddle.fluid.layers.trace
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_tril:
tril
----
.. autofunction:: paddle.fluid.layers.tril
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_triu:
triu
----
.. autofunction:: paddle.fluid.layers.triu
:noindex:
=========
paddle.nn
=========
.. toctree::
:maxdepth: 1
nn/loss.rst
====
loss
====
.. toctree::
:maxdepth: 1
loss/BCELoss.rst
loss/CrossEntropyLoss.rst
loss/L1Loss.rst
loss/MSELoss.rst
loss/NLLLoss.rst
=============
paddle.tensor
=============
.. toctree::
:maxdepth: 1
tensor/linalg.rst
tensor/math.rst
tensor/random.rst
tensor/stat.rst
======
linalg
======
.. toctree::
:maxdepth: 1
linalg/dist.rst
====
math
====
.. toctree::
:maxdepth: 1
math/add.rst
math/addcmul.rst
math/addmm.rst
math/atan.rst
math/clamp.rst
math/div.rst
math/elementwise_sum.rst
math/log1p.rst
math/logsumexp.rst
math/max.rst
math/min.rst
math/mm.rst
math/mul.rst
math/pow.rst
math/sin.rst
math/sqrt.rst
math/sum.rst
math/tanh.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_mul:
mul
---
.. autofunction:: paddle.tensor.math.mul
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_sin:
sin
---
.. autofunction:: paddle.tensor.math.sin
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_sum:
sum
---
.. autofunction:: paddle.tensor.math.sum
:noindex:
======
random
======
.. toctree::
:maxdepth: 1
random/randint.rst
random/randn.rst
random/randperm.rst
......@@ -10,6 +10,7 @@ fluid.dygraph
dygraph_cn/BackwardStrategy_cn.rst
dygraph_cn/BatchNorm_cn.rst
dygraph_cn/BCELoss_cn.rst
dygraph_cn/BilinearTensorProduct_cn.rst
dygraph_cn/Conv2D_cn.rst
dygraph_cn/Conv2DTranspose_cn.rst
......@@ -17,6 +18,7 @@ fluid.dygraph
dygraph_cn/Conv3DTranspose_cn.rst
dygraph_cn/CosineDecay_cn.rst
dygraph_cn/Dropout_cn.rst
dygraph_cn/declarative_cn.rst
dygraph_cn/Embedding_cn.rst
dygraph_cn/ExponentialDecay_cn.rst
dygraph_cn/FC_cn.rst
......@@ -24,14 +26,18 @@ fluid.dygraph
dygraph_cn/GroupNorm_cn.rst
dygraph_cn/GRUUnit_cn.rst
dygraph_cn/guard_cn.rst
dygraph_cn/InstanceNorm_cn.rst
dygraph_cn/InverseTimeDecay_cn.rst
dygraph_cn/L1Loss_cn.rst
dygraph_cn/Layer_cn.rst
dygraph_cn/LayerList_cn.rst
dygraph_cn/LayerNorm_cn.rst
dygraph_cn/Linear_cn.rst
dygraph_cn/load_dygraph_cn.rst
dygraph_cn/MSELoss_cn.rst
dygraph_cn/NaturalExpDecay_cn.rst
dygraph_cn/NCE_cn.rst
dygraph_cn/NLLLoss_cn.rst
dygraph_cn/NoamDecay_cn.rst
dygraph_cn/ParallelEnv_cn.rst
dygraph_cn/ParameterList_cn.rst
......@@ -41,6 +47,7 @@ fluid.dygraph
dygraph_cn/Pool2D_cn.rst
dygraph_cn/PRelu_cn.rst
dygraph_cn/prepare_context_cn.rst
dygraph_cn/ProgramTranslator_cn.rst
dygraph_cn/save_dygraph_cn.rst
dygraph_cn/Sequential_cn.rst
dygraph_cn/SpectralNorm_cn.rst
......
manual
InstanceNorm
-------------------------------
**版本升级,文档正在开发中**
L1Loss
-------------------------------
.. py:function:: paddle.fluid.layers.L1Loss(reduction='mean')
该接口用于创建一个L1Loss的可调用类,L1Loss计算输入input和标签label间的 `L1 loss` 损失。
该损失函数的数学计算公式如下:
当 `reduction` 设置为 ``'none'`` 时,
.. math::
Out = |input - label|
当 `reduction` 设置为 ``'mean'`` 时,
.. math::
Out = MEAN(|input - label|)
当 `reduction` 设置为 ``'sum'`` 时,
.. math::
Out = SUM(|input - label|)
输入input和标签label的维度是[N, *], 其中N是batch_size, `*` 是任意其他维度。
如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入input相同。
如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。
参数:
- **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回L1Loss。数据类型为string。
返回:返回计算L1Loss的可调用对象。
**代码示例**
.. code-block:: python
# declarative mode
import paddle.fluid as fluid
import numpy as np
import paddle
input = fluid.data(name="input", shape=[1])
label = fluid.data(name="label", shape=[1])
l1_loss = fluid.layers.L1Loss(reduction='mean')
output = l1_loss(input,label)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")
output_data = exe.run(fluid.default_main_program(),
feed={"input":input_data, "label":label_data},
fetch_list=[output],
return_numpy=True)
print(output_data) # [array([0.2], dtype=float32)]
# imperative mode
import paddle.fluid.dygraph as dg
with dg.guard(place) as g:
input = dg.to_variable(input_data)
label = dg.to_variable(label_data)
l1_loss = fluid.layers.L1Loss(reduction='mean')
output = l1_loss(input,label)
print(output.numpy()) # [0.2]
NLLLoss
-------------------------------
.. py:function:: paddle.fluid.dygraph.NLLLoss(weight=None, reduction='mean', ignore_index=-100)
该OP计算输入input和标签label间的 `negative log likelihood loss` 损失 ,可用于训练一个 `n` 类分类器。
如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 里面的值对应类别的权重。当你的训练集样本
不均衡的话,使用这个参数是非常有用的。
该损失函数的数学计算公式如下:
当 `reduction` 设置为 `none` 时,损失函数的数学计算公式为:
.. math::
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad
l_n = - w_{y_n} x_{n,y_n}, \quad
w_{c} = \text{weight}[c] \cdot \mathbb{1}\{c \not= \text{ignore_index}\},
其中 `N` 表示 `batch_size` 。如果 `reduction` 的值不是 `none` (默认为 `mean`),那么此时损失函数
的数学计算公式为:
.. math::
\ell(x, y) = \begin{cases}
\sum_{n=1}^N \frac{1}{\sum_{n=1}^N w_{y_n}} l_n, &
\text{if reduction} = \text{'mean';}\\
\sum_{n=1}^N l_n, &
\text{if reduction} = \text{'sum'.}
\end{cases}
参数:
- **input** (Variable): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。
- **label** (Variable): - 输入input对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。
- **weight** (Variable, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。
- **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。
- **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。
返回:返回存储表示 `negative log likihood loss` 的损失值。
返回类型:Variable
**代码示例**
.. code-block:: python
# declarative mode
import paddle.fluid as fluid
import numpy as np
import paddle
input_np = np.random.random(size=(10, 10)).astype(np.float32)
label_np = np.random.randint(0, 10, size=(10,)).astype(np.int64)
prog = fluid.Program()
startup_prog = fluid.Program()
place = fluid.CPUPlace()
with fluid.program_guard(prog, startup_prog):
input = fluid.data(name='input', shape=[10, 10], dtype='float32')
label = fluid.data(name='label', shape=[10], dtype='int64')
nll_loss = fluid.dygraph.NLLLoss()
res = nll_loss(input, label)
exe = fluid.Executor(place)
static_result = exe.run(
prog,
feed={"input": input_np,
"label": label_np},
fetch_list=[res])
print(static_result)
# imperative mode
import paddle.fluid.dygraph as dg
with dg.guard(place) as g:
input = dg.to_variable(input_np)
label = dg.to_variable(label_np)
output = nll_loss(input, label)
print(output.numpy())
**版本升级,文档正在开发中**
Conv1D
ProgramTranslator
-------------------------------
**版本升级,文档正在开发中**
get
declarative
-------------------------------
**版本升级,文档正在开发中**
=======================
paddle.framework
=======================
.. toctree::
:maxdepth: 1
framework_cn/get_default_dtype_cn.rst
framework_cn/manual_seed_cn.rst
framework_cn/set_default_dtype_cn.rst
......@@ -6,9 +6,6 @@ API Reference
:maxdepth: 1
../api_guides/index_cn.rst
framework_cn.rst
nn_cn.rst
tensor_cn.rst
fluid_cn.rst
api_tree_cn.rst
backward_cn.rst
......@@ -24,6 +21,5 @@ API Reference
optimizer_cn.rst
profiler_cn.rst
regularizer_cn.rst
tensor_cn.rst
transpiler_cn.rst
unique_name_cn.rst
......@@ -16,9 +16,13 @@ fluid.layers
layers_cn/adaptive_pool2d_cn.rst
layers_cn/adaptive_pool3d_cn.rst
layers_cn/add_position_encoding_cn.rst
layers_cn/addcmul_cn.rst
layers_cn/addmm_cn.rst
layers_cn/affine_channel_cn.rst
layers_cn/affine_grid_cn.rst
layers_cn/allclose_cn.rst
layers_cn/anchor_generator_cn.rst
layers_cn/arange_cn.rst
layers_cn/argmax_cn.rst
layers_cn/argmin_cn.rst
layers_cn/argsort_cn.rst
......@@ -35,6 +39,7 @@ fluid.layers
layers_cn/beam_search_decode_cn.rst
layers_cn/bilinear_tensor_product_cn.rst
layers_cn/bipartite_match_cn.rst
layers_cn/bmm_cn.rst
layers_cn/box_clip_cn.rst
layers_cn/box_coder_cn.rst
layers_cn/box_decoder_and_assign_cn.rst
......@@ -47,6 +52,7 @@ fluid.layers
layers_cn/ceil_cn.rst
layers_cn/center_loss_cn.rst
layers_cn/chunk_eval_cn.rst
layers_cn/clamp_cn.rst
layers_cn/clip_by_norm_cn.rst
layers_cn/clip_cn.rst
layers_cn/collect_fpn_proposals_cn.rst
......@@ -68,6 +74,7 @@ fluid.layers
layers_cn/crf_decoding_cn.rst
layers_cn/crop_cn.rst
layers_cn/crop_tensor_cn.rst
layers_cn/cross_cn.rst
layers_cn/cross_entropy_cn.rst
layers_cn/ctc_greedy_decoder_cn.rst
layers_cn/cumsum_cn.rst
......@@ -78,8 +85,11 @@ fluid.layers
layers_cn/density_prior_box_cn.rst
layers_cn/detection_output_cn.rst
layers_cn/diag_cn.rst
layers_cn/diag_embed_cn.rst
layers_cn/dice_loss_cn.rst
layers_cn/dist_cn.rst
layers_cn/distribute_fpn_proposals_cn.rst
layers_cn/dot_cn.rst
layers_cn/double_buffer_cn.rst
layers_cn/dropout_cn.rst
layers_cn/dynamic_gru_cn.rst
......@@ -91,6 +101,7 @@ fluid.layers
layers_cn/edit_distance_cn.rst
layers_cn/elementwise_add_cn.rst
layers_cn/elementwise_div_cn.rst
layers_cn/elementwise_equal_cn.rst
layers_cn/elementwise_floordiv_cn.rst
layers_cn/elementwise_max_cn.rst
layers_cn/elementwise_min_cn.rst
......@@ -111,8 +122,11 @@ fluid.layers
layers_cn/fill_constant_cn.rst
layers_cn/filter_by_instag_cn.rst
layers_cn/flatten_cn.rst
layers_cn/flip_cn.rst
layers_cn/floor_cn.rst
layers_cn/fsp_matrix_cn.rst
layers_cn/full_cn.rst
layers_cn/full_like_cn.rst
layers_cn/gather_cn.rst
layers_cn/gather_nd_cn.rst
layers_cn/gather_tree_cn.rst
......@@ -142,11 +156,14 @@ fluid.layers
layers_cn/image_resize_short_cn.rst
layers_cn/increment_cn.rst
layers_cn/inverse_time_decay_cn.rst
layers_cn/index_select_cn.rst
layers_cn/instance_norm_cn.rst
layers_cn/interpolate_cn.rst
layers_cn/iou_similarity_cn.rst
layers_cn/is_empty_cn.rst
layers_cn/isfinite_cn.rst
layers_cn/kldiv_loss_cn.rst
layers_cn/kron_cn.rst
layers_cn/l2_normalize_cn.rst
layers_cn/label_smooth_cn.rst
layers_cn/layer_norm_cn.rst
......@@ -160,12 +177,15 @@ fluid.layers
layers_cn/lod_append_cn.rst
layers_cn/lod_reset_cn.rst
layers_cn/log_cn.rst
layers_cn/log1p_cn.rst
layers_cn/log_loss_cn.rst
layers_cn/log_softmax_cn.rst
layers_cn/logical_and_cn.rst
layers_cn/logical_not_cn.rst
layers_cn/logical_or_cn.rst
layers_cn/logical_xor_cn.rst
layers_cn/logsigmoid_cn.rst
layers_cn/logsumexp_cn.rst
layers_cn/lrn_cn.rst
layers_cn/lstm_cn.rst
layers_cn/lstm_unit_cn.rst
......@@ -177,6 +197,7 @@ fluid.layers
layers_cn/mean_cn.rst
layers_cn/mean_iou_cn.rst
layers_cn/merge_selected_rows_cn.rst
layers_cn/meshgrid_cn.rst
layers_cn/mse_loss_cn.rst
layers_cn/mul_cn.rst
layers_cn/multi_box_head_cn.rst
......@@ -186,6 +207,7 @@ fluid.layers
layers_cn/natural_exp_decay_cn.rst
layers_cn/nce_cn.rst
layers_cn/noam_decay_cn.rst
layers_cn/nonzero_cn.rst
layers_cn/Normal_cn.rst
layers_cn/not_equal_cn.rst
layers_cn/npair_loss_cn.rst
......@@ -210,8 +232,10 @@ fluid.layers
layers_cn/py_func_cn.rst
layers_cn/py_reader_cn.rst
layers_cn/randint_cn.rst
layers_cn/randn_cn.rst
layers_cn/random_crop_cn.rst
layers_cn/range_cn.rst
layers_cn/randperm_cn.rst
layers_cn/rank_cn.rst
layers_cn/rank_loss_cn.rst
layers_cn/read_file_cn.rst
......@@ -237,6 +261,7 @@ fluid.layers
layers_cn/roi_align_cn.rst
layers_cn/roi_perspective_transform_cn.rst
layers_cn/roi_pool_cn.rst
layers_cn/roll_cn.rst
layers_cn/round_cn.rst
layers_cn/row_conv_cn.rst
layers_cn/rpn_target_assign_cn.rst
......@@ -300,6 +325,7 @@ fluid.layers
layers_cn/swish_cn.rst
layers_cn/Switch_cn.rst
layers_cn/switch_case_cn.rst
layers_cn/t_cn.rst
layers_cn/tanh_cn.rst
layers_cn/tanh_shrink_cn.rst
layers_cn/target_assign_cn.rst
......@@ -308,7 +334,10 @@ fluid.layers
layers_cn/tensor_array_to_tensor_cn.rst
layers_cn/thresholded_relu_cn.rst
layers_cn/topk_cn.rst
layers_cn/trace_cn.rst
layers_cn/transpose_cn.rst
layers_cn/tril_cn.rst
layers_cn/triu_cn.rst
layers_cn/unfold_cn.rst
layers_cn/Uniform_cn.rst
layers_cn/uniform_random_cn.rst
......
......@@ -3,7 +3,7 @@
addcmul
-------------------------------
.. py:function:: paddle.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None)
.. py:function:: paddle.fluid.layers.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None)
计算tensor1和tensor2的逐元素乘积,然后将结果乘以标量value,再加到input上输出。其中input, tensor1, tensor2的维度必须是可广播的。
......@@ -33,5 +33,5 @@ addcmul
input = fluid.data(name='input', dtype='float32', shape=[3, 4])
tensor1 = fluid.data(name='tenosr1', dtype='float32', shape=[1, 4])
tensor2 = fluid.data(name='tensor2', dtype='float32', shape=[3, 4])
data = paddle.addcmul(input, tensor1, tensor2, value=1.0)
data = fluid.layers.addcmul(input, tensor1, tensor2, value=1.0)
......@@ -3,7 +3,7 @@
arange
-------------------------------
.. py:function:: paddle.tensor.arange(start, end, step=1, dtype=None, name=None)
.. py:function:: paddle.fluid.layers.arange(start, end, step=1, dtype=None, name=None)
该API根据step均匀分隔给定数值区间[start, end),并返回该分隔结果。
......@@ -24,6 +24,6 @@ arange
import paddle
import paddle.fluid as fluid
with fluid.dygraph.guard():
x = paddle.arange(0, 6, 2)
x = fluid.layers.arange(0, 6, 2)
# x: [0, 2, 4]
# x dtype: float32
......@@ -3,7 +3,7 @@
bmm
-------------------------------
.. py:function:: paddle.tensor.bmm(x, y, name=None):
.. py:function:: paddle.fluid.layers.bmm(x, y, name=None):
对输入x及输入y进行矩阵相乘。
......@@ -38,7 +38,7 @@ bmm
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(input1)
y = fluid.dygraph.to_variable(input2)
out = paddle.bmm(x, y)
out = fluid.layers.bmm(x, y)
#output size: (2, 2, 2)
#output value:
#[[[6.0, 6.0],[12.0, 12.0]],[[45.0, 45.0],[60.0, 60.0]]]
......
......@@ -3,7 +3,7 @@
clamp
-------------------------------
.. py:function:: paddle.clamp(input, min=None, max=None, output=None, name=None)
.. py:function:: paddle.fluid.layers.clamp(input, min=None, max=None, output=None, name=None)
该OP将输入的所有元素进行剪裁,使得输出元素限制在[min, max]内,具体公式如下:
......@@ -34,8 +34,8 @@ clamp
[4.5,6.4]]).astype('float32')
with fluid.dygraph.guard():
x1 = fluid.dygraph.to_variable(in1)
out1 = paddle.tensor.clamp(x1, min=3.5, max=5.0)
out2 = paddle.tensor.clamp(x1, min=2.5)
out1 = fluid.layers.clamp(x1, min=3.5, max=5.0)
out2 = fluid.layers.clamp(x1, min=2.5)
print(out1.numpy())
# [[3.5, 3.5]
# [4.5, 5.0]]
......
......@@ -3,7 +3,7 @@
cross
-------------------------------
.. py:function:: paddle.cross(input, other, dim=None)
.. py:function:: paddle.fluid.layers.cross(input, other, dim=None)
该OP返回在 ``dim`` 维度上,两个张量 ``input`` 和 ``other`` 的向量积(叉积)。 ``input`` 和 ``other`` 必须有相同的形状,
且指定的 ``dim`` 维上 ``size`` 必须为3,如果 ``dim`` 未指定,默认选取第一个 ``size`` 等于3的维度。
......@@ -34,12 +34,12 @@ cross
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data_x)
y = fluid.dygraph.to_variable(data_y)
out_z1 = paddle.cross(x, y)
out_z1 = fluid.layers.cross(x, y)
print(out_z1.numpy())
#[[-1. -1. -1.]
# [ 2. 2. 2.]
# [-1. -1. -1.]]
out_z2 = paddle.cross(x, y, dim=1)
out_z2 = fluid.layers.cross(x, y, dim=1)
print(out_z2.numpy())
#[[0. 0. 0.]
# [0. 0. 0.]
......
......@@ -3,7 +3,7 @@
dist
-------------------------------
.. py:function:: paddle.tensor.linalg.dist(x, y, p=2)
.. py:function:: paddle.fluid.layers.linalg.dist(x, y, p=2)
该OP用于计算 `(x-y)` 的 p 范数(p-norm),需要注意这不是严格意义上的范数,仅作为距离的度量。输入 `x` 和 `y` 的形状(shape)必须是可广播的(broadcastable)。其含义如下,详情请参考 `numpy的广播概念 <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_ :
......@@ -65,11 +65,11 @@ z (4-D Tensor): 8 x 7 x 6 x 5
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(np.array([[3, 3],[3, 3]]).astype(np.float32))
y = fluid.dygraph.to_variable(np.array([[3, 3],[3, 1]]).astype(np.float32))
out = paddle.dist(x, y, 0)
out = fluid.layers.dist(x, y, 0)
print(out.numpy()) # out = [1.]
out = paddle.dist(x, y, 2)
out = fluid.layers.dist(x, y, 2)
print(out.numpy()) # out = [2.]
out = paddle.dist(x, y, float("inf"))
out = fluid.layers.dist(x, y, float("inf"))
print(out.numpy()) # out = [2.]
out = paddle.dist(x, y, float("-inf"))
out = fluid.layers.dist(x, y, float("-inf"))
print(out.numpy()) # out = [0.]
......@@ -3,7 +3,7 @@
dot
-------------------------------
.. py:function:: paddle.tensor.linalg.dot(x, y, name=None)
.. py:function:: paddle.fluid.layers.dot(x, y, name=None)
该OP计算向量的内积
......@@ -31,7 +31,7 @@ dot
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(np.random.uniform(0.1, 1, [10]).astype(np.float32))
y = fluid.dygraph.to_variable(np.random.uniform(1, 3, [10]).astype(np.float32))
z = paddle.dot(x, y)
z = fluid.layers.dot(x, y)
print(z.numpy())
......@@ -3,7 +3,7 @@
elementwise_equal
-------------------------------
.. py:function:: paddle.elementwise_equal(x, y, name=None)
.. py:function:: paddle.fluid.layers.elementwise_equal(x, y, name=None)
该OP返回 :math:`x==y` 逐元素比较x和y是否相等。
......@@ -26,4 +26,4 @@ elementwise_equal
label = fluid.layers.assign(np.array([3, 3], dtype="int32"))
limit = fluid.layers.assign(np.array([3, 2], dtype="int32"))
out1 = paddle.elementwise_equal(x=label, y=limit) #out1=[True, False]
out1 = fluid.layers.elementwise_equal(x=label, y=limit) #out1=[True, False]
......@@ -3,7 +3,7 @@
flip
-------------------------------
.. py:function:: paddle.flip(input, dims, name=None):
.. py:function:: paddle.fluid.layers.flip(input, dims, name=None):
该OP沿指定轴反转n维tensor.
......@@ -45,6 +45,6 @@ flip
img = np.arange(12).reshape((3,2,2)).astype(np.float32)
with fluid.dygraph.guard():
inputs = fluid.dygraph.to_variable(img)
ret = paddle.flip(inputs, [0, 1])
ret = fluid.layers.flip(inputs, [0, 1])
print(ret.numpy()) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]]
......@@ -3,7 +3,7 @@
full_like
-------------------------------
.. py:function:: paddle.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None)
.. py:function:: paddle.fluid.layers.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None)
该OP创建一个和input具有相同的形状和数据类型的Tensor,其中元素值均为fill_value。
......@@ -28,7 +28,7 @@ full_like
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name='input', dtype='float32', shape=[2, 3])
output = paddle.full_like(input, 2.0)
output = fluid.layers..full_like(input, 2.0)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img=np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
......
......@@ -3,7 +3,7 @@
index_select
-------------------------------
.. py:function:: paddle.index_select(input, index, dim=0)
.. py:function:: paddle.fluid.layers.index_select(input, index, dim=0)
该OP沿着指定维度 ``dim`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``dim`` 维外,返回的张量其余维度大小同输入 ``input`` , ``dim`` 维大小等于 ``index`` 的大小。
......@@ -31,12 +31,12 @@ index_select
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data)
index = fluid.dygraph.to_variable(data_index)
out_z1 = paddle.index_select(x, index)
out_z1 = fluid.layers.index_select(x, index)
print(out_z1.numpy())
#[[1. 2. 3. 4.]
# [5. 6. 7. 8.]
# [5. 6. 7. 8.]]
out_z2 = paddle.index_select(x, index, dim=1)
out_z2 = fluid.layers.index_select(x, index, dim=1)
print(out_z2.numpy())
#[[ 1. 2. 2.]
# [ 5. 6. 6.]
......
......@@ -3,7 +3,7 @@
kron
-------------------------------
.. py:function:: paddle.tensor.kron(x, y, out=None, name=None)
.. py:function:: paddle.fluid.layers.kron(x, y, out=None, name=None)
Kronecker Product 算子。
......@@ -61,7 +61,7 @@ Kronecker Product 算子。
with dg.guard(place):
a_var = dg.to_variable(a)
b_var = dg.to_variable(b)
c_var = paddle.kron(a_var, b_var)
c_var = fluid.layers.kron(a_var, b_var)
c_np = c_var.numpy()
print(c_np)
......
......@@ -3,7 +3,7 @@
log1p
-------------------------------
.. py:function:: paddle.tensor.log1p(x, out=None, name=None)
.. py:function:: paddle.fluid.layers.log1p(x, out=None, name=None)
该OP计算Log1p(加一的自然对数)结果。
......@@ -31,7 +31,7 @@ log1p
import numpy as np
x = fluid.data(name="x", shape=[2,1], dtype="float32")
res = paddle.log1p(x) # paddle.log1p等价于 paddle.tensor.log1p
res = fluid.layers.log1p(x)
# 举例选择CPU计算环境
exe = fluid.Executor(fluid.CPUPlace())
......
......@@ -3,7 +3,7 @@
logsumexp
-------------------------------
.. py:function:: paddle.tensor.math.logsumexp(x, dim=None, keepdim=False, out=None, name=None)
.. py:function:: paddle.fluid.layers.logsumexp(x, dim=None, keepdim=False, out=None, name=None)
该OP对输入Tensor的元素以e为底做指数运算,然后根据指定维度做求和之后取自然对数
......@@ -32,7 +32,7 @@ logsumexp
with fluid.dygraph.guard():
np_x = np.random.uniform(0.1, 1, [10]).astype(np.float32)
x = fluid.dygraph.to_variable(np_x)
print(paddle.logsumexp(x).numpy())
print(fluid.layers.logsumexp(x).numpy())
**代码示例2**
......@@ -45,5 +45,5 @@ logsumexp
with fluid.dygraph.guard():
np_x = np.random.uniform(0.1, 1, [2, 3, 4]).astype(np.float32)
x = fluid.dygraph.to_variable(np_x)
print(paddle.logsumexp(x, dim=1).numpy())
print(paddle.logsumexp(x, dim=[0, 2]).numpy())
print(fluid.layers.logsumexp(x, dim=1).numpy())
print(fluid.layers.logsumexp(x, dim=[0, 2]).numpy())
......@@ -3,7 +3,7 @@
nonzero
-------------------------------
.. py:function:: paddle.nonzero(input, as_tuple=False)
.. py:function:: paddle.fluid.layers.nonzero(input, as_tuple=False)
该OP返回输入 ``input`` 中非零元素的坐标。如果输入 ``input`` 有 ``n`` 维,共包含 ``z`` 个非零元素,当 ``as_tuple = False`` 时,
返回结果是一个 ``shape`` 等于 ``[z x n]`` 的 ``Tensor`` , 第 ``i`` 行代表输入中第 ``i`` 个非零元素的坐标;当 ``as_tuple = True`` 时,
......@@ -33,12 +33,12 @@ nonzero
x1 = fluid.dygraph.to_variable(data1)
x2 = fluid.dygraph.to_variable(data2)
x3 = fluid.dygraph.to_variable(data3)
out_z1 = paddle.nonzero(x1)
out_z1 = fluid.layers.nonzero(x1)
print(out_z1.numpy())
#[[0 0]
# [1 1]
# [2 2]]
out_z1_tuple = paddle.nonzero(x1, as_tuple=True)
out_z1_tuple = fluid.layers.nonzero(x1, as_tuple=True)
for out in out_z1_tuple:
print(out.numpy())
#[[0]
......@@ -47,19 +47,19 @@ nonzero
#[[0]
# [1]
# [2]]
out_z2 = paddle.nonzero(x2)
out_z2 = fluid.layers.nonzero(x2)
print(out_z2.numpy())
#[[1]
# [3]]
out_z2_tuple = paddle.nonzero(x2, as_tuple=True)
out_z2_tuple = fluid.layers.nonzero(x2, as_tuple=True)
for out in out_z2_tuple:
print(out.numpy())
#[[1]
# [3]]
out_z3 = paddle.nonzero(x3)
out_z3 = fluid.layers.nonzero(x3)
print(out_z3.numpy())
#[]
out_z3_tuple = paddle.nonzero(x3, as_tuple=True)
out_z3_tuple = fluid.layers.nonzero(x3, as_tuple=True)
for out in out_z3_tuple:
print(out.numpy())
#[]
......
.. _cn_api_fluid_layers_randint:
randint
-------------------------------
.. py:function:: paddle.fluid.layers.randint(low, high=None, shape=None, out=None, dtype=None, device=None, stop_gradient=False, seed=0, name=None)
该OP使用从区间[low,high)内均匀分布采样的随机整数初始化一个Tensor。当high为None时(默认),均匀采样的区间为[0,low)。
参数:
- **low** (int)-要生成的随机值范围的下限,low包含在范围中。当high为None时,均匀采样的区间为[0,low)。
- **high** (int,可选)-要生成的随机值范围的上限,high不包含在范围中。默认值为None。
- **shape** (list|tuple|Variable,可选)-输出Tensor的维度,shape类型支持list,tuple,Variable。如果shape类型是list或者tuple,它的元素可以是整数或者形状为[1]的Tensor,其中整数的数据类型为int,Tensor的数据类型为int32或int64。如果shape的类型是Variable,则是1D的Tensor,Tensor的数据类型为int32或int64。如果shape为None,则会将shape设置为[1]。默认值为None。
- **out** (Variable,可选)-用于存储创建的Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
- **dtype** (np.dtype|core.VarDesc.VarType|str,可选)- 输出Tensor的数据类型,支持数据类型为int32,int64。如果dtype为None,则会将dtype设置为int64。默认值为None。
- **device** (str, 可选)-指定在GPU或CPU上创建Tensor。如果device为None,则将选择运行Paddle程序的设备,默认为None。
- **stop_gradient** (bool,可选)-指定是否停止梯度计算,默认值为False。
- **seed** (int,可选)-随机种子,用于生成样本。0表示使用系统生成的种子。注意如果种子不为0,该操作符每次都生成同样的随机数。默认为 0。
- **name** (str,可选)-具体用法请参见:ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:表示一个随机初始化结果的Tensor,该Tensor的数据类型由dtype参数决定,该Tensor的维度由shape参数决定。
返回类型:Variable
抛出异常:
- :code:`TypeError`: shape的类型应该是list、tuple 或 Variable。
- :code:`TypeError`: dtype的类型应该是int32或int64。
- :code:`ValueError`: 该OP的high必须大于low(high为None时,则会先将high设置为low,将low设置为0,再判断low和high的大小关系)。
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
# example 1:
# attr shape is a list which doesn't contain tensor Variable.
result_1 = fluid.layers.randint(low=-5, high=5, shape=[3, 4], dtype="int64")
# example 2:
# attr shape is a list which contains tensor Variable.
dim_1 = fluid.layers.fill_constant([1],"int64",3)
dim_2 = fluid.layers.fill_constant([1],"int32",5)
result_2 = fluid.layers.randint(low=-5, high=5, shape=[dim_1, dim_2], dtype="int32")
# example 3:
# attr shape is a Variable, the data type must be int64 or int32.
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
result_3 = fluid.layers.randint(low=-5, high=5, shape=var_shape, dtype="int32")
var_shape_int32 = fluid.data(name='var_shape_int32', shape=[2], dtype="int32")
result_4 = fluid.layers.randint(low=-5, high=5, shape=var_shape_int32, dtype="int64")
# example 4:
# Input only one parameter
# low=0, high=10, shape=[1], dtype='int64'
result_4 = fluid.layers.randint(10)
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
randn
-------------------------------
.. py:function:: paddle.tensor.random.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None)
.. py:function:: paddle.fluid.layers.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None)
该 API 用于生成数据符合标准正态随机分布(均值为 0,方差为 1 的正态随机分布)的 Tensor。
......@@ -26,7 +26,7 @@ randn
# declarative mode
import paddle
import paddle.fluid as fluid
data = paddle.randn([2, 4])
data = fluid.layers.randn([2, 4])
place = fluid.CPUPlace()
exe = fluid.Executor(place)
res, = exe.run(fluid.default_main_program(), feed={}, fetch_list=[data])
......@@ -42,7 +42,7 @@ randn
import paddle.fluid.dygraph as dg
place = fluid.CPUPlace()
with dg.guard(place) as g:
x = paddle.randn([2, 4])
x = fluid.layers.randn([2, 4])
x_np = x.numpy()
print(x_np)
# [[ 1.5149173 -0.26234224 -0.592486 1.4523455 ]
......
......@@ -3,7 +3,7 @@
randperm
-------------------------------
.. py:function:: paddle.tensor.random.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0)
.. py:function:: paddle.fluid.layers.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0)
该OP返回一个数值在0到n-1、顺序随机的整数排列。
......@@ -31,16 +31,16 @@ randperm
# the random seed in computer, so the output in the next example
# will be change.
with fluid.dygraph.guard():
out_1 = paddle.randperm(6)
out_1 = fluid.layers.randperm(6)
print(out_1.numpy()) # Random permutation, for example [2 4 5 0 3 1]
out_2 = fluid.dygraph.to_variable(
np.array([0, 1, 2, 3])).astype(np.int64)
paddle.randperm(6, out_2)
fluid.layers.randperm(6, out_2)
print(out_2.numpy()) # Random permutation, for example [5 0 2 4 1 3]
out_3 = paddle.randperm(6, dtype="int32", device="cpu")
out_3 = fluid.layers.randperm(6, dtype="int32", device="cpu")
print(out_3.numpy()) # Random permutation, for example [3 1 4 2 5 0]
out_4 = paddle.randperm(6, device="cpu", stop_gradient=True)
out_4 = fluid.layers.randperm(6, device="cpu", stop_gradient=True)
print(out_4.numpy()) # Random permutation, for example [3 1 5 2 0 4]
......@@ -3,7 +3,7 @@
roll
-------------------------------
.. py:function:: paddle.roll(input, shifts, dims=None):
.. py:function:: paddle.fluid.layers.roll(input, shifts, dims=None):
该OP沿着指定维度对输入 ``input`` 进行循环滚动,当元素移动到最后位置时,会从第一个位置重新插入。如果 ``dims`` 为 ``None`` ,则输入在被循环滚动之前,会先展平成 ``1-D Tensor`` ,滚动操作完成后恢复成原来的形状。
......@@ -28,12 +28,12 @@ roll
[7.0, 8.0, 9.0]])
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data)
out_z1 = paddle.roll(x, shifts=1)
out_z1 = fluid.layers.roll(x, shifts=1)
print(out_z1.numpy())
#[[9. 1. 2.]
# [3. 4. 5.]
# [6. 7. 8.]]
out_z2 = paddle.roll(x, shifts=1, dims=0)
out_z2 = fluid.layers.roll(x, shifts=1, dims=0)
print(out_z2.numpy())
#[[7. 8. 9.]
# [1. 2. 3.]
......
......@@ -3,7 +3,7 @@
t
-------------------------------
.. py:function:: paddle.tensor.t(input, name=None)
.. py:function:: paddle.fluid.layers.t(input, name=None)
该OP对小于等于2维的Tensor进行数据转置。0维和1维Tensor返回本身,2维Tensor等价于perm设置为0,1的 :ref:`cn_api_fluid_layers_transpose` 函数。
......@@ -21,16 +21,16 @@ t
# 例1 (0-D tensor)
x = tensor([0.79])
paddle.t(x) = tensor([0.79])
fluid.layers.t(x) = tensor([0.79])
# 例2 (1-D tensor)
x = tensor([0.79, 0.84, 0.32])
paddle.t(x) = tensor([0.79, 0.84, 0.32])
fluid.layers.t(x) = tensor([0.79, 0.84, 0.32])
# 例3 (2-D tensor)
x = tensor([0.79, 0.84, 0.32],
[0.64, 0.14, 0.57])
paddle.t(x) = tensor([0.79, 0.64],
fluid.layers.t(x) = tensor([0.79, 0.64],
[0.84, 0.14],
[0.32, 0.57])
......@@ -42,7 +42,7 @@ t
import paddle
import paddle.fluid as fluid
x = fluid.data(name='x', shape=[2, 3], dtype='float32')
x_transposed = paddle.t(x) # paddle.t 等价于 paddle.tensor.t
x_transposed = fluid.layers.t(x) # paddle.t 等价于 paddle.tensor.t
print(x_transposed.shape)
#(3L, 2L)
set
trace
-------------------------------
**版本升级,文档正在开发中**
=======================
paddle.nn
=======================
.. toctree::
:maxdepth: 1
nn_cn/Conv1D_cn.rst
nn_cn/Conv2D_cn.rst
nn_cn/diag_embed_cn.rst
nn_cn/interpolate_cn.rst
nn_cn/Linear_cn.rst
nn_cn/log_softmax_cn.rst
nn_cn/ReLU_cn.rst
nn_cn/Upsample_cn.rst
nn_cn/activation_cn.rst
nn_cn/loss_cn.rst
Conv2D
-------------------------------
**版本升级,文档正在开发中**
Linear
-------------------------------
**版本升级,文档正在开发中**
ReLU
-------------------------------
**版本升级,文档正在开发中**
Upsample
-------------------------------
**版本升级,文档正在开发中**
=======================
activation
=======================
.. toctree::
:maxdepth: 1
activation_cn/Sigmoid_cn.rst
Sigmoid
-------------------------------
**版本升级,文档正在开发中**
=======================
loss
=======================
.. toctree::
:maxdepth: 1
loss_cn/BCELoss_cn.rst
loss_cn/CrossEntropyLoss_cn.rst
loss_cn/L1Loss_cn.rst
loss_cn/MSELoss_cn.rst
loss_cn/NLLLoss_cn.rst
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册