diff --git a/doc/fluid/api/dygraph/grad.rst b/doc/fluid/api/dygraph/grad.rst index fb697aaf16523a5ef1014061e91b2408468448d0..01973660288d4148827cd8a7cc19584950b1ed9a 100644 --- a/doc/fluid/api/dygraph/grad.rst +++ b/doc/fluid/api/dygraph/grad.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_dygraph_grad: +.. _api_paddle_grad: grad ---- -.. autofunction:: paddle.fluid.dygraph.grad +.. autofunction:: paddle.grad :noindex: diff --git a/doc/fluid/api/nn.rst b/doc/fluid/api/nn.rst index 472e1b9a80c19a410fefb050b05ff108cfa8bcdb..246a466029ba84bc31d7ab79ab23bc6317ffdb6b 100644 --- a/doc/fluid/api/nn.rst +++ b/doc/fluid/api/nn.rst @@ -29,12 +29,17 @@ paddle.nn nn/clip_by_norm.rst nn/collect_fpn_proposals.rst nn/cond.rst + nn/ConstantPad1d.rst + nn/ConstantPad2d.rst + nn/ConstantPad3d.rst nn/continuous_value_model.rst nn/conv2d.rst nn/conv2d_transpose.rst nn/conv3d.rst nn/conv3d_transpose.rst nn/cosine_decay.rst + nn/cosine_similarity.rst + nn/CosineSimilarity.rst nn/cross_entropy.rst nn/data.rst nn/deformable_roi_pooling.rst @@ -87,6 +92,7 @@ paddle.nn nn/logsigmoid.rst nn/loss.rst nn/lrn.rst + nn/margin_rank_loss.rst nn/matrix_nms.rst nn/maxout.rst nn/mse_loss.rst @@ -111,9 +117,14 @@ paddle.nn nn/psroi_pool.rst nn/random_crop.rst nn/rank_loss.rst + nn/ReflectionPad1d.rst + nn/ReflectionPad2d.rst nn/ReLU.rst nn/relu.rst nn/relu6.rst + nn/ReplicationPad1d.rst + nn/ReplicationPad2d.rst + nn/ReplicationPad3d.rst nn/resize_bilinear.rst nn/resize_nearest.rst nn/resize_trilinear.rst @@ -144,7 +155,7 @@ paddle.nn nn/ssd_loss.rst nn/swish.rst nn/switch_case.rst - nn/tanh_shrink.rst + nn/tanhshrink.rst nn/target_assign.rst nn/teacher_student_sigmoid_loss.rst nn/temporal_shift.rst @@ -157,6 +168,7 @@ paddle.nn nn/functional/loss/margin_ranking_loss.rst nn/functional/activation/sigmoid.rst nn/layer/loss/MarginRankingLoss.rst + nn/ZeroPad2d.rst nn/AdaptiveAvgPool2d.rst nn/AdaptiveAvgPool3d.rst - nn/layer/activation/Sigmoid.rst \ No newline at end of file + nn/layer/activation/Sigmoid.rst diff --git a/doc/fluid/api/nn/ConstantPad1d.rst b/doc/fluid/api/nn/ConstantPad1d.rst new file mode 100644 index 0000000000000000000000000000000000000000..c50dceea85368677f9b7655f1e086266afc87746 --- /dev/null +++ b/doc/fluid/api/nn/ConstantPad1d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ConstantPad1d: + +ConstantPad1d +------------------------------- +:doc_source: paddle.nn.ConstantPad1d + + diff --git a/doc/fluid/api/nn/ConstantPad2d.rst b/doc/fluid/api/nn/ConstantPad2d.rst new file mode 100644 index 0000000000000000000000000000000000000000..a1b614c7e5e9f2521cf74f5a9e5641632f9f1e86 --- /dev/null +++ b/doc/fluid/api/nn/ConstantPad2d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ConstantPad2d: + +ConstantPad2d +------------------------------- +:doc_source: paddle.nn.ConstantPad2d + + diff --git a/doc/fluid/api/nn/ConstantPad3d.rst b/doc/fluid/api/nn/ConstantPad3d.rst new file mode 100644 index 0000000000000000000000000000000000000000..65bf1aad222361d749893a73882dde6005803290 --- /dev/null +++ b/doc/fluid/api/nn/ConstantPad3d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ConstantPad3d: + +ConstantPad3d +------------------------------- +:doc_source: paddle.nn.ConstantPad3d + + diff --git a/doc/fluid/api/nn/CosineSimilarity.rst b/doc/fluid/api/nn/CosineSimilarity.rst new file mode 100644 index 0000000000000000000000000000000000000000..36e235f0752ed84dce258dae4e3248e1173cad8a --- /dev/null +++ b/doc/fluid/api/nn/CosineSimilarity.rst @@ -0,0 +1,7 @@ +.. _api_nn_CosineSimilarity: + +CosineSimilarity +------------------------------- +:doc_source: paddle.nn.CosineSimilarity + + diff --git a/doc/fluid/api/nn/ReflectionPad1d.rst b/doc/fluid/api/nn/ReflectionPad1d.rst new file mode 100644 index 0000000000000000000000000000000000000000..48998894854e59228aa26de7ec1bdbb8c3e98ec4 --- /dev/null +++ b/doc/fluid/api/nn/ReflectionPad1d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ReflectionPad1d: + +ReflectionPad1d +------------------------------- +:doc_source: paddle.nn.ReflectionPad1d + + diff --git a/doc/fluid/api/nn/ReflectionPad2d.rst b/doc/fluid/api/nn/ReflectionPad2d.rst new file mode 100644 index 0000000000000000000000000000000000000000..50ade0a1acd71415d99839addbf85f271a4dc854 --- /dev/null +++ b/doc/fluid/api/nn/ReflectionPad2d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ReflectionPad2d: + +ReflectionPad2d +------------------------------- +:doc_source: paddle.nn.ReflectionPad2d + + diff --git a/doc/fluid/api/nn/ReplicationPad1d.rst b/doc/fluid/api/nn/ReplicationPad1d.rst new file mode 100644 index 0000000000000000000000000000000000000000..da4c6217ac8a94d30b1e677732d27847bacd86cd --- /dev/null +++ b/doc/fluid/api/nn/ReplicationPad1d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ReplicationPad1d: + +ReplicationPad1d +------------------------------- +:doc_source: paddle.nn.ReplicationPad1d + + diff --git a/doc/fluid/api/nn/ReplicationPad2d.rst b/doc/fluid/api/nn/ReplicationPad2d.rst new file mode 100644 index 0000000000000000000000000000000000000000..b388ba3b97290b8bccdbcf49621ae16170909694 --- /dev/null +++ b/doc/fluid/api/nn/ReplicationPad2d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ReplicationPad2d: + +ReplicationPad2d +------------------------------- +:doc_source: paddle.nn.ReplicationPad2d + + diff --git a/doc/fluid/api/nn/ReplicationPad3d.rst b/doc/fluid/api/nn/ReplicationPad3d.rst new file mode 100644 index 0000000000000000000000000000000000000000..9faba1ccda736bb2b8593e5a84593b71a88f365b --- /dev/null +++ b/doc/fluid/api/nn/ReplicationPad3d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ReplicationPad3d: + +ReplicationPad3d +------------------------------- +:doc_source: paddle.nn.ReplicationPad3d + + diff --git a/doc/fluid/api/nn/ZeroPad2d.rst b/doc/fluid/api/nn/ZeroPad2d.rst new file mode 100644 index 0000000000000000000000000000000000000000..1b71c19f98021f7cdefa4ff44425434bbbd55252 --- /dev/null +++ b/doc/fluid/api/nn/ZeroPad2d.rst @@ -0,0 +1,7 @@ +.. _api_nn_ZeroPad2d: + +ZeroPad2d +------------------------------- +:doc_source: paddle.nn.ZeroPad2d + + diff --git a/doc/fluid/api/nn/activation.rst b/doc/fluid/api/nn/activation.rst index d073a6f71c408dc7fe97889a01b92197ed355eb3..5e1d1be87c05e0c533311573cec81ca980f88b92 100644 --- a/doc/fluid/api/nn/activation.rst +++ b/doc/fluid/api/nn/activation.rst @@ -8,8 +8,15 @@ activation activation/ELU.rst activation/GELU.rst activation/Hardshrink.rst + activation/Tanh.rst activation/Hardtanh.rst + activation/LogSigmoid.rst activation/PReLU.rst activation/ReLU.rst - activation/LogSigmoid.rst + activation/ReLU6.rst + activation/SELU.rst activation/Softmax.rst + activation/Softplus.rst + activation/Softshrink.rst + activation/Softsign.rst + activation/Tanhshrink.rst diff --git a/doc/fluid/api/nn/activation/ReLU6.rst b/doc/fluid/api/nn/activation/ReLU6.rst new file mode 100644 index 0000000000000000000000000000000000000000..8c0f9dfdd6dcc42eb5a0e4a39d1ad7e3026444b0 --- /dev/null +++ b/doc/fluid/api/nn/activation/ReLU6.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_ReLU6: + +ReLU6 +--------- + +.. autoclass:: paddle.nn.ReLU6 + :noindex: + diff --git a/doc/fluid/api/nn/activation/SELU.rst b/doc/fluid/api/nn/activation/SELU.rst new file mode 100644 index 0000000000000000000000000000000000000000..1817d2f7f01233390eca8bf91315ff09e068e6bd --- /dev/null +++ b/doc/fluid/api/nn/activation/SELU.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_SELU: + +SELU +--------- + +.. autoclass:: paddle.nn.SELU + :noindex: + diff --git a/doc/fluid/api/nn/activation/Softplus.rst b/doc/fluid/api/nn/activation/Softplus.rst new file mode 100644 index 0000000000000000000000000000000000000000..3d914222a4b6ac4996d867ac1bfa06cf6fdd4d06 --- /dev/null +++ b/doc/fluid/api/nn/activation/Softplus.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_Softplus: + +Softplus +--------- + +.. autoclass:: paddle.nn.Softplus + :noindex: + diff --git a/doc/fluid/api/nn/activation/Softshrink.rst b/doc/fluid/api/nn/activation/Softshrink.rst new file mode 100644 index 0000000000000000000000000000000000000000..0c332c8fe505563bda387aec3020691e5fe8525a --- /dev/null +++ b/doc/fluid/api/nn/activation/Softshrink.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_Softshrink: + +Softshrink +---------- + +.. autoclass:: paddle.nn.Softshrink + :noindex: + diff --git a/doc/fluid/api/nn/activation/Softsign.rst b/doc/fluid/api/nn/activation/Softsign.rst new file mode 100644 index 0000000000000000000000000000000000000000..9bedacb898e320ebd8986004330fceda2af55479 --- /dev/null +++ b/doc/fluid/api/nn/activation/Softsign.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_Softsign: + +Softsign +--------- + +.. autoclass:: paddle.nn.Softsign + :noindex: + diff --git a/doc/fluid/api/nn/activation/Tanh.rst b/doc/fluid/api/nn/activation/Tanh.rst new file mode 100644 index 0000000000000000000000000000000000000000..80cb491331f1f6bbe8afec91c444709c196ce131 --- /dev/null +++ b/doc/fluid/api/nn/activation/Tanh.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_activation_Tanh: + +Tanh +--------- + +.. autoclass:: paddle.nn.layer.activation.Tanh + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/activation/Tanhshrink.rst b/doc/fluid/api/nn/activation/Tanhshrink.rst new file mode 100644 index 0000000000000000000000000000000000000000..8715fa2726342bcb988a2a442240b7a2673abbc3 --- /dev/null +++ b/doc/fluid/api/nn/activation/Tanhshrink.rst @@ -0,0 +1,8 @@ +.. _api_nn_activation_Tanhshrink: + +Tanhshrink +---------- + +.. autoclass:: paddle.nn.Tanhshrink + :noindex: + diff --git a/doc/fluid/api/nn/cosine_similarity.rst b/doc/fluid/api/nn/cosine_similarity.rst new file mode 100644 index 0000000000000000000000000000000000000000..d568494ff0536262c65a4ef3f8e80aad168d1819 --- /dev/null +++ b/doc/fluid/api/nn/cosine_similarity.rst @@ -0,0 +1,7 @@ +.. _api_nn_cosine_similarity: + +cosine_similarity +------------------------------- +:doc_source: paddle.nn.functional.cosine_similarity + + diff --git a/doc/fluid/api/nn/functional.rst b/doc/fluid/api/nn/functional.rst index 25d0a9743a51d6813fba6bf15a4e1e4118e8a469..d28cbfd07878f39a9e1d90a9a16b1615d9346e9e 100644 --- a/doc/fluid/api/nn/functional.rst +++ b/doc/fluid/api/nn/functional.rst @@ -8,5 +8,6 @@ functional functional/l1_loss.rst functional/nll_loss.rst functional/mse_loss.rst + functional/ctc_loss.rst functional/adaptive_avg_pool2d.rst functional/adaptive_avg_pool3d.rst diff --git a/doc/fluid/api/nn/functional/binary_cross_entropy.rst b/doc/fluid/api/nn/functional/binary_cross_entropy.rst new file mode 100644 index 0000000000000000000000000000000000000000..adafad14aac0b6523c147a0b6803b208004a4fdc --- /dev/null +++ b/doc/fluid/api/nn/functional/binary_cross_entropy.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_functional_binary_cross_entropy: + +binary_cross_entropy +-------------------- + +.. autofunction:: paddle.nn.functional.binary_cross_entropy + :noindex: + diff --git a/doc/fluid/api/nn/functional/ctc_loss.rst b/doc/fluid/api/nn/functional/ctc_loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..c77513c956eb592fc3b1335f08d75b37b0080bff --- /dev/null +++ b/doc/fluid/api/nn/functional/ctc_loss.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_functional_ctc_loss: + +ctc_loss +-------- + +.. autofunction:: paddle.nn.functional.loss.ctc_loss + :noindex: + diff --git a/doc/fluid/api/nn/leaky_relu.rst b/doc/fluid/api/nn/leaky_relu.rst index 2a63e375c2ae873b310f44458e4f55cc03df0075..cf38cdb92c3d432c66f95aaed46449c52677287f 100644 --- a/doc/fluid/api/nn/leaky_relu.rst +++ b/doc/fluid/api/nn/leaky_relu.rst @@ -1,7 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + .. _api_nn_leaky_relu: leaky_relu -------------------------------- -:doc_source: paddle.fluid.layers.leaky_relu +---------- +.. autofunction:: paddle.nn.functional.leaky_relu + :noindex: diff --git a/doc/fluid/api/nn/loss.rst b/doc/fluid/api/nn/loss.rst index bbbf4faa1d34c1c01f90d25356971b87c68ad6b3..a46b76ab27ba2712a3fb0ff8a49cd47c9d97ea4e 100644 --- a/doc/fluid/api/nn/loss.rst +++ b/doc/fluid/api/nn/loss.rst @@ -10,3 +10,4 @@ loss loss/L1Loss.rst loss/MSELoss.rst loss/NLLLoss.rst + loss/CTCLoss.rst diff --git a/doc/fluid/api/nn/loss/BCELoss.rst b/doc/fluid/api/nn/loss/BCELoss.rst new file mode 100644 index 0000000000000000000000000000000000000000..2dd78661c46835024ad4826c6108a3115e329e45 --- /dev/null +++ b/doc/fluid/api/nn/loss/BCELoss.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_loss_BCELoss: + +BCELoss +------------------------------- + +.. autoclass:: paddle.nn.loss.BCELoss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/loss/CTCLoss.rst b/doc/fluid/api/nn/loss/CTCLoss.rst new file mode 100644 index 0000000000000000000000000000000000000000..13ce8ac53cac0808338ca95ff152c491b79706a2 --- /dev/null +++ b/doc/fluid/api/nn/loss/CTCLoss.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_loss_CTCLoss: + +CTCLoss +------- + +.. autoclass:: paddle.nn.loss.CTCLoss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/pad.rst b/doc/fluid/api/nn/pad.rst index b53ecff1fa4de6aabe2462dc8f89d48417de88bb..4459de858d4d80544d92acff9ca3e62c8446e890 100644 --- a/doc/fluid/api/nn/pad.rst +++ b/doc/fluid/api/nn/pad.rst @@ -2,6 +2,6 @@ pad ------------------------------- -:doc_source: paddle.fluid.layers.pad +:doc_source: paddle.nn.functional.pad diff --git a/doc/fluid/api/nn/relu.rst b/doc/fluid/api/nn/relu.rst index f4a73adad505bf8eeb58bee30fd0321cada4dcc9..b186a2b174d77ad0fc635d169fa065b659358c99 100644 --- a/doc/fluid/api/nn/relu.rst +++ b/doc/fluid/api/nn/relu.rst @@ -1,7 +1,7 @@ -.. _api_nn_relu: +.. _api_nn_ReLU: -relu +ReLU ------------------------------- +:doc_source: paddle.fluid.layers.relu + -.. autofunction:: paddle.nn.functional.relu - :noindex: \ No newline at end of file diff --git a/doc/fluid/api/nn/relu6.rst b/doc/fluid/api/nn/relu6.rst index 7b1deb353c48b661afb07ad466870ad815579be0..1346795b4166c57470ea65a96e36e08e9e5b879d 100644 --- a/doc/fluid/api/nn/relu6.rst +++ b/doc/fluid/api/nn/relu6.rst @@ -1,7 +1,9 @@ .. _api_nn_relu6: relu6 -------------------------------- -:doc_source: paddle.fluid.layers.relu6 +---------- + +.. autofunction:: paddle.nn.functional.relu6 + :noindex: diff --git a/doc/fluid/api/nn/selu.rst b/doc/fluid/api/nn/selu.rst index 6a86f8fb9369f50948ec3d4da2ccf7b57c03a7dd..cce236e7c93fec18b2eba99ae55a107e4a556a39 100644 --- a/doc/fluid/api/nn/selu.rst +++ b/doc/fluid/api/nn/selu.rst @@ -1,7 +1,9 @@ .. _api_nn_selu: selu -------------------------------- -:doc_source: paddle.fluid.layers.selu +---------- + +.. autofunction:: paddle.nn.functional.selu + :noindex: diff --git a/doc/fluid/api/nn/softplus.rst b/doc/fluid/api/nn/softplus.rst index 6133cf4d613dace3624704d691640f196b967ea2..2c059b78c40d9ef5c7e7ce3fead8abda28e26d5f 100644 --- a/doc/fluid/api/nn/softplus.rst +++ b/doc/fluid/api/nn/softplus.rst @@ -1,7 +1,9 @@ .. _api_nn_softplus: softplus -------------------------------- -:doc_source: paddle.fluid.layers.softplus +---------- + +.. autofunction:: paddle.nn.functional.softplus + :noindex: diff --git a/doc/fluid/api/nn/softshrink.rst b/doc/fluid/api/nn/softshrink.rst index f611309eddd25588ce8b368c2d15ce980e18eeef..dce2b14edd22aa12df3eb6dc348a9d031d9de79d 100644 --- a/doc/fluid/api/nn/softshrink.rst +++ b/doc/fluid/api/nn/softshrink.rst @@ -1,7 +1,9 @@ .. _api_nn_softshrink: softshrink -------------------------------- -:doc_source: paddle.fluid.layers.softshrink +---------- + +.. autofunction:: paddle.nn.functional.softshrink + :noindex: diff --git a/doc/fluid/api/nn/softsign.rst b/doc/fluid/api/nn/softsign.rst index 88cd3458f117e02aade1f324006671b378a5e647..f2b85114794a14b3df7bab955bef7d7dd1bb06b3 100644 --- a/doc/fluid/api/nn/softsign.rst +++ b/doc/fluid/api/nn/softsign.rst @@ -1,7 +1,8 @@ .. _api_nn_softsign: softsign -------------------------------- -:doc_source: paddle.fluid.layers.softsign +---------- +.. autofunction:: paddle.nn.functional.softsign + :noindex: diff --git a/doc/fluid/api/nn/tanh_shrink.rst b/doc/fluid/api/nn/tanh_shrink.rst deleted file mode 100644 index 61c074dc65a790efd40c0e1ffa346b5e8533df48..0000000000000000000000000000000000000000 --- a/doc/fluid/api/nn/tanh_shrink.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_nn_tanh_shrink: - -tanh_shrink -------------------------------- -:doc_source: paddle.fluid.layers.tanh_shrink - - diff --git a/doc/fluid/api/nn/tanhshrink.rst b/doc/fluid/api/nn/tanhshrink.rst new file mode 100644 index 0000000000000000000000000000000000000000..88160bcc6098f5566f86a4128a4f8a09e79384cc --- /dev/null +++ b/doc/fluid/api/nn/tanhshrink.rst @@ -0,0 +1,9 @@ +.. _api_nn_tanhshrink: + +tanhshrink +----------- + +.. autofunction:: paddle.nn.functional.tanhshrink + :noindex: + + diff --git a/doc/fluid/api/paddle.rst b/doc/fluid/api/paddle.rst index 1d69e4df54808d97d7876289469b0b5e6cf7fa91..8f9717c1def3bd8bee865386258266eeeaa8bb43 100644 --- a/doc/fluid/api/paddle.rst +++ b/doc/fluid/api/paddle.rst @@ -23,6 +23,7 @@ paddle paddle/cast.rst paddle/ceil.rst paddle/cholesky.rst + paddle/chunk.rst paddle/clamp.rst paddle/CompiledProgram.rst paddle/concat.rst @@ -41,6 +42,7 @@ paddle paddle/diag.rst paddle/disable_imperative.rst paddle/dist.rst + paddle/distribution.rst paddle/div.rst paddle/dot.rst paddle/elementwise_add.rst @@ -111,6 +113,7 @@ paddle paddle/not_equal.rst paddle/ones.rst paddle/ones_like.rst + paddle/numel.rst paddle/ParallelExecutor.rst paddle/ParamAttr.rst paddle/pow.rst diff --git a/doc/fluid/api/paddle/argmax.rst b/doc/fluid/api/paddle/argmax.rst index c159ec02d9a369f193c363ee562a93e718b4a9c7..dc1665f9f199d4b288686710fa60d25eadd075c3 100644 --- a/doc/fluid/api/paddle/argmax.rst +++ b/doc/fluid/api/paddle/argmax.rst @@ -1,7 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + .. _api_paddle_argmax: argmax -------------------------------- -:doc_source: paddle.fluid.layers.argmax +------ +.. autofunction:: paddle.tensor.search.argmax + :noindex: diff --git a/doc/fluid/api/paddle/argmin.rst b/doc/fluid/api/paddle/argmin.rst index 7368362db56ed7895697fe7d235f9ae9a45cf10c..18c2334659a92457e4be4f739d94a5f8c633442e 100644 --- a/doc/fluid/api/paddle/argmin.rst +++ b/doc/fluid/api/paddle/argmin.rst @@ -1,7 +1,12 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + .. _api_paddle_argmin: argmin -------------------------------- -:doc_source: paddle.fluid.layers.argmin +------ + +.. autofunction:: paddle.tensor.search.argmin + :noindex: diff --git a/doc/fluid/api/paddle/distribution.rst b/doc/fluid/api/paddle/distribution.rst new file mode 100644 index 0000000000000000000000000000000000000000..76ee9f2eeb20955bd7ed7824c75d1d28a1856272 --- /dev/null +++ b/doc/fluid/api/paddle/distribution.rst @@ -0,0 +1,10 @@ +============ +distribution +============ + +.. toctree:: + :maxdepth: 1 + + distribution/Distribution.rst + distribution/Normal.rst + distribution/Uniform.rst diff --git a/doc/fluid/api/paddle/distribution/Distribution.rst b/doc/fluid/api/paddle/distribution/Distribution.rst new file mode 100644 index 0000000000000000000000000000000000000000..dbfe5082f27b75fd88efb77c2f89d4991b30c723 --- /dev/null +++ b/doc/fluid/api/paddle/distribution/Distribution.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_distribution_Distribution: + +Distribution +------------ + +.. autoclass:: paddle.distribution.Distribution + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/paddle/distribution/Normal.rst b/doc/fluid/api/paddle/distribution/Normal.rst new file mode 100644 index 0000000000000000000000000000000000000000..f0f972fd7e561d9200fb566bab4f2019100efcbd --- /dev/null +++ b/doc/fluid/api/paddle/distribution/Normal.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_distribution_Normal: + +Normal +------ + +.. autoclass:: paddle.distribution.Normal + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/paddle/distribution/Uniform.rst b/doc/fluid/api/paddle/distribution/Uniform.rst new file mode 100644 index 0000000000000000000000000000000000000000..81b5d8dcdfcee360b680958a4c5005dfcca773ac --- /dev/null +++ b/doc/fluid/api/paddle/distribution/Uniform.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_distribution_Uniform: + +Uniform +------- + +.. autoclass:: paddle.distribution.Uniform + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/tensor.rst b/doc/fluid/api/tensor.rst index 48ed3d6b232bb167113f9e06ce1a9524daf7e39b..7e11f3c546725d2d2a5a156f484227813d057771 100644 --- a/doc/fluid/api/tensor.rst +++ b/doc/fluid/api/tensor.rst @@ -16,6 +16,7 @@ paddle.tensor tensor/atan.rst tensor/cast.rst tensor/ceil.rst + tensor/chunk.rst tensor/concat.rst tensor/cos.rst tensor/create_tensor.rst @@ -49,7 +50,10 @@ paddle.tensor tensor/has_nan.rst tensor/increment.rst tensor/is_empty.rst + tensor/index_select.rst tensor/isfinite.rst + tensor/isinf.rst + tensor/isnan.rst tensor/less_equal.rst tensor/less_than.rst tensor/logic.rst @@ -74,6 +78,7 @@ paddle.tensor tensor/not_equal.rst tensor/ones.rst tensor/ones_like.rst + tensor/numel.rst tensor/pow.rst tensor/random.rst tensor/rank.rst @@ -108,6 +113,7 @@ paddle.tensor tensor/squeeze.rst tensor/stack.rst tensor/stanh.rst + tensor/std.rst tensor/stat.rst tensor/strided_slice.rst tensor/sum.rst @@ -119,6 +125,7 @@ paddle.tensor tensor/unique_with_counts.rst tensor/unsqueeze.rst tensor/unstack.rst + tensor/var.rst tensor/where.rst tensor/zeros.rst tensor/zeros_like.rst diff --git a/doc/fluid/api/tensor/argmax.rst b/doc/fluid/api/tensor/argmax.rst index 87d33a51bc5c287cf33e06b4503b281737f0800c..8c4e15720bdeb2540f4d01026a5d68985cd32f05 100644 --- a/doc/fluid/api/tensor/argmax.rst +++ b/doc/fluid/api/tensor/argmax.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_argmax: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_argmax: argmax -------------------------------- -:doc_source: paddle.fluid.layers.argmax +------ +.. autofunction:: paddle.tensor.search.argmax + :noindex: diff --git a/doc/fluid/api/tensor/argmin.rst b/doc/fluid/api/tensor/argmin.rst index 3bfac20b5c48f98925d1db8c116cf5b489cde1e9..c23f6127472a2a33acddfb35b7f8a21be9353f42 100644 --- a/doc/fluid/api/tensor/argmin.rst +++ b/doc/fluid/api/tensor/argmin.rst @@ -1,7 +1,12 @@ -.. _api_tensor_cn_argmin: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_argmin: argmin -------------------------------- -:doc_source: paddle.fluid.layers.argmin +------ + +.. autofunction:: paddle.tensor.search.argmin + :noindex: diff --git a/doc/fluid/api/tensor/chunk.rst b/doc/fluid/api/tensor/chunk.rst new file mode 100644 index 0000000000000000000000000000000000000000..2ff086ac6a690c705f98c01dfbb4ef1ea68affee --- /dev/null +++ b/doc/fluid/api/tensor/chunk.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_chunk: + +chunk +--- + +.. autofunction:: paddle.tensor.chunk + :noindex: + diff --git a/doc/fluid/api/tensor/concat.rst b/doc/fluid/api/tensor/concat.rst index 67c36d744325196e8bce65ed3b7d5d0f8ce9393a..a87f247c03493105da4ad6ae7fc6f14f45f6d62f 100644 --- a/doc/fluid/api/tensor/concat.rst +++ b/doc/fluid/api/tensor/concat.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_concat: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_concat: concat -------------------------------- -:doc_source: paddle.fluid.layers.concat +-------- +.. autofunction:: paddle.tensor.concat + :noindex: diff --git a/doc/fluid/api/tensor/eye.rst b/doc/fluid/api/tensor/eye.rst index 6a30fcc0e96a839c09646632347bae9b2c13e62a..88f0eb3737875fbc2b2282fe0ab213478db13757 100644 --- a/doc/fluid/api/tensor/eye.rst +++ b/doc/fluid/api/tensor/eye.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_eye: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_eye: eye -------------------------------- -:doc_source: paddle.fluid.layers.eye +-------- +.. autofunction:: paddle.tensor.full + :noindex: diff --git a/doc/fluid/api/tensor/full.rst b/doc/fluid/api/tensor/full.rst index 5bfcfc559dd1c81b6c6c322d3fade1c922ab3861..8905deaf3bb58549fe390b106b127fdf2b5d2271 100644 --- a/doc/fluid/api/tensor/full.rst +++ b/doc/fluid/api/tensor/full.rst @@ -1,7 +1,10 @@ -.. _api_tensor_cn_full: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! -full -------------------------------- -:doc_source: paddle.fluid.layers.fill_constant +.. _api_tensor_full: +full +-------- +.. autofunction:: paddle.tensor.full + :noindex: diff --git a/doc/fluid/api/tensor/index_select.rst b/doc/fluid/api/tensor/index_select.rst new file mode 100644 index 0000000000000000000000000000000000000000..d95a199d435e479c06bc9286b1ba74d96433174e --- /dev/null +++ b/doc/fluid/api/tensor/index_select.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_index_select: + +index_select +------------- + +.. autofunction:: paddle.tensor.index_select + :noindex: + diff --git a/doc/fluid/api/tensor/isfinite.rst b/doc/fluid/api/tensor/isfinite.rst index 2fbd3b6e0fca719ceb5575b5149b5f9f1f38cd45..8a599a8ab6eb2217070a5bc5eccea4f378b1ee04 100644 --- a/doc/fluid/api/tensor/isfinite.rst +++ b/doc/fluid/api/tensor/isfinite.rst @@ -1,7 +1,8 @@ -.. _api_tensor_cn_isfinite: +.. _api_tensor_isfinite: isfinite ------------------------------- -:doc_source: paddle.fluid.layers.isfinite +.. autofunction:: paddle.tensor.math.isfinite + :noindex: diff --git a/doc/fluid/api/tensor/isinf.rst b/doc/fluid/api/tensor/isinf.rst new file mode 100644 index 0000000000000000000000000000000000000000..df86445ecfb15c4fda06f442b7b4c4f7cd0d5c0f --- /dev/null +++ b/doc/fluid/api/tensor/isinf.rst @@ -0,0 +1,8 @@ +.. _api_tensor_isinf: + +isinf +------------------------------- + +.. autofunction:: paddle.tensor.math.isinf + :noindex: + diff --git a/doc/fluid/api/tensor/isnan.rst b/doc/fluid/api/tensor/isnan.rst new file mode 100644 index 0000000000000000000000000000000000000000..0fa742c2d2c26d6040a5f303e925c06114d8b93a --- /dev/null +++ b/doc/fluid/api/tensor/isnan.rst @@ -0,0 +1,8 @@ +.. _api_tensor_isnan: + +isnan +------------------------------- + +.. autofunction:: paddle.tensor.math.isnan + :noindex: + diff --git a/doc/fluid/api/tensor/linspace.rst b/doc/fluid/api/tensor/linspace.rst index d66cc866982871827dc21b08e45ce58960e338b8..637c9b780f4da46c4960cc6440945ad9970f4752 100644 --- a/doc/fluid/api/tensor/linspace.rst +++ b/doc/fluid/api/tensor/linspace.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_linspace: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_linspace: linspace -------------------------------- -:doc_source: paddle.fluid.layers.linspace +-------- +.. autofunction:: paddle.tensor.linspace + :noindex: diff --git a/doc/fluid/api/tensor/math.rst b/doc/fluid/api/tensor/math.rst index 0e0218b0351e9c7d90ec9637c6b12f4dd0297c59..f79e3e0de6cd0e70fafdc2f2ad6ce4966493ef56 100644 --- a/doc/fluid/api/tensor/math.rst +++ b/doc/fluid/api/tensor/math.rst @@ -10,7 +10,11 @@ math math/addmm.rst math/atan.rst math/clamp.rst - math/div.rst + math/divide.rst + math/floor_divide.rst + math/remainder.rst + math/floor_mod.rst + math/mod.rst math/elementwise_sum.rst math/log1p.rst math/logsumexp.rst @@ -19,6 +23,8 @@ math math/mm.rst math/mul.rst math/pow.rst + math/prod.rst + math/sign.rst math/sin.rst math/sqrt.rst math/sum.rst diff --git a/doc/fluid/api/tensor/math/divide.rst b/doc/fluid/api/tensor/math/divide.rst new file mode 100644 index 0000000000000000000000000000000000000000..db7c8aa3cd242d58f34e19845a5102b5a90c6b7e --- /dev/null +++ b/doc/fluid/api/tensor/math/divide.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_divide: + +divide +------ + +.. autofunction:: paddle.tensor.math.divide + :noindex: + diff --git a/doc/fluid/api/tensor/math/floor_divide.rst b/doc/fluid/api/tensor/math/floor_divide.rst new file mode 100644 index 0000000000000000000000000000000000000000..aed75d9790babc2d0e7007f6df313f1987241e66 --- /dev/null +++ b/doc/fluid/api/tensor/math/floor_divide.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_floor_divide: + +floor_divide +------------ + +.. autofunction:: paddle.tensor.math.floor_divide + :noindex: + diff --git a/doc/fluid/api/tensor/math/floor_mod.rst b/doc/fluid/api/tensor/math/floor_mod.rst new file mode 100644 index 0000000000000000000000000000000000000000..655e419119b70e73cc8d68af42692923ae1b6e9c --- /dev/null +++ b/doc/fluid/api/tensor/math/floor_mod.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_floor_mod: + +floor_mod +--------- + +.. autofunction:: paddle.tensor.math.floor_mod + :noindex: + diff --git a/doc/fluid/api/tensor/math/logsumexp.rst b/doc/fluid/api/tensor/math/logsumexp.rst new file mode 100644 index 0000000000000000000000000000000000000000..63a25475394863db763250e653ec1348d18e0726 --- /dev/null +++ b/doc/fluid/api/tensor/math/logsumexp.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_logsumexp: + +logsumexp +--------- + +.. autofunction:: paddle.tensor.math.logsumexp + :noindex: + diff --git a/doc/fluid/api/tensor/math/mod.rst b/doc/fluid/api/tensor/math/mod.rst new file mode 100644 index 0000000000000000000000000000000000000000..a5e207a6c43331c150050bc292c32de2db5f4243 --- /dev/null +++ b/doc/fluid/api/tensor/math/mod.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_mod: + +mod +--- + +.. autofunction:: paddle.tensor.math.mod + :noindex: + diff --git a/doc/fluid/api/tensor/math/prod.rst b/doc/fluid/api/tensor/math/prod.rst new file mode 100644 index 0000000000000000000000000000000000000000..b5ced4643775d9001501342ef852dfd38108d49d --- /dev/null +++ b/doc/fluid/api/tensor/math/prod.rst @@ -0,0 +1,9 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! +.. _api_tensor_math_prod: + +prod +---- + +.. autofunction:: paddle.tensor.math.prod + :noindex: diff --git a/doc/fluid/api/tensor/math/remainder.rst b/doc/fluid/api/tensor/math/remainder.rst new file mode 100644 index 0000000000000000000000000000000000000000..6d753fd1310ef994c83a46e06cfa8c4befd4ed88 --- /dev/null +++ b/doc/fluid/api/tensor/math/remainder.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_remainder: + +remainder +--------- + +.. autofunction:: paddle.tensor.math.remainder + :noindex: + diff --git a/doc/fluid/api/tensor/math/sign.rst b/doc/fluid/api/tensor/math/sign.rst new file mode 100644 index 0000000000000000000000000000000000000000..5ee442aec6366911066c206e5e33c9a6f5e5e743 --- /dev/null +++ b/doc/fluid/api/tensor/math/sign.rst @@ -0,0 +1,10 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! +.. _api_tensor_math_sign: + +sign +------ + +.. autofunction:: paddle.tensor.math.sign + :noindex: + diff --git a/doc/fluid/api/tensor/numel.rst b/doc/fluid/api/tensor/numel.rst new file mode 100644 index 0000000000000000000000000000000000000000..cc72d3313ce3caabc64ef00d35d2351ef82d0354 --- /dev/null +++ b/doc/fluid/api/tensor/numel.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_numel: + +numel +------- + +.. autofunction:: paddle.tensor.numel + :noindex: + diff --git a/doc/fluid/api/tensor/ones.rst b/doc/fluid/api/tensor/ones.rst index a1ca5e07206ec46a088c5730dea7e63749b9b445..047198c18a373ecb72fd4b700abf4a29769db012 100644 --- a/doc/fluid/api/tensor/ones.rst +++ b/doc/fluid/api/tensor/ones.rst @@ -1,7 +1,12 @@ -.. _api_tensor_cn_ones: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_ones: ones -------------------------------- -:doc_source: paddle.fluid.layers.ones +-------- + +.. autofunction:: paddle.tensor.ones + :noindex: diff --git a/doc/fluid/api/tensor/random.rst b/doc/fluid/api/tensor/random.rst index fdc985d3de06f89ecc75c5f52dfe59d8f3747987..b119e70bb3226a9bf24f5d831da1a6b685abbca5 100644 --- a/doc/fluid/api/tensor/random.rst +++ b/doc/fluid/api/tensor/random.rst @@ -5,7 +5,10 @@ random .. toctree:: :maxdepth: 1 + random/normal.rst random/rand.rst random/randint.rst random/randn.rst random/randperm.rst + random/standard_normal.rst + random/uniform.rst diff --git a/doc/fluid/api/tensor/random/normal.rst b/doc/fluid/api/tensor/random/normal.rst new file mode 100644 index 0000000000000000000000000000000000000000..1617ef9ba4b53424a37ce7972952a27c0b686740 --- /dev/null +++ b/doc/fluid/api/tensor/random/normal.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_random_normal: + +normal +------ + +.. autofunction:: paddle.tensor.random.normal + :noindex: + diff --git a/doc/fluid/api/tensor/random/standard_normal.rst b/doc/fluid/api/tensor/random/standard_normal.rst new file mode 100644 index 0000000000000000000000000000000000000000..a279a26c077ea05a62bacd3f709624ea5fc7438d --- /dev/null +++ b/doc/fluid/api/tensor/random/standard_normal.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_random_standard_normal: + +standard_normal +--------------- + +.. autofunction:: paddle.tensor.random.standard_normal + :noindex: + diff --git a/doc/fluid/api/tensor/random/uniform.rst b/doc/fluid/api/tensor/random/uniform.rst new file mode 100644 index 0000000000000000000000000000000000000000..b323d371212dbbbe760267d4ec4551f339b69f52 --- /dev/null +++ b/doc/fluid/api/tensor/random/uniform.rst @@ -0,0 +1,10 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_random_uniform: + +uniform +------- + +.. autofunction:: paddle.tensor.random.uniform + :noindex: diff --git a/doc/fluid/api/tensor/split.rst b/doc/fluid/api/tensor/split.rst index 07c2e14808eb9980ebd4bb40a8e169415bc77204..60e6f037a674ddb0da0ac9f78e0670a8490d4e34 100644 --- a/doc/fluid/api/tensor/split.rst +++ b/doc/fluid/api/tensor/split.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_split: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_split: split -------------------------------- -:doc_source: paddle.fluid.layers.split +-------- +.. autofunction:: paddle.tensor.split + :noindex: diff --git a/doc/fluid/api/tensor/std.rst b/doc/fluid/api/tensor/std.rst new file mode 100644 index 0000000000000000000000000000000000000000..3d8db35c14dd6ad64f0dd23bbcc42b3e3101481d --- /dev/null +++ b/doc/fluid/api/tensor/std.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_std: + +std +--------- + +.. autofunction:: paddle.tensor.std + :noindex: + diff --git a/doc/fluid/api/tensor/var.rst b/doc/fluid/api/tensor/var.rst new file mode 100644 index 0000000000000000000000000000000000000000..4a617dec382b6e4e1d1926987500fec8f3e1c7cd --- /dev/null +++ b/doc/fluid/api/tensor/var.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_var: + +var +--------- + +.. autofunction:: paddle.tensor.var + :noindex: + diff --git a/doc/fluid/api/tensor/zeros.rst b/doc/fluid/api/tensor/zeros.rst index 4da38cd94a74ec9724889c1ca708cd24d550f159..616719db249a07ef1ad0373b87b36d3de107e715 100644 --- a/doc/fluid/api/tensor/zeros.rst +++ b/doc/fluid/api/tensor/zeros.rst @@ -1,7 +1,12 @@ -.. _api_tensor_cn_zeros: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_zeros: zeros -------------------------------- -:doc_source: paddle.fluid.layers.zeros +-------- + +.. autofunction:: paddle.tensor.zeros + :noindex: diff --git a/doc/fluid/api_cn/dygraph_cn/grad_cn.rst b/doc/fluid/api_cn/dygraph_cn/grad_cn.rst index bc73f2e14a68bf2be3a68d43c24e39bdd0ad1337..55bc6eb484c1cfd124b8fd1141a985e4da77d31a 100644 --- a/doc/fluid/api_cn/dygraph_cn/grad_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn/grad_cn.rst @@ -1,11 +1,11 @@ -.. _cn_api_fluid_dygraph_grad: +.. _cn_api_paddle_grad: grad ------------------------------- **注意:该API仅支持【动态图】模式** -.. py:method:: paddle.fluid.dygraph.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, no_grad_vars=None, backward_strategy=None) +.. py:method:: paddle.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, no_grad_vars=None, backward_strategy=None) 对于每个 `inputs` ,计算所有 `outputs` 相对于其的梯度和。 @@ -27,34 +27,34 @@ grad **示例代码 1** .. code-block:: python - import paddle.fluid as fluid + import paddle + paddle.disable_static() def test_dygraph_grad(create_graph): - with fluid.dygraph.guard(): - x = fluid.layers.ones(shape=[1], dtype='float32') - x.stop_gradient = False - y = x * x + x = paddle.ones(shape=[1], dtype='float32') + x.stop_gradient = False + y = x * x - # Since y = x * x, dx = 2 * x - dx = fluid.dygraph.grad( - outputs=[y], - inputs=[x], - create_graph=create_graph, - retain_graph=True)[0] + # Since y = x * x, dx = 2 * x + dx = paddle.grad( + outputs=[y], + inputs=[x], + create_graph=create_graph, + retain_graph=True)[0] - z = y + dx + z = y + dx - # If create_graph = False, the gradient of dx - # would not be backpropagated. Therefore, - # z = x * x + dx, and x.gradient() = 2 * x = 2.0 + # If create_graph = False, the gradient of dx + # would not be backpropagated. Therefore, + # z = x * x + dx, and x.gradient() = 2 * x = 2.0 - # If create_graph = True, the gradient of dx - # would be backpropagated. Therefore, - # z = x * x + dx = x * x + 2 * x, and - # x.gradient() = 2 * x + 2 = 4.0 + # If create_graph = True, the gradient of dx + # would be backpropagated. Therefore, + # z = x * x + dx = x * x + 2 * x, and + # x.gradient() = 2 * x + 2 = 4.0 - z.backward() - return x.gradient() + z.backward() + return x.gradient() print(test_dygraph_grad(create_graph=False)) # [2.] print(test_dygraph_grad(create_graph=True)) # [4.] @@ -62,16 +62,15 @@ grad **示例代码 2** .. code-block:: python - import paddle.fluid as fluid - - fluid.enable_dygraph() + import paddle + paddle.disable_static() def test_dygraph_grad(grad_outputs=None): - x = fluid.layers.fill_constant(shape=[1], value=2.0, dtype='float32') + x = paddle.fill_constant(shape=[1], value=2.0, dtype='float32') x.stop_gradient = False y1 = x * x - y2 = x * 3 + y2 = x * 3 # If grad_outputs=None, dy1 = [1], dy2 = [1]. # If grad_outputs=[g1, g2], then: @@ -83,24 +82,24 @@ grad # Therefore, the final result would be: # dx = 2 * x * dy1 + 3 * dy2 = 4 * dy1 + 3 * dy2. - dx = fluid.dygraph.grad( + dx = paddle.grad( outputs=[y1, y2], inputs=[x], grad_outputs=grad_outputs)[0] return dx.numpy() - THREE = fluid.layers.fill_constant(shape=[1], value=3.0, dtype='float32') - FOUR = fluid.layers.fill_constant(shape=[1], value=4.0, dtype='float32') + grad_value = paddle.fill_constant(shape=[1], value=4.0, dtype='float32') # dy1 = [1], dy2 = [1] print(test_dygraph_grad(None)) # [7.] # dy1 = [1], dy2 = [4] - print(test_dygraph_grad([None, FOUR])) # [16.] + print(test_dygraph_grad([None, grad_value])) # [16.] # dy1 = [4], dy2 = [1] - print(test_dygraph_grad([FOUR, None])) # [19.] + print(test_dygraph_grad([grad_value, None])) # [19.] # dy1 = [3], dy2 = [4] - print(test_dygraph_grad([THREE, FOUR])) # [24.] \ No newline at end of file + grad_y1 = paddle.fill_constant(shape=[1], value=3.0, dtype='float32') + print(test_dygraph_grad([grad_y1, grad_value])) # [24.] \ No newline at end of file diff --git a/doc/fluid/api_cn/layers_cn/linspace_cn.rst b/doc/fluid/api_cn/layers_cn/linspace_cn.rst index ca9775016b06c55b7504d31d913aeaad1df76466..51cee5f51993f50e572bb363af8a33b8a376ab3e 100644 --- a/doc/fluid/api_cn/layers_cn/linspace_cn.rst +++ b/doc/fluid/api_cn/layers_cn/linspace_cn.rst @@ -5,25 +5,23 @@ linspace .. py:function:: paddle.fluid.layers.linspace(start, stop, num, dtype=None, name=None) - - - 该OP返回一个Tensor,Tensor的值为在区间start和stop上均匀间隔的num个值,输出Tensor的长度为num。 **注意:该OP不进行梯度计算** 参数: - - **start** (float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **stop** (float|Tensor) – ``end`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **start** (int|float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32,float64,int32 或者int64。 + - **stop** (int|float|Tensor) – ``stop`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32,float64,int32或者int64。 - **num** (int|Tensor) – ``num`` 是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 - - **dtype** (string, 可选) – 输出Tensor的数据类型,可以是float32或者是float64,如果dtype的数据类型为None,输出Tensor数据类型为float32。 + - **dtype** (np.dtype|str, 可选) – 输出Tensor的数据类型,可以是float32,float64, int32或者int64。如果dtype的数据类型为None,输出Tensor数据类型为float32。 - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。 抛出异常: - - ``TypeError`` - 当start或者stop的数据类型不是float32或者float64。 - - ``TypeError`` - 当num的数据类型不是float32或者float64。 - - ``TypeError`` - 当dtype的类型不是float32或者float64。 + - ``TypeError`` - 当 ``start`` 或者 ``stop`` 的数据类型不是float32,float64, int32或者int64。 + - ``TypeError`` - 当 ``dtype`` 的类型不是float32,float64,int32或者int64。 + - ``TypeError`` - ``num`` 的类型必须是int当 ``num`` 不是Tensor的时候。 + - ``TypeError`` - ``num`` 的数据类型必须是int32当 ``num`` 是Tensor的时候。 **代码示例**: diff --git a/doc/fluid/api_cn/layers_cn/ones_cn.rst b/doc/fluid/api_cn/layers_cn/ones_cn.rst index 647b8d8c7caa1896a4a958712af7df325b986718..1eb93c5e0a86886cf3d88e93a6cea0c6e8e23e92 100644 --- a/doc/fluid/api_cn/layers_cn/ones_cn.rst +++ b/doc/fluid/api_cn/layers_cn/ones_cn.rst @@ -9,7 +9,7 @@ ones 参数: - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 - - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 + - **dtype** (np.dtype|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 - **force_cpu** (bool, 可选) – 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。 diff --git a/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst b/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst index a1b65ee1ddb2fe5e59e63df68d7a674a684d6e65..c0a11bc9204a431a4fba0df588189b9d604dcf97 100644 --- a/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst +++ b/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst @@ -15,7 +15,7 @@ reduce_prod 参数: - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 - - **dim** (list | int ,可选)- 求乘积运算的维度。如果为None,则计算所有元素的乘积并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **dim** (int|list|tuple ,可选)- 求乘积运算的维度。如果为None,则计算所有元素的乘积并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 diff --git a/doc/fluid/api_cn/layers_cn/reshape_cn.rst b/doc/fluid/api_cn/layers_cn/reshape_cn.rst index a5e39dff07f19832e9468f7deea5cc43b366a33d..ad2c8b7217b0aed1ad2d30b88bd0b45abd8cc474 100644 --- a/doc/fluid/api_cn/layers_cn/reshape_cn.rst +++ b/doc/fluid/api_cn/layers_cn/reshape_cn.rst @@ -5,11 +5,6 @@ reshape .. py:function:: paddle.fluid.layers.reshape(x, shape, actual_shape=None, act=None, inplace=False, name=None) -:alias_main: paddle.reshape -:alias: paddle.reshape,paddle.tensor.reshape,paddle.tensor.manipulation.reshape -:old_api: paddle.fluid.layers.reshape - - 该OP在保持输入 ``x`` 数据不变的情况下,改变 ``x`` 的形状。 @@ -31,23 +26,24 @@ reshape 2. 给定一个形状为[2,4,6]的三维张量x,目标形状为[2,3,-1,2],则将x变换为形状为[2,3,4,2]的4-D张量,且x的数据保持不变。在这种情况下,目标形状的一个维度被设置为-1,这个维度的值是从x的元素总数和剩余维度推断出来的。 3. 给定一个形状为[2,4,6]的三维张量x,目标形状为[-1,0,3,2],则将x变换为形状为[2,4,3,2]的4-D张量,且x的数据保持不变。在这种情况下,0对应位置的维度值将从x的对应维数中复制,-1对应位置的维度值由x的元素总数和剩余维度推断出来。 -**注意:参数** ``actual_shape`` **之后将被舍弃,只用参数** ``shape`` **来表示目标形状。** +.. warning:: +参数 ``actual_shape`` 之后将被舍弃,只用参数 ``shape`` 来表示目标形状。 参数: - - **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor``,数据类型为 ``float32``,``float64``,``int32``,或 ``int64``。 - - **shape** (list|tuple|Variable)- 数据类型是 ``int32`` 。定义目标形状。目标形状最多只能有一个维度为-1。如果 ``shape`` 的类型是 list 或 tuple, 它的元素可以是整数或者形状为[1]的 ``Tensor`` 或 ``LoDTensor``。如果 ``shape`` 的类型是 ``Variable``,则是1-D的 ``Tensor`` 或 ``LoDTensor``。 - - **actual_shape** (Variable,可选)- 1-D ``Tensor`` 或 ``LoDTensor``,默认值:`None`。如果 ``actual_shape`` 被提供,``actual_shape`` 具有比 ``shape`` 更高的优先级,此时 ``shape`` 只能是整数列表或元组。更新提示:``actual_shape`` 在未来的版本中将被舍弃,并用 ``shape`` 代替。 + - **x** (Tensor)- N-D ``Tensor``,数据类型为 ``float32``,``float64``,``int32``,或 ``int64``。 + - **shape** (list|tuple|Tensor)- 数据类型是 ``int32`` 。定义目标形状。目标形状最多只能有一个维度为-1。如果 ``shape`` 的类型是 list 或 tuple, 它的元素可以是整数或者形状为[1]的 ``Tensor``。如果 ``shape`` 的类型是 ``Tensor``,则是1-D的 ``Tensor``。 + - **actual_shape** (Tensor,可选)- 1-D ``Tensor``,默认值:`None`。如果 ``actual_shape`` 被提供,``actual_shape`` 具有比 ``shape`` 更高的优先级,此时 ``shape`` 只能是整数列表或元组。更新提示:``actual_shape`` 在未来的版本中将被舍弃,并用 ``shape`` 代替。 - **act** (str,可选)- 对形状改变后的输入变量做非线性激活操作,激活函数类型可以参考 :ref:`api_guide_activations` 。默认值: ``None``。 - **inplace** (bool,可选)- 如果 ``inplace`` 为 ``True``,则 ``layers.reshape`` 的输入和输出是同一个变量,否则 ``layers.reshape`` 的输入和输出是不同的变量。默认值:``False``。请注意,如果 ``x`` 是多个OP的输入,则 ``inplace`` 必须为False。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置。默认值: ``None``。 -返回:多维 ``Tensor`` 或 ``LoDTensor``,数据类型与 ``input`` 相同。如果 ``inplace`` 为 ``False``,则返回一个新的变量,否则将改变输入变量 ``x`` 自身。如果 ``act`` 为 ``None``,则直接返回形状改变后的变量,否则返回经过激活函数后的变量。 - -返回类型:Variable。 +返回: +::::::::: +``Tensor``,改变形状后的 ``Tensor``,数据类型与 ``x`` 相同。如果 ``inplace`` 为 ``False``,则返回一个新的变量,否则将改变输入变量 ``x`` 自身。如果 ``act`` 为 ``None``,则直接返回形状改变后的变量,否则返回经过激活函数后的变量。 抛出异常: - - :code:`TypeError`:``actual_shape`` 的类型应该是 Variable 或 None。 - - :code:`TypeError`:``starts`` 的类型应该是list、tuple 或 Variable。 + - :code:`TypeError`:``actual_shape`` 的类型应该是 Tensor 或 None。 + - :code:`TypeError`:``starts`` 的类型应该是list、tuple 或 Tensor。 - :code:`ValueError`:``shape`` 中至多有一个元素可以是-1。 - :code:`ValueError`:``shape`` 中的元素为0时,对应的维度应该小于等于``x``的维度。 - :code:`ValueError`:``shape`` 中的元素除了-1之外,都应该是非负值。 @@ -59,7 +55,7 @@ reshape import paddle.fluid as fluid # example 1: - # attr shape is a list which doesn't contain tensor Variable. + # attr shape is a list which doesn't contain Tensors. data_1 = fluid.data( name='data_1', shape=[2, 4, 6], dtype='float32') reshaped_1 = fluid.layers.reshape( @@ -67,7 +63,7 @@ reshape # the shape of reshaped_1 is [2,4,3,2]. # example 2: - # attr shape is a list which contains tensor Variable. + # attr shape is a list which contains Tensors. data_2 = fluid.layers.fill_constant([2,25], "int32", 3) dim = fluid.layers.fill_constant([1], "int32", 5) reshaped_2 = fluid.layers.reshape(data_2, shape=[dim, 10]) diff --git a/doc/fluid/api_cn/layers_cn/sign_cn.rst b/doc/fluid/api_cn/layers_cn/sign_cn.rst index 5559e7a7bef67ed07aa58e3162e6c501867a803f..7b5e84aa970e7c8dd9c736990c7f32f5d8e7fc17 100644 --- a/doc/fluid/api_cn/layers_cn/sign_cn.rst +++ b/doc/fluid/api_cn/layers_cn/sign_cn.rst @@ -5,12 +5,6 @@ sign .. py:function:: paddle.fluid.layers.sign(x) -:alias_main: paddle.sign -:alias: paddle.sign,paddle.tensor.sign,paddle.tensor.math.sign -:old_api: paddle.fluid.layers.sign - - - 此OP对输入x中每个元素进行正负判断,并且输出正负判断值:1代表正,-1代表负,0代表零。 参数: diff --git a/doc/fluid/api_cn/layers_cn/zeros_cn.rst b/doc/fluid/api_cn/layers_cn/zeros_cn.rst index 7e9973e1080d68abd2d9d2a0ccbe1e8733b02a98..170007734a9e5e7aa4acd541c032f55bc96cb058 100644 --- a/doc/fluid/api_cn/layers_cn/zeros_cn.rst +++ b/doc/fluid/api_cn/layers_cn/zeros_cn.rst @@ -9,7 +9,7 @@ zeros 参数: - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 - - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 + - **dtype** (np.dtype|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 - **force_cpu** (bool, 可选) - 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 返回:值全为0的Tensor,数据类型和 ``dtype`` 定义的类型一致。 diff --git a/doc/fluid/api_cn/nn_cn.rst b/doc/fluid/api_cn/nn_cn.rst index 07c1a61f864fdee7f4a9e4af18aa616d8e3d7c2a..92dbcee5b951ea20b1add4345f7ff3e854f26723 100644 --- a/doc/fluid/api_cn/nn_cn.rst +++ b/doc/fluid/api_cn/nn_cn.rst @@ -48,7 +48,12 @@ paddle.nn nn_cn/conv2d_transpose_cn.rst nn_cn/conv3d_cn.rst nn_cn/conv3d_transpose_cn.rst + nn_cn/ConstantPad1d_cn.rst + nn_cn/ConstantPad2d_cn.rst + nn_cn/ConstantPad3d_cn.rst nn_cn/cosine_decay_cn.rst + nn_cn/cosine_similarity_cn.rst + nn_cn/CosineSimilarity_cn.rst nn_cn/cross_entropy_cn.rst nn_cn/data_cn.rst nn_cn/deformable_roi_pooling_cn.rst @@ -108,6 +113,7 @@ paddle.nn nn_cn/one_hot_cn.rst nn_cn/pad2d_cn.rst nn_cn/pad_cn.rst + nn_cn/Pad_cn.rst nn_cn/pad_constant_like_cn.rst nn_cn/PairwiseDistance_cn.rst nn_cn/ParameterList_cn.rst @@ -124,11 +130,16 @@ paddle.nn nn_cn/psroi_pool_cn.rst nn_cn/random_crop_cn.rst nn_cn/rank_loss_cn.rst + nn_cn/ReflectionPad1d_cn.rst + nn_cn/ReflectionPad2d_cn.rst nn_cn/relu6_cn.rst nn_cn/relu_cn.rst nn_cn/resize_bilinear_cn.rst nn_cn/resize_nearest_cn.rst nn_cn/resize_trilinear_cn.rst + nn_cn/ReplicationPad1d_cn.rst + nn_cn/ReplicationPad2d_cn.rst + nn_cn/ReplicationPad3d_cn.rst nn_cn/retinanet_detection_output_cn.rst nn_cn/retinanet_target_assign_cn.rst nn_cn/roi_align_cn.rst @@ -156,7 +167,7 @@ paddle.nn nn_cn/ssd_loss_cn.rst nn_cn/swish_cn.rst nn_cn/switch_case_cn.rst - nn_cn/tanh_shrink_cn.rst + nn_cn/tanhshrink_cn.rst nn_cn/target_assign_cn.rst nn_cn/teacher_student_sigmoid_loss_cn.rst nn_cn/temporal_shift_cn.rst @@ -174,4 +185,10 @@ paddle.nn nn/cn/functional_cn/MaxPool3d_cn.rst nn_cn/AdaptiveAvgPool2d_cn.rst nn_cn/AdaptiveAvgPool3d_cn.rst - + nn_cn/Dropout_cn.rst + nn_cn/Dropout2D_cn.rst + nn_cn/Dropout3D_cn.rst + nn_cn/AlphaDropout_cn.rst + nn_cn/ZeroPad2d_cn.rst + nn_cn/AdaptiveAvgPool2d_cn.rst + nn_cn/AdaptiveAvgPool3d_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/AlphaDropout_cn.rst b/doc/fluid/api_cn/nn_cn/AlphaDropout_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..8dfdac7935a55010b9891b9835b8b2446629e75c --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/AlphaDropout_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_nn_AlphaDropout: + +AlphaDropout +------------------------------- + +.. py:function:: paddle.nn.AlphaDropout(p=0.5, name=None) + +AlphaDropout是一种具有自归一化性质的dropout。均值为0,方差为1的输入,经过AlphaDropout计算之后,输出的均值和方差与输入保持一致。AlphaDropout通常与SELU激活函数组合使用。论文请参考: `Self-Normalizing Neural Networks `_ + +在动态图模式下,请使用模型的 `eval()` 方法切换至测试阶段。 + +.. note:: + 对应的 `functional方法` 请参考: :ref:`cn_api_nn_functional_alpha_dropout` 。 + +参数 +::::::::: + - **p** (float): 将输入节点置0的概率,即丢弃概率。默认: 0.5。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +经过AlphaDropout之后的结果,与输入x形状相同的 `Tensor` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.array([[-1, 1], [-1, 1]]).astype('float32') + x = paddle.to_tensor(x) + m = paddle.nn.AlphaDropout(p=0.5) + y_train = m(x) + m.eval() # switch the model to test phase + y_test = m(x) + print(x.numpy()) + print(y_train.numpy()) + # [[-0.10721093, 1.6655989 ], [-0.7791938, -0.7791938]] (randomly) + print(y_test.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/ConstantPad1d_cn.rst b/doc/fluid/api_cn/nn_cn/ConstantPad1d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d7025d80e873242b892d0e1deda4bcac895b2e37 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ConstantPad1d_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_nn_ConstantPad1d: + +ConstantPad1d +------------------------------- +.. py:class:: paddle.nn.ConstantPad1d(padding, value=0.0, data_format="NCL", name=None) + +**ConstantPad1d** + +按照 padding 对输入 以constant模式进行 ``pad``,即填充固定值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right]。 + - **value** (float32) - 待填充的值,默认值为0.0。 + - **data_format** (str) - 指定input的format,可为 `'NCL'` 或者 `'NLC'`,默认值为`'NCL'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 2, 3) + pad = [1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ConstantPad1d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[0. 1. 2. 3. 0. 0.] + # [0. 4. 5. 6. 0. 0.]]] diff --git a/doc/fluid/api_cn/nn_cn/ConstantPad2d_cn.rst b/doc/fluid/api_cn/nn_cn/ConstantPad2d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3e8f3e14a80fa3b1e8bd78656fb66b2eb38e9f6d --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ConstantPad2d_cn.rst @@ -0,0 +1,39 @@ +.. _cn_api_nn_ConstantPad2d: + +ConstantPad2d +------------------------------- +.. py:class:: paddle.nn.ConstantPad2d(padding, value=0.0, data_format="NCHW", name=None) + +**ConstantPad2d** + +按照 padding 对输入 以constant模式进行 ``pad``,即填充固定值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom]。 + - **value** (float32) - 待填充的值,默认值为0.0。 + - **data_format** (str) - 指定input的format,可为 `'NCHW'` 或者 `'NHWC'`,默认值为`'NCHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 2, 3) + pad = [1, 0, 1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ConstantPad2d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[0. 0. 0. 0.] + # [0. 1. 2. 3.] + # [0. 4. 5. 6.] + # [0. 0. 0. 0.] + # [0. 0. 0. 0.]]]] diff --git a/doc/fluid/api_cn/nn_cn/ConstantPad3d_cn.rst b/doc/fluid/api_cn/nn_cn/ConstantPad3d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..35ad8aa795d3d0704f7dbac79ba06b6cd5223b7c --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ConstantPad3d_cn.rst @@ -0,0 +1,39 @@ +.. _cn_api_nn_ConstantPad3d: + +ConstantPad3d +------------------------------- +.. py:class:: paddle.nn.ConstantPad3d(padding, value=0.0, data_format="NCDHW", name=None) + +**ConstantPad3d** + +按照 padding 对输入 以constant模式进行 ``pad``,即填充固定值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back]。 + - **value** (float32) - 待填充的值,默认值为0.0。 + - **data_format** (str) - 指定input的format,可为 `'NCDHW'` 或者 `'NDHWC'`,默认值为`'NCDHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 1, 2, 3) + pad = [1, 0, 1, 2, 0, 0] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ConstantPad3d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[[0. 0. 0. 0.] + # [0. 1. 2. 3.] + # [0. 4. 5. 6.] + # [0. 0. 0. 0.] + # [0. 0. 0. 0.]]]]] diff --git a/doc/fluid/api_cn/nn_cn/CosineSimilarity_cn.rst b/doc/fluid/api_cn/nn_cn/CosineSimilarity_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..a11bb606ad14afd7c91871c10b618e5255209bde --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/CosineSimilarity_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_nn_CosineSimilarity: + +CosineSimilarity +------------------------------- +.. py:class:: paddle.nn.CosineSimilarity(axis=1, eps=1e-8) + +**CosineSimilarity** + +计算x1与x2沿axis维度的余弦相似度。 + +参数: + - **axis** (int) - 指定计算的维度,会在该维度上计算余弦相似度,默认值为1。 + - **eps** (float) - 很小的值,防止计算时分母为0,默认值为1e-8。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + np.random.seed(0) + x1 = np.random.rand(2,3) + x2 = np.random.rand(2,3) + x1 = paddle.to_tensor(x1) + x2 = paddle.to_tensor(x2) + + cos_sim_func = nn.CosineSimilarity(axis=0) + result = cos_sim_func(x1, x2) + print(result.numpy()) + # [0.99806249 0.9817672 0.94987036] diff --git a/doc/fluid/api_cn/nn_cn/Dropout2D_cn.rst b/doc/fluid/api_cn/nn_cn/Dropout2D_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..6b04409a2f1632652c58e66fbba82ddd9c851c99 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Dropout2D_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_nn_Dropout2D: + +Dropout2D +------------------------------- + +.. py:function:: paddle.nn.Dropout2D(p=0.5, data_format='NCHW', name=None) + +根据丢弃概率 `p` ,在训练过程中随机将某些通道特征图置0(对一个形状为 `NCHW` 的4维张量,通道特征图指的是其中的形状为 `HW` 的2维特征图)。Dropout2D可以提高通道特征图之间的独立性。论文请参考: `Efficient Object Localization Using Convolutional Networks `_ + +在动态图模式下,请使用模型的 `eval()` 方法切换至测试阶段。 + +.. note:: + 对应的 `functional方法` 请参考: :ref:`cn_api_nn_functional_dropout2d` 。 + +参数 +::::::::: + - **p** (float): 将输入通道置0的概率, 即丢弃概率。默认: 0.5。 + - **data_format** (str): 指定输入的数据格式,输出的数据格式将与输入保持一致,可以是 `NCHW` 和 `NHWC` 。其中 `N` 是批尺寸, `C` 是通道数, `H` 是特征高度, `W` 是特征宽度。默认值: `NCHW` 。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +::::::::: + - **输入** : 4-D `Tensor` 。 + - **输出** : 4-D `Tensor` ,形状与输入相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.random.random(size=(2, 3, 4, 5)).astype('float32') + x = paddle.to_tensor(x) + m = paddle.nn.Dropout2D(p=0.5) + y_train = m(x) + m.eval() # switch the model to test phase + y_test = m(x) + print(x.numpy()) + print(y_train.numpy()) + print(y_test.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/Dropout3D_cn.rst b/doc/fluid/api_cn/nn_cn/Dropout3D_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..56fc7b4fbbe1cd472a6fec368b685668d8808513 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Dropout3D_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_nn_Dropout3D: + +Dropout3D +------------------------------- + +.. py:function:: paddle.nn.Dropout3D(p=0.5, data_format='NCDHW', name=None) + +根据丢弃概率 `p` ,在训练过程中随机将某些通道特征图置0(对一个形状为 `NCDHW` 的5维张量,通道特征图指的是其中的形状为 `DHW` 的3维特征图)。Dropout3D可以提高通道特征图之间的独立性。论文请参考: `Efficient Object Localization Using Convolutional Networks `_ + +在动态图模式下,请使用模型的 `eval()` 方法切换至测试阶段。 + +.. note:: + 对应的 `functional方法` 请参考: :ref:`cn_api_nn_functional_dropout3d` 。 + +参数 +::::::::: + - **p** (float): 将输入通道置0的概率, 即丢弃概率。默认: 0.5。 + - **data_format** (str): 指定输入的数据格式,输出的数据格式将与输入保持一致,可以是 `NCDHW` 和 `NDHWC` 。其中 `N` 是批尺寸, `C` 是通道数, `D` 是特征深度, `H` 是特征高度, `W` 是特征宽度。默认值: `NCDHW` 。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +::::::::: + - **输入** : 5-D `Tensor` 。 + - **输出** : 5-D `Tensor` ,形状与输入相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.random.random(size=(2, 3, 4, 5, 6)).astype('float32') + x = paddle.to_tensor(x) + m = paddle.nn.Dropout3D(p=0.5) + y_train = m(x) + m.eval() # switch the model to test phase + y_test = m(x) + print(x.numpy()) + print(y_train.numpy()) + print(y_test.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/Dropout_cn.rst b/doc/fluid/api_cn/nn_cn/Dropout_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..345de11e7060b6d43b369d6f078cd7c038eb6a46 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Dropout_cn.rst @@ -0,0 +1,55 @@ +.. _cn_api_nn_Dropout: + +Dropout +------------------------------- + +.. py:function:: paddle.nn.Dropout(p=0.5, axis=None, mode="upscale_in_train”, name=None) + +Dropout是一种正则化手段,该算子根据给定的丢弃概率 `p` ,在训练过程中随机将一些神经元输出设置为0,通过阻止神经元节点间的相关性来减少过拟合。论文请参考: `Improving neural networks by preventing co-adaptation of feature detectors `_ + +在动态图模式下,请使用模型的 `eval()` 方法切换至测试阶段。 + +.. note:: + 对应的 `functional方法` 请参考: :ref:`cn_api_nn_functional_dropout` 。 + +参数 +::::::::: + - **p** (float): 将输入节点置为0的概率, 即丢弃概率。默认: 0.5。 + - **axis** (int|list): 指定对输入 `Tensor` 进行Dropout操作的轴。默认: None。 + - **mode** (str): 丢弃单元的方式,有两种'upscale_in_train'和'downscale_in_infer',默认: 'upscale_in_train'。计算方法如下: + + 1. upscale_in_train, 在训练时增大输出结果。 + + - train: out = input * mask / ( 1.0 - p ) + - inference: out = input + + 2. downscale_in_infer, 在预测时减小输出结果 + + - train: out = input * mask + - inference: out = input * (1.0 - p) + + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +::::::::: + - **输入** : N-D `Tensor` 。 + - **输出** : N-D `Tensor` ,形状与输入相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.array([[1,2,3], [4,5,6]]).astype('float32') + x = paddle.to_tensor(x) + m = paddle.nn.Dropout(p=0.5) + y_train = m(x) + m.eval() # switch the model to test phase + y_test = m(x) + print(x.numpy()) + print(y_train.numpy()) + print(y_test.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/ReflectionPad1d_cn.rst b/doc/fluid/api_cn/nn_cn/ReflectionPad1d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..bba4b39464fe5e8bdb4ee0626d912ad8f9e2e858 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReflectionPad1d_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_nn_ReflectionPad1d: + +ReflectionPad1d +------------------------------- +.. py:class:: paddle.nn.ReflectionPad1d(padding, data_format="NCL", name=None) + +**ReflectionPad1d** + +按照 padding 对输入 以reflection模式进行 ``pad``,即填充以输入边界值为轴的映射 。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right]。 + - **data_format** (str) - 指定input的format,可为 `'NCL'` 或者 `'NLC'`,默认值为`'NCL'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 2, 3) + pad = [1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ReflectionPad1d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[2. 1. 2. 3. 2. 1.] + # [5. 4. 5. 6. 5. 4.]]] diff --git a/doc/fluid/api_cn/nn_cn/ReflectionPad2d_cn.rst b/doc/fluid/api_cn/nn_cn/ReflectionPad2d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..35fdb4bc0f2af5d55629ba5cb9f101dd8f3f2150 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReflectionPad2d_cn.rst @@ -0,0 +1,40 @@ +.. _cn_api_nn_ReflectionPad2d: + +ReflectionPad2d +------------------------------- +.. py:class:: paddle.nn.ReflectionPad2d(padding, data_format="NCHW", name=None) + +**ReflectionPad2d** + +按照 padding 对输入 以reflection模式进行 ``pad``,即填充以输入边界值为轴的映射 。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom]。。 + - **data_format** (str) - 指定input的format,可为 `'NCHW'` 或者 `'NHWC'`,默认值为`'NCHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 4, 3) + pad = [1, 0, 1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ReflectionPad2d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[ 5. 4. 5. 6.] + # [ 2. 1. 2. 3.] + # [ 5. 4. 5. 6.] + # [ 8. 7. 8. 9.] + # [11. 10. 11. 12.] + # [ 8. 7. 8. 9.] + # [ 5. 4. 5. 6.]]]] \ No newline at end of file diff --git a/doc/fluid/api_cn/nn_cn/ReplicationPad1d_cn.rst b/doc/fluid/api_cn/nn_cn/ReplicationPad1d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..f919f552020466faf33653f36691e517f29dadf6 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReplicationPad1d_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_nn_ReplicationPad1d: + +ReplicationPad1d +------------------------------- +.. py:class:: paddle.nn.ReplicationPad1d(padding, data_format="NCL", name=None) + +**ReplicationPad1d** + +按照 padding 对输入 以replicate模式进行 ``pad``,即填充输入的边界值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right]。 + - **data_format** (str) - 指定input的format,可为 `'NCL'` 或者 `'NLC'`,默认值为`'NCL'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 2, 3) + pad = [1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ReplicationPad1d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[1. 1. 2. 3. 3. 3.] + # [1. 4. 5. 6. 6. 6.]]] diff --git a/doc/fluid/api_cn/nn_cn/ReplicationPad2d_cn.rst b/doc/fluid/api_cn/nn_cn/ReplicationPad2d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..97b41a220b9ccfe3813cdcfd26029126d4b4be22 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReplicationPad2d_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_nn_ReplicationPad2d: + +ReplicationPad2d +------------------------------- +.. py:class:: paddle.nn.ReplicationPad2d(padding, data_format="NCHW", name=None) + +**ReplicationPad2d** + +按照 padding 对输入 以replicate模式进行 ``pad``,即填充输入的边界值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom]。 + - **data_format** (str) - 指定input的format,可为 `'NCHW'` 或者 `'NHWC'`,默认值为`'NCHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 2, 3) + pad = [1, 0, 1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ReplicationPad2d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[1. 1. 2. 3.] + # [1. 1. 2. 3.] + # [4. 4. 5. 6.] + # [4. 4. 5. 6.] + # [4. 4. 5. 6.]]]] diff --git a/doc/fluid/api_cn/nn_cn/ReplicationPad3d_cn.rst b/doc/fluid/api_cn/nn_cn/ReplicationPad3d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..4d379c21297d0602c97cfeba3f81e06585cc1026 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReplicationPad3d_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_nn_ReplicationPad3d: + +ReplicationPad3d +------------------------------- +.. py:class:: paddle.nn.ReplicationPad3d(padding, data_format="NCDHW", name=None) + +**ReplicationPad3d** + +按照 padding 对输入 以replicate模式进行 ``pad``,即填充输入的边界值。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back]。 + - **data_format** (str) - 指定input的format,可为 `'NCDHW'` 或者 `'NDHWC'`,默认值为`'NCDHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 1, 2, 3) + pad = [1, 0, 1, 2, 0, 0] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ReplicationPad3d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[[1. 1. 2. 3.] + # [1. 1. 2. 3.] + # [4. 4. 5. 6.] + # [4. 4. 5. 6.] + # [4. 4. 5. 6.]]]]] diff --git a/doc/fluid/api_cn/nn_cn/ZeroPad2d_cn.rst b/doc/fluid/api_cn/nn_cn/ZeroPad2d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ed6a69b86fdb93f4172a14d638abd08022910e1b --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ZeroPad2d_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_nn_ZeroPad2d: + +ZeroPad2d +------------------------------- +.. py:class:: paddle.nn.ZeroPad2d(padding, data_format="NCHW", name=None) + +**ZeroPad2d** + +按照 padding 对输入填充固定值0。 + +参数: + - **padding** (Tensor | List[int32]) - 填充大小。pad的格式为[pad_left, pad_right, pad_top, pad_bottom]。 + - **data_format** (str) - 指定input的format,可为 `'NCHW'` 或者 `'NHWC'`,默认值为`'NCHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + input_shape = (1, 1, 2, 3) + pad = [1, 0, 1, 2] + data = np.arange(np.prod(input_shape), dtype=np.float32).reshape(input_shape) + 1 + my_pad = nn.ZeroPad2d(padding=pad) + data = paddle.to_tensor(data) + result = my_pad(data) + print(result.numpy()) + # [[[[0. 0. 0. 0.] + # [0. 1. 2. 3.] + # [0. 4. 5. 6.] + # [0. 0. 0. 0.] + # [0. 0. 0. 0.]]]] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn.rst index 14caa161565ccce2fac5d063fd45f7d68e1d3730..3cab2b771c210c5ee97fa2d371208c4876a591f4 100644 --- a/doc/fluid/api_cn/nn_cn/activation_cn.rst +++ b/doc/fluid/api_cn/nn_cn/activation_cn.rst @@ -11,11 +11,18 @@ activation activation_cn/ELU_cn.rst activation_cn/GELU_cn.rst activation_cn/Hardshrink_cn.rst + activation_cn/Tanh_cn.rst activation_cn/Hardtanh_cn.rst - activation_cn/PRelu_cn.rst - activation_cn/ReLU_cn.rst activation_cn/LeakyReLU_cn.rst - activation_cn/Softmax_cn.rst + activation_cn/LogSigmoid_cn.rst activation_cn/LogSoftmax_cn.rst + activation_cn/PRelu_cn.rst + activation_cn/ReLU_cn.rst + activation_cn/ReLU6_cn.rst + activation_cn/SELU_cn.rst activation_cn/Sigmoid_cn.rst - activation_cn/LogSigmoid_cn.rst + activation_cn/Softmax_cn.rst + activation_cn/Softplus_cn.rst + activation_cn/Softshrink_cn.rst + activation_cn/Softsign_cn.rst + activation_cn/Tanhshrink_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst index 9b9c61818c72a4a8aefcaa356ffd0b0fbf4d81df..62d710903d488957b9360f88a448c4c267212023 100644 --- a/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst +++ b/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst @@ -2,19 +2,25 @@ LeakyReLU ------------------------------- -.. py:class:: paddle.nn.LeakyReLU(alpha=0.01, name=None) +.. py:class:: paddle.nn.LeakyReLU(negative_slope=0.01, name=None) -ReLU (Rectified Linear Unit)激活层 +LeakyReLU 激活层 .. math:: - \\Out = max(x, alpha*x)\\ + LeakyReLU(x)= + \left\{ + \begin{aligned} + &x, & & if \ x >= 0 \\ + &negative\_slope * x, & & otherwise \\ + \end{aligned} + \right. \\ 其中,:math:`x` 为输入的 Tensor 参数 :::::::::: - - alpha (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。 + - negative_slope (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。 - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 形状: @@ -29,8 +35,8 @@ ReLU (Rectified Linear Unit)激活层 import paddle import numpy as np - paddle.enable_imperative() + paddle.disable_static() - lrelu = paddle.nn.LeakyReLU() - x = paddle.imperative.to_variable(np.array([-2, 0, 1], 'float32')) - out = lrelu(x) # [-0.02, 0, 1] + m = paddle.nn.LeakyReLU() + x = paddle.to_tensor(np.array([-2, 0, 1], 'float32')) + out = m(x) # [-0.02, 0., 1.] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/ReLU6_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/ReLU6_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..0ba5f2af0ec631c33f97e3091044309d20906868 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/ReLU6_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_nn_ReLU6: + +ReLU6 +------------------------------- +.. py:class:: paddle.nn.ReLU6(name=None) + +ReLU6激活层 + +.. math:: + + ReLU6(x) = min(max(0,x), 6) + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-1, 0.3, 6.5])) + m = paddle.nn.ReLU6() + out = m(x) # [0, 0.3, 6] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/SELU_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/SELU_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2965c5f304352952dd296d7e7761c32e7b51066d --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/SELU_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_nn_SELU: + +SELU +------------------------------- +.. py:class:: paddle.nn.SELU(scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None) + +SELU激活层 + +.. math:: + + SELU(x) = scale * (max(0,x) + min(0, alpha * (e^{x} - 1))) + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - scale (float, 可选) - SELU激活计算公式中的scale值。默认值为1.0507009873554804934193349852946。 + - alpha (float, 可选) - SELU激活计算公式中的alpha值。默认值为1.6732632423543772848170429916717。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([[0.0, 1.0],[2.0, 3.0]])) + m = paddle.nn.SELU() + out = m(x) # [[0, 1.050701],[2.101402, 3.152103]] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Softplus_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Softplus_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..cce23fcb7046fbdc66eb61a099517077a6378750 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Softplus_cn.rst @@ -0,0 +1,39 @@ +.. _cn_api_nn_Softplus: + +Softplus +------------------------------- +.. py:class:: paddle.nn.Softplus(beta=1, threshold=20, name=None) + +Softplus激活层 + +.. math:: + + Softplus(x) = \frac{1}{beta} * \log(1 + e^{beta * x}) \\ + \text{为了保证数值稳定性, 当}\,beta * x > threshold\,\text{时,函数转变为线性函数x}. + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - beta (float, 可选) - Softplus激活计算公式中的beta值。默认值为1。 + - threshold (float, 可选) - Softplus激活计算公式中的threshold值。默认值为20。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + m = paddle.nn.Softplus() + out = m(x) # [0.513015, 0.598139, 0.744397, 0.854355] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Softshrink_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Softshrink_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d04cf74e560a9176824a324d7ecd340e227b59dc --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Softshrink_cn.rst @@ -0,0 +1,41 @@ +.. _cn_api_nn_Softshrink: + +Softshrink +------------------------------- +.. py:class:: paddle.nn.Softshrink(threshold=0.5, name=None) + +Softshrink激活层 + +.. math:: + + Softshrink(x)= \begin{cases} + x - threshold, \text{if } x > threshold \\ + x + threshold, \text{if } x < -threshold \\ + 0, \text{otherwise} + \end{cases} + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - threshold (float, 可选) - Softshrink激活计算公式中的threshold值,必须大于等于零。默认值为0.5。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.9, -0.2, 0.1, 0.8])) + m = paddle.nn.Softshrink() + out = m(x) # [-0.4, 0, 0, 0.3] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Softsign_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Softsign_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..8029d97d80dc9bcf506bb127fc2499f7564029de --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Softsign_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_nn_Softsign: + +Softsign +------------------------------- +.. py:class:: paddle.nn.Softsign(name=None) + +Softsign激活层 + +.. math:: + + Softsign(x) = \frac{x}{1 + |x|} + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + m = paddle.nn.Softsign() + out = m(x) # [-0.285714, -0.166667, 0.0909091, 0.230769] diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..4f97cdb57f053dd24bca94e945afae7ffa6fd04a --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_nn_Tanh: + +Tanh +------------------------------- +.. py:class:: paddle.nn.Tanh(name=None) + +Tanh激活层 + +.. math:: + Tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} + + +参数 +:::::::::: + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + m = paddle.nn.Tanh() + out = m(x) + print(out.numpy()) + # [-0.37994896 -0.19737532 0.09966799 0.29131261] \ No newline at end of file diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Tanhshrink_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Tanhshrink_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..6c657fd800a7d4a475bb0277df42bf9dfea7eeb2 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Tanhshrink_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_nn_Tanhshrink: + +Tanhshrink +------------------------------- +.. py:class:: paddle.nn.Tanhshrink(name=None) + +Tanhshrink激活层 + +.. math:: + + Tanhshrink(x) = x - tanh(x) + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: +:::::::::: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + m = paddle.nn.Tanhshrink() + out = m(x) # [-0.020051, -0.00262468, 0.000332005, 0.00868739] diff --git a/doc/fluid/api_cn/nn_cn/cosine_similarity_cn.rst b/doc/fluid/api_cn/nn_cn/cosine_similarity_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c2f4109534b5485e5154cc140a1661d94b3945f8 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/cosine_similarity_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_paddle_nn_cosine_similarity: + +cosine_similarity +------------------------------- + +.. py:function:: paddle.nn.functional.cosine_similarity(x1, x2, axis=1, eps=1e-8) + +该OP用于计算x1与x2沿axis维度的余弦相似度。 + +参数: + - **x1** (Tensor) - Tensor,数据类型支持float32, float64。 + - **x2** (Tensor) - Tensor,数据类型支持float32, float64。 + - **axis** (int) - 指定计算的维度,会在该维度上计算余弦相似度,默认值为1。 + - **eps** (float) - 很小的值,防止计算时分母为0,默认值为1e-8。 + + +返回: 余弦相似度的计算结果,数据类型与x1, x2相同。 + +返回类型:Tensor + + + +**代码示例:** + +.. code-block:: python + + import paddle + import paddle.nn as nn + import numpy as np + paddle.disable_static() + + np.random.seed(0) + x1 = np.random.rand(2,3) + x2 = np.random.rand(2,3) + x1 = paddle.to_tensor(x1) + x2 = paddle.to_tensor(x2) + result = paddle.nn.functional.cosine_similarity(x1, x2, axis=0) + print(result.numpy()) + # [0.99806249 0.9817672 0.94987036] + + + diff --git a/doc/fluid/api_cn/nn_cn/functional_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn.rst index 4c87bf387f1eace135aa1b7cb3c94d53ddd45877..e3eccf684050aa4af95fb9e49af20c10d2ecd361 100644 --- a/doc/fluid/api_cn/nn_cn/functional_cn.rst +++ b/doc/fluid/api_cn/nn_cn/functional_cn.rst @@ -8,18 +8,25 @@ functional .. toctree:: :maxdepth: 1 + functional_cn/binary_cross_entropy_cn.rst functional_cn/l1_loss_cn.rst functional_cn/nll_loss_cn.rst functional_cn/normalize_cn.rst functional_cn/margin_ranking_loss_cn.rst + functional_cn/mse_loss_cn.rst + functional_cn/ctc_loss_cn.rst functional_cn/sigmoid_cn.rst - functional_cn/avg_pool2d_cn.rst functional_cn/max_pool2d_cn.rst functional_cn/avg_pool3d_cn.rst functional_cn/max_pool3d_cn.rst - + functional_cn/dropout_cn.rst + functional_cn/dropout2d_cn.rst + functional_cn/dropout3d_cn.rst + functional_cn/alpha_dropout_cn.rst functional_cn/mse_loss_cn.rst functional_cn/adaptive_avg_pool2d_cn.rst functional_cn/adaptive_avg_pool3d_cn.rst functional_cn/sigmoid_cn.rst + functional_cn/cross_entropy_loss_cn.rst + diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/alpha_dropout_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/alpha_dropout_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..cad8c3bb7d12fb6a9f9db481103d8e949ca0c688 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/alpha_dropout_cn.rst @@ -0,0 +1,37 @@ +.. _cn_api_nn_functional_alpha_dropout: + +alpha_dropout +------------------------------- + +.. py:function:: paddle.nn.functional.alpha_dropout(x, p=0.5, training=True, name=None) + +alpha_dropout是一种具有自归一化性质的dropout。均值为0,方差为1的输入,经过alpha_dropout计算之后,输出的均值和方差与输入保持一致。alpha_dropout通常与SELU激活函数组合使用。 + +参数 +::::::::: + - **x** (Tensor): 输入的多维 `Tensor` ,数据类型为:float32、float64。 + - **p** (float): 将输入节点置0的概率,即丢弃概率。默认: 0.5。 + - **training** (bool): 标记是否为训练阶段。 默认: True。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +经过alpha_dropout之后的结果,与输入x形状相同的 `Tensor` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.array([[-1, 1], [-1, 1]]).astype('float32') + x = paddle.to_tensor(x) + y_train = paddle.nn.functional.alpha_dropout(x, 0.5) + y_test = paddle.nn.functional.alpha_dropout(x, 0.5, training=False) + print(x.numpy()) + print(y_train.numpy()) + # [[-0.10721093, 1.6655989 ], [-0.7791938, -0.7791938]] (randomly) + print(y_test.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/binary_cross_entropy_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/binary_cross_entropy_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..11f77916759816ce1ddb451263e3bb42106ee49a --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/binary_cross_entropy_cn.rst @@ -0,0 +1,61 @@ +.. _cn_api_nn_functional_binary_cross_entropy: + +binary_cross_entropy +------------------------------- + +.. py:functional:: paddle.nn.functional.binary_cross_entropy(input, label, weight=None, reduction='mean', name=None) + +该函数用于计算输入 ``input`` 和标签 ``label`` 之间的二值交叉熵损失值。二值交叉熵损失函数公式如下: + +当 `weight` 不为空时,公式为: + +.. math:: + Out = -1 * weight * (label * log(input) + (1 - label) * log(1 - input)) + +当 `weight` 为空时,公式为: + +.. math:: + Out = -1 * (label * log(input) + (1 - label) * log(1 - input)) + +当 `reduction` 为 `none` 时,直接返回最原始的 `Out` 结果。 + +当 `reduction` 为 `mean` 时,最终的输出结果为: + +.. math:: + Out = MEAN(Out) + +当 `reduction` 为 `sum` 时,最终的输出结果为: + +.. math:: + Out = SUM(Out) + + +.. note:: + 输入数据 ``input`` 一般是 ``sigmoid`` 的输出。因为是二分类,所以标签值 ``label`` 应该是0或者1。 + +参数 +::::::::: + - **input** (Tensor) - :math:`[N, *]` , 其中N是batch_size, `*` 是任意其他维度。输入数据 ``input`` 一般是 ``sigmoid`` 的输出。数据类型是float32、float64。 + - **label** (Tensor) - :math:`[N, *]` ,标签 ``label`` 的维度、数据类型与输入 ``input`` 相同。 + - **weight** (Tensor,可选) - 手动指定每个batch二值交叉熵的权重,如果指定的话,维度必须是一个batch的数据的维度。数据类型是float32, float64。默认值是:None。 + - **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `BCELoss` 的均值;设置为 ``'sum'`` 时,计算 `BCELoss` 的总和;设置为 ``'none'`` 时,则返回bce_loss。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: + - 输出的结果Tensor。如果 :attr:`reduction` 是 ``'none'``, 则输出的维度为 :math:`[N, *]` , 与输入 ``input`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出的维度为 :math:`[1]` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + + paddle.disable_static() + input = paddle.to_tensor([0.5, 0.6, 0.7], dtype='float32') + label = paddle.to_tensor([1.0, 0.0, 1.0], dtype='float32') + output = F.binary_cross_entropy(input, label) + print(output.numpy()) # [0.65537095] + diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/cross_entropy_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/cross_entropy_loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3b2bbf0311e59ad86f3279dfb9508198d4c88b77 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/cross_entropy_loss_cn.rst @@ -0,0 +1,51 @@ +.. _cn_api_nn_functional_cross_entropy_loss: + +cross_entropy_loss +------------------------------- +.. py:function:: paddle.nn.functional.cross_entropy_loss(input, label, weight=None, ignore_index=-100, reduction='mean') + +该接口计算输入input和标签label间的交叉熵损失 ,它结合了 `LogSoftmax` 和 `NLLLoss` 的计算,可用于训练一个 `n` 类分类器。 + +如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 每个值对应每个类别的权重。 +该损失函数的数学计算公式如下: + + .. math:: + loss_j = -\text{input[class]} + + \log\left(\sum_{i=0}^{K}\exp(\text{input}_i)\right), j = 1,..., K + +当 `weight` 不为 `none` 时,损失函数的数学计算公式为: + + .. math:: + loss_j = \text{weight[class]}(-\text{input[class]} + + \log\left(\sum_{i=0}^{K}\exp(\text{input}_i)\right)), j = 1,..., K + + +参数 +::::::::: + - **input** (Tensor): - 输入 `Tensor` ,数据类型为float32或float64。其形状为 :math:`[N, C]` , 其中 `C` 为类别数。对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_k]` ,k >= 1。 + - **label** (Tensor): - 输入input对应的标签值,数据类型为int64。其形状为 :math:`[N]` ,每个元素符合条件:0 <= label[i] <= C-1。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k]` ,k >= 1。 + - **weight** (Tensor, 可选): - 指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,维度必须为 `C` (类别数)。数据类型为float32或float64。 + - **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。 + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,数据类型为string,可选值有: `none` , `mean` , `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。 + +返回 +::::::::: + `Tensor` , 返回计算 `cross_entropy_loss` 交叉熵后的损失值。 + + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + paddle.disable_static() + input_data = np.random.random([5, 100]).astype("float64") + label_data = np.random.randint(0, 100, size=(5)).astype(np.int64) + weight_data = np.random.random([100]).astype("float64") + input = paddle.to_tensor(input_data) + label = paddle.to_tensor(label_data) + weight = paddle.to_tensor(weight_data) + loss = paddle.nn.functional.cross_entropy(input=input, label=label, weight=weight) + print(loss.numpy()) + diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/ctc_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/ctc_loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2722525a61feefc4ea1bb3263e7eec0f88462796 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/ctc_loss_cn.rst @@ -0,0 +1,80 @@ +ctc_loss +------------------------------- + +.. py:function:: paddle.nn.functional.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0, reduction='mean') + +该接口用于计算 CTC loss。该接口的底层调用了第三方 baidu-research::warp-ctc 的实现。 +也可以叫做 softmax with CTC,因为 Warp-CTC 库中插入了 softmax 激活函数来对输入的值进行归一化。 + +参数 +::::::::: + - **log_probs** (Tensor): - 经过 padding 的概率序列,其 shape 必须是 [max_logit_length, batch_size, num_classes + 1]。其中 max_logit_length 是最长输入序列的长度。该输入不需要经过 softmax 操作,因为该 OP 的内部对 input 做了 softmax 操作。数据类型仅支持float32。 + - **labels** (Tensor): - 经过 padding 的标签序列,其 shape 为 [batch_size, max_label_length],其中 max_label_length 是最长的 label 序列的长度。数据类型支持int32。 + - **input_lengths** (Tensor): - 表示输入 ``log_probs`` 数据中每个序列的长度,shape为 [batch_size] 。数据类型支持int64。 + - **label_lengths** (Tensor): - 表示 label 中每个序列的长度,shape为 [batch_size] 。数据类型支持int64。 + - **blank** (int,可选): - 空格标记的 ID 值,其取值范围为 [0,num_classes+1) 。数据类型支持int32。默认值为0。 + - **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'``。设置为 ``'mean'`` 时,对 loss 值除以 label_lengths,并返回所得商的均值;设置为 ``'sum'`` 时,返回 loss 值的总和;设置为 ``'none'`` 时,则直接返回输出的 loss 值。默认值为 ``'mean'``。 + +返回 +::::::::: +``Tensor``,输入 ``log_probs`` 和标签 ``labels`` 间的 `ctc loss`。如果 :attr:`reduction` 是 ``'none'``, 则输出 loss 的维度为 [batch_size]。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``,则输出Loss的维度为 [1]。数据类型与输入 ``log_probs`` 一致。 + + +代码示例 +::::::::: + +.. code-block:: python + + # declarative mode + import paddle.nn.functional as F + import numpy as np + import paddle + + # length of the longest logit sequence + max_seq_length = 4 + #length of the longest label sequence + max_label_length = 3 + # number of logit sequences + batch_size = 2 + # class num + class_num = 3 + + np.random.seed(1) + log_probs = np.array([[[4.17021990e-01, 7.20324516e-01, 1.14374816e-04], + [3.02332580e-01, 1.46755889e-01, 9.23385918e-02]], + + [[1.86260208e-01, 3.45560730e-01, 3.96767467e-01], + [5.38816750e-01, 4.19194520e-01, 6.85219526e-01]], + + [[2.04452246e-01, 8.78117442e-01, 2.73875929e-02], + [6.70467496e-01, 4.17304814e-01, 5.58689833e-01]], + + [[1.40386939e-01, 1.98101491e-01, 8.00744593e-01], + [9.68261600e-01, 3.13424170e-01, 6.92322612e-01]], + + [[8.76389146e-01, 8.94606650e-01, 8.50442126e-02], + [3.90547849e-02, 1.69830427e-01, 8.78142476e-01]]]).astype("float32") + labels = np.array([[1, 2, 2], + [1, 2, 2]]).astype("int32") + input_lengths = np.array([5, 5]).astype("int64") + label_lengths = np.array([3, 3]).astype("int64") + + paddle.disable_static() + log_probs = paddle.to_tensor(log_probs) + labels = paddle.to_tensor(labels) + input_lengths = paddle.to_tensor(input_lengths) + label_lengths = paddle.to_tensor(label_lengths) + + loss = F.ctc_loss(log_probs, labels, + input_lengths, + label_lengths, + blank=0, + reduction='none') + print(loss.numpy()) #[3.9179852 2.9076521] + + loss = F.ctc_loss(log_probs, labels, + input_lengths, + label_lengths, + blank=0, + reduction='mean') + print(loss.numpy()) #[1.1376063] \ No newline at end of file diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/dropout2d_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/dropout2d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..35c61c137a4842bc17f7c43eea4eb14d3a595e81 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/dropout2d_cn.rst @@ -0,0 +1,41 @@ +.. _cn_api_nn_functional_dropout2d: + +dropout2d +------------------------------- + +.. py:function:: paddle.nn.functional.dropout2d(x, p=0.5, training=True, name=None) + +该算子根据丢弃概率 `p` ,在训练过程中随机将某些通道特征图置0(对一个形状为 `NCHW` 的4维张量,通道特征图指的是其中的形状为 `HW` 的2维特征图)。 + +.. note:: + 该op基于 ``paddle.nn.functional.dropout`` 实现,如您想了解更多,请参见 :ref:`cn_api_nn_functional_dropout` 。 + +参数 +::::::::: + - **x** (Tensor): 形状为[N, C, H, W]或[N, H, W, C]的4D `Tensor` ,数据类型为float32或float64。 + - **p** (float): 将输入通道置0的概率,即丢弃概率。默认: 0.5。 + - **training** (bool): 标记是否为训练阶段。 默认: True。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +经过dropout2d之后的结果,与输入x形状相同的 `Tensor` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.random.random(size=(2, 3, 4, 5)).astype('float32') + x = paddle.to_tensor(x) + y_train = paddle.nn.functional.dropout2d(x) #train + y_test = paddle.nn.functional.dropout2d(x, training=False) + for i in range(2): + for j in range(3): + print(x.numpy()[i,j,:,:]) + print(y_train.numpy()[i,j,:,:]) + print(y_test.numpy()[i,j,:,:]) diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/dropout3d_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/dropout3d_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..0fc0ab0ee6a5cf37b81319673b9db8c1c131081c --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/dropout3d_cn.rst @@ -0,0 +1,39 @@ +.. _cn_api_nn_functional_dropout3d: + +dropout3d +------------------------------- + +.. py:function:: paddle.nn.functional.dropout3d(x, p=0.5, training=True, name=None) + +该算子根据丢弃概率 `p` ,在训练过程中随机将某些通道特征图置0(对一个形状为 `NCDHW` 的5维张量,通道指的是其中的形状为 `DHW` 的3维特征图)。 + +.. note:: + 该op基于 ``paddle.nn.functional.dropout`` 实现,如您想了解更多,请参见 :ref:`cn_api_nn_functional_dropout` 。 + +参数 +::::::::: + - **x** (Tensor): 形状为[N, C, D, H, W]或[N, D, H, W, C]的5D `Tensor` ,数据类型为float32或float64。 + - **p** (float): 将输入通道置0的概率,即丢弃概率。默认: 0.5。 + - **training** (bool): 标记是否为训练阶段。 默认: True。 + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +经过dropout3d之后的结果,与输入x形状相同的 `Tensor` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.random.random(size=(2, 3, 4, 5, 6)).astype('float32') + x = paddle.to_tensor(x) + y_train = paddle.nn.functional.dropout3d(x) #train + y_test = paddle.nn.functional.dropout3d(x, training=False) + print(x.numpy()[0,0,:,:,:]) + print(y_train.numpy()[0,0,:,:,:]) + print(y_test.numpy()[0,0,:,:,:]) diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/dropout_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/dropout_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..a349e66aeb5471ffe5810e2c5fe480d8f736515e --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/dropout_cn.rst @@ -0,0 +1,134 @@ +.. _cn_api_nn_functional_dropout: + +dropout +------------------------------- + +.. py:function:: paddle.nn.functional.dropout(x, p=0.5, axis=None, training=True, mode="upscale_in_train”, name=None) + +Dropout是一种正则化手段,该算子根据给定的丢弃概率 `p` ,在训练过程中随机将一些神经元输出设置为0,通过阻止神经元节点间的相关性来减少过拟合。 + +参数 +::::::::: + - **x** (Tensor): 输入的多维 `Tensor` ,数据类型为:float32、float64。 + - **p** (float): 将输入节点置0的概率,即丢弃概率。默认: 0.5。 + - **axis** (int|list): 指定对输入 `Tensor` 进行dropout操作的轴。默认: None。 + - **training** (bool): 标记是否为训练阶段。 默认: True。 + - **mode** (str): 丢弃单元的方式,有两种'upscale_in_train'和'downscale_in_infer',默认: 'upscale_in_train'。计算方法如下: + + 1. upscale_in_train, 在训练时增大输出结果。 + + - train: out = input * mask / ( 1.0 - p ) + - inference: out = input + + 2. downscale_in_infer, 在预测时减小输出结果 + + - train: out = input * mask + - inference: out = input * (1.0 - p) + + - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +经过dropout之后的结果,与输入x形状相同的 `Tensor` 。 + +使用示例1 +::::::::: +axis参数的默认值为None。当 ``axis=None`` 时,dropout的功能为: 对输入张量x中的任意元素,以丢弃概率p随机将一些元素输出置0。这是我们最常见的dropout用法。 + + - 下面以一个示例来解释它的实现逻辑,同时展示其它参数的含义。 + +.. code-block:: text + + 假定x是形状为2*3的2维张量: + [[1 2 3] + [4 5 6]] + 在对x做dropout时,程序会先生成一个和x相同形状的mask张量,mask中每个元素的值为0或1。 + 每个元素的具体值,则是依据丢弃概率从伯努利分布中随机采样得到。 + 比如,我们可能得到下面这样一个2*3的mask: + [[0 1 0] + [1 0 1]] + 将输入x和生成的mask点积,就得到了随机丢弃部分元素之后的结果: + [[0 2 0] + [4 0 6]] + 假定dropout的概率使用默认值,即 ``p=0.5`` ,若mode参数使用默认值,即 ``mode='upscale_in_train'`` , + 则在训练阶段,最终增大后的结果为: + [[0 4 0 ] + [8 0 12]] + 在测试阶段,输出跟输入一致: + [[1 2 3] + [4 5 6]] + 若参数mode设置为'downscale_in_infer',则训练阶段的输出为: + [[0 2 0] + [4 0 6]] + 在测试阶段,缩小后的输出为: + [[0.5 1. 1.5] + [2. 2.5 3. ]] + +使用示例2 +::::::::: +若参数axis不为None,dropout的功能为:以一定的概率从图像特征或语音序列中丢弃掉整个通道。 + + - axis应设置为: ``[0,1,...,ndim(x)-1]`` 的子集(ndim(x)为输入x的维度),例如: + + - 若x的维度为2,参数axis可能的取值有4种: ``None``, ``[0]``, ``[1]``, ``[0,1]`` + - 若x的维度为3,参数axis可能的取值有8种: ``None``, ``[0]``, ``[1]``, ``[2]``, ``[0,1]``, ``[0,2]``, ``[1,2]``, ``[0,1,2]`` + + - 下面以维度为2的输入张量展示axis参数的用法: + +.. code-block:: text + + 假定x是形状为2*3的2维Tensor: + [[1 2 3] + [4 5 6]] + (1) 若 ``axis=[0]`` , 则表示只在第0个维度做dropout。这时生成mask的形状为2*1。 + 例如,我们可能会得到这样的mask: + [[1] + [0]] + 这个2*1的mask在和x做点积的时候,会首先广播成一个2*3的矩阵: + [[1 1 1] + [0 0 0]] + 点积所得的结果为: + [[1 2 3] + [0 0 0]] + 之后依据其它参数的设置,得到最终的输出结果。 + + (2) 若 ``axis=[1]`` ,则表示只在第1个维度做dropout。这时生成的mask形状为1*3。 + 例如,我们可能会得到这样的mask: + [[1 0 1]] + 这个1*3的mask在和x做点积的时候,会首先广播成一个2*3的矩阵: + [[1 0 1] + [1 0 1]] + 点积所得结果为: + [[1 0 3] + [4 0 6]] + (3) 若 ``axis=[0, 1]`` ,则表示在第0维和第1维上做dropout。此时与默认设置 ``axis=None`` 的作用一致。 + +若输入x为4维张量,形状为 `NCHW` , 当设置 ``axis=[0,1]`` 时,则只会在通道 `N` 和 `C` 上做dropout,通道 `H` 和 `W` 的元素是绑定在一起的,即: ``paddle.nn.functional.dropout(x, p, axis=[0,1])`` , 此时对4维张量中的某个2维特征图(形状 `HW` ),或者全部置0,或者全部保留,这便是dropout2d的实现。详情参考 :ref:`cn_api_nn_functional_dropout2d` 。 + +类似的,若输入x为5维张量,形状为 `NCDHW` , 当设置 ``axis=[0,1]`` 时,便可实现dropout3d。详情参考 :ref:`cn_api_nn_functional_dropout3d` 。 + +.. note:: + 关于广播(broadcasting)机制,如您想了解更多,请参见 :ref:`cn_user_guide_broadcasting` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.array([[1,2,3], [4,5,6]]).astype('float32') + x = paddle.to_tensor(x) + y_train = paddle.nn.functional.dropout(x, 0.5) + y_test = paddle.nn.functional.dropout(x, 0.5, training=False) #test + y_0 = paddle.nn.functional.dropout(x, axis=0) + y_1 = paddle.nn.functional.dropout(x, axis=1) + y_01 = paddle.nn.functional.dropout(x, axis=[0,1]) + print(x.numpy()) + print(y_train.numpy()) + print(y_test.numpy()) + print(y_0.numpy()) + print(y_1.numpy()) + print(y_01.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst b/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst index cb837884b4213834e11c41390a5da07a6c47079b..66c492e749c5992f8f86bd06c6d521330b67c7ac 100644 --- a/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst +++ b/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst @@ -2,7 +2,7 @@ hardshrink ------------------------------- -.. py:functional:: paddle.nn.functional.hardshrink(x, threshold=0.5, name=None) +.. py:function:: paddle.nn.functional.hardshrink(x, threshold=0.5, name=None) hardshrink激活层。计算公式如下: diff --git a/doc/fluid/api_cn/nn_cn/layer_cn.rst b/doc/fluid/api_cn/nn_cn/layer_cn.rst index af4ec612d7702c8635aa07008ba4a84ba6b49cd6..357167c5276d083feea6a8e5c381dfeb4e33a395 100644 --- a/doc/fluid/api_cn/nn_cn/layer_cn.rst +++ b/doc/fluid/api_cn/nn_cn/layer_cn.rst @@ -1,11 +1,7 @@ -======================= -layer -======================= +.. _cn_api_nn_cn_Layer: +Layer +------------------------------- +:doc_source: paddle.fluid.dygraph.layers.Layer - -.. toctree:: - :maxdepth: 1 - - layer_cn/Sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/leaky_relu_cn.rst b/doc/fluid/api_cn/nn_cn/leaky_relu_cn.rst index 11eff19254013ef32b7d3b13c975bcea522fe465..a0bb19d6ec7f383294f7943389fdd962a6d94bbb 100644 --- a/doc/fluid/api_cn/nn_cn/leaky_relu_cn.rst +++ b/doc/fluid/api_cn/nn_cn/leaky_relu_cn.rst @@ -2,6 +2,42 @@ leaky_relu ------------------------------- -:doc_source: paddle.fluid.layers.leaky_relu +.. py:function:: paddle.nn.functional.leaky_relu(x, negative_slope=0.01, name=None) +leaky_relu激活层。计算公式如下: +.. math:: + + LeakyReLU(x)= + \left\{ + \begin{aligned} + &x, & & if \ x >= 0 \\ + &negative\_slope * x, & & otherwise \\ + \end{aligned} + \right. \\ + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。 + - negative_slope (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-2, 0, 1], 'float32')) + out = F.leaky_relu(x) # [-0.02, 0., 1.] diff --git a/doc/fluid/api_cn/nn_cn/loss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn.rst index c463d12c463c9a0b686687a3cf09f4b66b44759a..1ec2a89a9b689e20f8fef6dc09f7213ccb3d8c54 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn.rst @@ -14,3 +14,4 @@ loss loss_cn/MarginRankingLoss_cn.rst loss_cn/MSELoss_cn.rst loss_cn/NLLLoss_cn.rst + loss_cn/CTCLoss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst index 78cd4fb635e65cfb216a37e83679650e0f88197d..0231b6eb5a19db9448376be8f7106dfe083604b7 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst @@ -3,9 +3,9 @@ BCELoss ------------------------------- -.. py:function:: paddle.nn.BCELoss(input, label, weight=None, reduction='mean') +.. py:class:: paddle.nn.BCELoss(weight=None, reduction='mean', name=None) -该接口用于创建一个BCELoss的可调用类,用于计算输入和标签之间的二值交叉熵损失值。二值交叉熵损失函数公式如下: +该接口用于创建一个BCELoss的可调用类,用于计算输入 ``input`` 和标签 ``label`` 之间的二值交叉熵损失值。二值交叉熵损失函数公式如下: 当 `weight` 不为空时,公式为: @@ -17,12 +17,9 @@ BCELoss .. math:: Out = -1 * (label * log(input) + (1 - label) * log(1 - input)) -当 `reduction` 为 `none` 时,最终的输出结果为: +当 `reduction` 为 `none` 时,直接返回最原始的 `Out` 结果。 -.. math:: - Out = Out - -当 `reduction` 为 `sum` 时,最终的输出结果为: +当 `reduction` 为 `mean` 时,最终的输出结果为: .. math:: Out = MEAN(Out) @@ -33,47 +30,36 @@ BCELoss Out = SUM(Out) -**注意:输入数据一般是 `fluid.layers.sigmoid` 的输出。因为是二分类,所以标签值应该是0或者1。 +.. note:: + 输入数据 ``input`` 一般是 ``sigmoid`` 的输出。因为是二分类,所以标签值 ``label`` 应该是0或者1。 -输入input和标签label的维度是[N, *], 其中N是batch_size, `*` 是任意其他维度。 -如果 :attr:`reduction` 是 ``'none'``, 则输出的维度为 [N, *], 与输入input的形状相同。 -如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出的维度为 [1]。 +参数 +::::::::: + - **weight** (Tensor,可选) - 手动指定每个batch二值交叉熵的权重,如果指定的话,维度必须是一个batch的数据的维度。数据类型是float32, float64。默认值是:None。 + - **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `BCELoss` 的均值;设置为 ``'sum'`` 时,计算 `BCELoss` 的总和;设置为 ``'none'`` 时,则返回bce_loss。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 -参数: - - **weight(Variable, optional)**:- 手动指定每个batch二值交叉熵的权重,如果指定的话,维度必须是一个batch的数据的维度。数据类型是float32, float64。默认是:None。 - - **reduction(str, optional)**:- 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `BCELoss` 的均值;设置为 ``'sum'`` 时,计算 `BCELoss` 的总和;设置为 ``'none'`` 时,则返回BCELoss。 +形状 +::::::::: + - **input** (Tensor) - :math:`(N, *)` , 其中N是batch_size, `*` 是任意其他维度。输入数据 ``input`` 一般是 ``sigmoid`` 的输出。数据类型是float32、float64。 + - **label** (Tensor) - :math:`(N, *)` ,标签 ``label`` 的维度、数据类型与输入 ``input`` 相同。 + - **output** (Tensor) - 输出的Tensor。如果 :attr:`reduction` 是 ``'none'``, 则输出的维度为 :math:`(N, *)` , 与输入 ``input`` 的形状相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出的维度为 :math:`[1]` 。 -返回:返回计算BCELoss的可调用对象。 +返回 +::::::::: + 返回计算BCELoss的可调用对象。 -**代码示例** +代码示例 +:::::::::: .. code-block:: python - # declarative mode - import paddle.fluid as fluid - import numpy as np import paddle - input = fluid.data(name="input", shape=[3, 1], dtype='float32') - label = fluid.data(name="label", shape=[3, 1], dtype='float32') + + paddle.disable_static() + input = paddle.to_tensor([0.5, 0.6, 0.7], dtype='float32') + label = paddle.to_tensor([1.0, 0.0, 1.0], dtype='float32') bce_loss = paddle.nn.loss.BCELoss() output = bce_loss(input, label) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) - - input_data = np.array([0.5, 0.6, 0.7]).astype("float32") - label_data = np.array([1.0, 0.0, 1.0]).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.65537095], 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) - output = bce_loss(input, label) - print(output.numpy()) # [0.65537095] + print(output.numpy()) # [0.65537095] + diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/CTCLoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/CTCLoss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..a2ad0c28a4058d8cbdfc447b9f890e0ce9d24185 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/loss_cn/CTCLoss_cn.rst @@ -0,0 +1,78 @@ +CTCLoss +------------------------------- + +.. py:class:: paddle.nn.loss.CTCLoss(blank=0, reduction='mean') + +该接口用于计算 CTC loss。该接口的底层调用了第三方 baidu-research::warp-ctc 的实现。 +也可以叫做 softmax with CTC,因为 Warp-CTC 库中插入了 softmax 激活函数来对输入的值进行归一化。 + +参数 +::::::::: + - **blank** (int,可选): - 空格标记的 ID 值,其取值范围为 [0,num_classes+1) 。数据类型支持int32。默认值为0。 + - **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。设置为 ``'mean'`` 时,对 loss 值除以 label_lengths,并返回所得商的均值;设置为 ``'sum'`` 时,返回 loss 值的总和;设置为 ``'none'`` 时,则直接返回输出的 loss 值。默认值为 ``'mean'``。 + +形状 +::::::::: + - **log_probs** (Tensor): - 经过 padding 的概率序列,其 shape 必须是 [max_logit_length, batch_size, num_classes + 1]。其中 max_logit_length 是最长输入序列的长度。该输入不需要经过 softmax 操作,因为该 OP 的内部对 input 做了 softmax 操作。数据类型仅支持float32。 + - **labels** (Tensor): - 经过 padding 的标签序列,其 shape 为 [batch_size, max_label_length],其中 max_label_length 是最长的 label 序列的长度。数据类型支持int32。 + - **input_lengths** (Tensor): - 表示输入 ``log_probs`` 数据中每个序列的长度,shape为 [batch_size] 。数据类型支持int64。 + - **label_lengths** (Tensor): - 表示 label 中每个序列的长度,shape为 [batch_size] 。数据类型支持int64。 + +返回 +::::::::: +``Tensor``,输入 ``log_probs`` 和标签 ``labels`` 间的 `ctc loss`。如果 :attr:`reduction` 是 ``'none'``,则输出 loss 的维度为 [batch_size]。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。数据类型与输入 ``log_probs`` 一致。 + +代码示例 +::::::::: + +.. code-block:: python + + # declarative mode + import numpy as np + import paddle + + # length of the longest logit sequence + max_seq_length = 4 + #length of the longest label sequence + max_label_length = 3 + # number of logit sequences + batch_size = 2 + # class num + class_num = 3 + + np.random.seed(1) + log_probs = np.array([[[4.17021990e-01, 7.20324516e-01, 1.14374816e-04], + [3.02332580e-01, 1.46755889e-01, 9.23385918e-02]], + + [[1.86260208e-01, 3.45560730e-01, 3.96767467e-01], + [5.38816750e-01, 4.19194520e-01, 6.85219526e-01]], + + [[2.04452246e-01, 8.78117442e-01, 2.73875929e-02], + [6.70467496e-01, 4.17304814e-01, 5.58689833e-01]], + + [[1.40386939e-01, 1.98101491e-01, 8.00744593e-01], + [9.68261600e-01, 3.13424170e-01, 6.92322612e-01]], + + [[8.76389146e-01, 8.94606650e-01, 8.50442126e-02], + [3.90547849e-02, 1.69830427e-01, 8.78142476e-01]]]).astype("float32") + labels = np.array([[1, 2, 2], + [1, 2, 2]]).astype("int32") + input_lengths = np.array([5, 5]).astype("int64") + label_lengths = np.array([3, 3]).astype("int64") + + paddle.disable_static() + log_probs = paddle.to_tensor(log_probs) + labels = paddle.to_tensor(labels) + input_lengths = paddle.to_tensor(input_lengths) + label_lengths = paddle.to_tensor(label_lengths) + + loss = paddle.nn.CTCLoss(blank=0, reduction='none')(log_probs, labels, + input_lengths, + label_lengths) + print(loss.numpy()) #[3.9179852 2.9076521] + + loss = paddle.nn.CTCLoss(blank=0, reduction='mean')(log_probs, labels, + input_lengths, + label_lengths) + print(loss.numpy()) #[1.1376063] + diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst index 5e85d3a50dba92772a068ee8dc0e0beaaf3ddc73..0535e8690f6902f24fb31e39fa06d61bf4c88117 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst @@ -1,9 +1,11 @@ +.. _cn_api_nn_loss_CrossEntropyLoss: + CrossEntropyLoss ------------------------------- -.. py:function:: paddle.nn.loss.CrossEntropyLoss(weight=None, reduction='mean', ignore_index=-100) +.. py:function:: paddle.nn.loss.CrossEntropyLoss(weight=None, ignore_index=-100, reduction='mean') -该OP计算输入input和标签label间的交叉熵损失 ,它结合了`LogSoftmax` 和 `NLLLoss` 的OP计算,可用于训练一个 `n` 类分类器。 +该OP计算输入input和标签label间的交叉熵损失 ,它结合了 `LogSoftmax` 和 `NLLLoss` 的OP计算,可用于训练一个 `n` 类分类器。 如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 每个值对应每个类别的权重。 该损失函数的数学计算公式如下: @@ -19,48 +21,34 @@ CrossEntropyLoss \log\left(\sum_{i=0}^{K}\exp(\text{input}_i)\right)), j = 1,..., K -参数: - - **input** (Variable): - 输入 `Tensor`,数据类型为float32或float64。其形状为 :math:`[N, C]` , 其中 `C` 为类别数。对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_k]`,k >= 1。 - - **label** (Variable): - 输入input对应的标签值,数据类型为int64。其形状为 :math:`[N]`,每个元素符合条件:0 <= label[i] <= C-1。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k]`,k >= 1。 - - **weight** (Variable, 可选): - 指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,维度必须为 `C`(类别数)。数据类型为float32或float64。 - - **reduction** (string, 可选): - 指定应用于输出结果的计算方式,数据类型为string,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。 +参数 +::::::::: + - **weight** (Tensor, 可选): - 指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,维度必须为 `C` (类别数)。数据类型为float32或float64。 - **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。 + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,数据类型为string,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。 -返回:返回计算 `CrossEntropyLoss` 交叉熵后的损失值。 +形状 +::::::::: + - **input** (Tensor): - 输入 `Tensor` ,数据类型为float32或float64。其形状为 :math:`[N, C]` , 其中 `C` 为类别数。对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_k]` ,k >= 1。 + - **label** (Tensor): - 输入input对应的标签值,数据类型为int64。其形状为 :math:`[N]` ,每个元素符合条件:0 <= label[i] <= C-1。对于多维度的情形下,它的形状为 :math:`[N, d_1, d_2, ..., d_k]` ,k >= 1。 + - **output** (Tensor): - 计算 `CrossEntropyLoss` 交叉熵后的损失值。 -返回类型:Variable -**代码示例** +代码示例 +::::::::: .. code-block:: python - # declarative mode import paddle - import paddle.fluid as fluid import numpy as np - input = fluid.data(name='input', shape=[5, 100], dtype='float64') - label = fluid.data(name='label', shape=[5], dtype='int64') - weight = fluid.data(name='weight', shape=[100], dtype='float64') - ce_loss = paddle.nn.loss.CrossEntropyLoss(weight=weight, reduction='mean') - output = ce_loss(input, label) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) + paddle.disable_static() input_data = np.random.random([5, 100]).astype("float64") label_data = np.random.randint(0, 100, size=(5)).astype(np.int64) weight_data = np.random.random([100]).astype("float64") - output = exe.run(fluid.default_main_program(), - feed={"input": input_data, "label": label_data,"weight": weight_data}, - fetch_list=[output], - return_numpy=True) - print(output) - # 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) - weight = dg.to_variable(weight_data) - ce_loss = paddle.nn.loss.CrossEntropyLoss(weight=weight, reduction='mean') - output = ce_loss(input, label) - print(output.numpy()) + input = paddle.to_tensor(input_data) + label = paddle.to_tensor(label_data) + weight = paddle.to_tensor(weight_data) + ce_loss = paddle.nn.loss.CrossEntropyLoss(weight=weight, reduction='mean') + output = ce_loss(input, label) + print(output.numpy()) diff --git a/doc/fluid/api_cn/nn_cn/pad_cn.rst b/doc/fluid/api_cn/nn_cn/pad_cn.rst index 93c135ecfa084a032269bc99154b1c095a452c5a..d4d7b998b550be9cf85b9c02ab2e05b6414a68fe 100644 --- a/doc/fluid/api_cn/nn_cn/pad_cn.rst +++ b/doc/fluid/api_cn/nn_cn/pad_cn.rst @@ -2,6 +2,96 @@ pad ------------------------------- -:doc_source: paddle.fluid.layers.pad + +.. py:function:: paddle.nn.functional.pad(x, pad, mode="constant", value=0.0, data_format="NCHW", name=None) + +该OP依照 pad 和 mode 属性对input进行 ``pad`` 。 + +参数: + - **x** (Tensor) - Tensor,format可以为 `'NCL'`, `'NLC'`, `'NCHW'`, `'NHWC'`, `'NCDHW'` + 或 `'NDHWC'`,默认值为`'NCHW'`,数据类型支持float16, float32, float64, int32, int64。 + - **pad** (Tensor | List[int32]) - 填充大小。当输入维度为3时,pad的格式为[pad_left, pad_right]; + 当输入维度为4时,pad的格式为[pad_left, pad_right, pad_top, pad_bottom]; + 当输入维度为5时,pad的格式为[pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back]。 + - **mode** (str) - padding的四种模式,分别为 `'constant'`, `'reflect'`, `'replicate'` 和`'circular'`。 + `'constant'` 表示填充常数 `value`;`'reflect'` 表示填充以input边界值为轴的映射;`'replicate'` 表示 + 填充input边界值;`'circular'`为循环填充input。具体结果可见以下示例。默认值为 `'constant'` 。 + - **value** (float32) - 以 `'constant'` 模式填充区域时填充的值。默认值为0.0。 + - **data_format** (str) - 指定input的format,可为 `'NCL'`, `'NLC'`, `'NCHW'`, `'NHWC'`, `'NCDHW'` + 或 `'NDHWC'`,默认值为`'NCHW'`。 + - **name** (str, 可选) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,缺省值为None。 +返回: 对input进行``pad`` 的结果,数据类型和input相同。 + +返回类型:Tensor + +**示例**: + +.. code-block:: text + + x = [[[[[1., 2., 3.], + [4., 5., 6.]]]]] + + Case 0: + pad = [2, 2, 1, 1, 0, 0], + mode = 'constant' + pad_value = 0 + Out = [[[[[0. 0. 0. 0. 0. 0. 0.] + [0. 0. 1. 2. 3. 0. 0.] + [0. 0. 4. 5. 6. 0. 0.] + [0. 0. 0. 0. 0. 0. 0.]]]]] + + Case 1: + pad = [2, 2, 1, 1, 0, 0], + mode = 'reflect' + Out = [[[[[6. 5. 4. 5. 6. 5. 4.] + [3. 2. 1. 2. 3. 2. 1.] + [6. 5. 4. 5. 6. 5. 4.] + [3. 2. 1. 2. 3. 2. 1.]]]]] + + Case 2: + pad = [2, 2, 1, 1, 0, 0], + mode = 'replicate' + Out = [[[[[1. 1. 1. 2. 3. 3. 3.] + [1. 1. 1. 2. 3. 3. 3.] + [4. 4. 4. 5. 6. 6. 6.] + [4. 4. 4. 5. 6. 6. 6.]]]]] + + Case 3: + pad = [2, 2, 1, 1, 0, 0], + mode = 'circular' + Out = [[[[[5. 6. 4. 5. 6. 4. 5.] + [2. 3. 1. 2. 3. 1. 2.] + [5. 6. 4. 5. 6. 4. 5.] + [2. 3. 1. 2. 3. 1. 2.]]]]] + +**代码示例:** + +.. code-block:: python + + import numpy as np + import paddle + import paddle.nn.functional as F + + paddle.disable_static() + + # example 1 + x_shape = (1, 1, 3) + x = np.arange(np.prod(x_shape), dtype=np.float32).reshape(x_shape) + 1 + tensor_x = paddle.to_tensor(x) + y = F.pad(tensor_x, [2, 3], value=1, mode='constant') + print(y.numpy()) + # [[[1. 1. 1. 2. 3. 1. 1. 1.]]] + + # example 2 + x_shape = (1, 1, 2, 3) + x = np.arange(np.prod(x_shape), dtype=np.float32).reshape(x_shape) + 1 + tensor_x = paddle.to_tensor(x) + y = F.pad(tensor_x, [1, 2, 1, 1], value=1, mode='circular') + print(y.numpy()) + # [[[[6. 4. 5. 6. 4. 5.] + # [3. 1. 2. 3. 1. 2.] + # [6. 4. 5. 6. 4. 5.] + # [3. 1. 2. 3. 1. 2.]]]] + diff --git a/doc/fluid/api_cn/nn_cn/relu6_cn.rst b/doc/fluid/api_cn/nn_cn/relu6_cn.rst index f1398c5acc7d33c3e1815f27bd5a2327dfcc91f3..b4c98f8fce5e63674f35bda7951018e9eb2d1fa7 100644 --- a/doc/fluid/api_cn/nn_cn/relu6_cn.rst +++ b/doc/fluid/api_cn/nn_cn/relu6_cn.rst @@ -2,6 +2,36 @@ relu6 ------------------------------- -:doc_source: paddle.fluid.layers.relu6 +.. py:function:: paddle.nn.functional.relu6(x, name=None) +relu6激活层 + +.. math:: + + relu6(x) = min(max(0,x), 6) + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-1, 0.3, 6.5])) + out = F.relu6(x) # [0, 0.3, 6] diff --git a/doc/fluid/api_cn/nn_cn/selu_cn.rst b/doc/fluid/api_cn/nn_cn/selu_cn.rst index 37ed03e2989d9cc1dcdedb037e67a4a08a25f8f6..ad02b2dfd8c5ce1766d3a019332bf1b17251a4bf 100644 --- a/doc/fluid/api_cn/nn_cn/selu_cn.rst +++ b/doc/fluid/api_cn/nn_cn/selu_cn.rst @@ -2,6 +2,38 @@ selu ------------------------------- -:doc_source: paddle.fluid.layers.selu +.. py:function:: paddle.nn.functional.selu(x, scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None) +selu激活层 + +.. math:: + + selu(x) = scale * (max(0,x) + min(0, alpha * (e^{x} - 1))) + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - scale (float, 可选) - selu激活计算公式中的scale值。默认值为1.0507009873554804934193349852946。 + - alpha (float, 可选) - selu激活计算公式中的alpha值。默认值为1.6732632423543772848170429916717。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([[0.0, 1.0],[2.0, 3.0]])) + out = F.selu(x) # [[0, 1.050701],[2.101402, 3.152103]] diff --git a/doc/fluid/api_cn/nn_cn/softplus_cn.rst b/doc/fluid/api_cn/nn_cn/softplus_cn.rst index 6ed70778d1a68e3d1093936928b830bd8a5d86b2..dabf852e2ade608c739fa9e0900935132c7b7b2d 100644 --- a/doc/fluid/api_cn/nn_cn/softplus_cn.rst +++ b/doc/fluid/api_cn/nn_cn/softplus_cn.rst @@ -2,6 +2,39 @@ softplus ------------------------------- -:doc_source: paddle.fluid.layers.softplus +.. py:function:: paddle.nn.functional.softplus(x, beta=1, threshold=20, name=None) +softplus激活层 + +.. math:: + + softplus(x) = \frac{1}{beta} * \log(1 + e^{beta * x}) \\ + \text{为了保证数值稳定性, 当}\,beta * x > threshold\,\text{时,函数转变为线性函数x}. + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - beta (float, 可选) - Softplus激活计算公式中的beta值。默认值为1。 + - threshold (float, 可选) - Softplus激活计算公式中的threshold值。默认值为20。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + out = F.softplus(x) # [0.513015, 0.598139, 0.744397, 0.854355] diff --git a/doc/fluid/api_cn/nn_cn/softshrink_cn.rst b/doc/fluid/api_cn/nn_cn/softshrink_cn.rst index e824fe2153825e98f7a1de44e398ba7ef7d5ca9a..d630a80d553919f7814247ac5b6049b1f3146f84 100644 --- a/doc/fluid/api_cn/nn_cn/softshrink_cn.rst +++ b/doc/fluid/api_cn/nn_cn/softshrink_cn.rst @@ -2,6 +2,41 @@ softshrink ------------------------------- -:doc_source: paddle.fluid.layers.softshrink +.. py:function:: paddle.nn.functional.softshrink(x, threshold=0.5, name=None) +softshrink激活层 + +.. math:: + + softshrink(x)= \begin{cases} + x - threshold, \text{if } x > threshold \\ + x + threshold, \text{if } x < -threshold \\ + 0, \text{otherwise} + \end{cases} + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - threshold (float, 可选) - softshrink激活计算公式中的threshold值,必须大于等于零。默认值为0.5。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.9, -0.2, 0.1, 0.8])) + out = F.softshrink(x) # [-0.4, 0, 0, 0.3] diff --git a/doc/fluid/api_cn/nn_cn/softsign_cn.rst b/doc/fluid/api_cn/nn_cn/softsign_cn.rst index 990268b65dc6b414fe0785781e2e4f5a5c4ba2ab..24c34bdbd2e89e28cc09e3ce421763afbafda529 100644 --- a/doc/fluid/api_cn/nn_cn/softsign_cn.rst +++ b/doc/fluid/api_cn/nn_cn/softsign_cn.rst @@ -2,6 +2,36 @@ softsign ------------------------------- -:doc_source: paddle.fluid.layers.softsign +.. py:function:: paddle.nn.functional.softsign(x, name=None) +softsign激活层 + +.. math:: + + softsign(x) = \frac{x}{1 + |x|} + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + out = F.softsign(x) # [-0.285714, -0.166667, 0.0909091, 0.230769] diff --git a/doc/fluid/api_cn/nn_cn/tanh_shrink_cn.rst b/doc/fluid/api_cn/nn_cn/tanh_shrink_cn.rst deleted file mode 100644 index 747320de63c87754770df3aac4408306df8ecb3c..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/nn_cn/tanh_shrink_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_nn_cn_tanh_shrink: - -tanh_shrink -------------------------------- -:doc_source: paddle.fluid.layers.tanh_shrink - - diff --git a/doc/fluid/api_cn/nn_cn/tanhshrink_cn.rst b/doc/fluid/api_cn/nn_cn/tanhshrink_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2e49b2b5156ab0d27298fbeefdc0802061cb09ca --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/tanhshrink_cn.rst @@ -0,0 +1,37 @@ +.. _cn_api_nn_cn_tanhshrink: + +tanhshrink +------------------------------- + +.. py:function:: paddle.nn.functional.tanhshrink(x, name=None) + +tanhshrink激活层 + +.. math:: + + tanhshrink(x) = x - tanh(x) + +其中,:math:`x` 为输入的 Tensor + +参数: +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + out = F.tanhshrink(x) # [-0.020051, -0.00262468, 0.000332005, 0.00868739] diff --git a/doc/fluid/api_cn/paddle_cn.rst b/doc/fluid/api_cn/paddle_cn.rst index 7497eb21ac79150aa3284c151896158813524989..47782281636bd6f85cf2876e53918a701d35cd97 100644 --- a/doc/fluid/api_cn/paddle_cn.rst +++ b/doc/fluid/api_cn/paddle_cn.rst @@ -5,7 +5,7 @@ paddle .. toctree:: :maxdepth: 1 - paddle_cn/abs_cn.rst + paddle_cn/abs_cn.rst paddle_cn/acos_cn.rst paddle_cn/addcmul_cn.rst paddle_cn/addmm_cn.rst @@ -21,7 +21,9 @@ paddle paddle_cn/cast_cn.rst paddle_cn/ceil_cn.rst paddle_cn/cholesky_cn.rst + paddle_cn/chunk_cn.rst paddle_cn/clamp_cn.rst + paddle_cn/clip_cn.rst paddle_cn/CompiledProgram_cn.rst paddle_cn/concat_cn.rst paddle_cn/cond_cn.rst @@ -40,6 +42,7 @@ paddle paddle_cn/diag_cn.rst paddle_cn/disable_dygraph_cn.rst paddle_cn/dist_cn.rst + paddle_cn/distribution_cn.rst paddle_cn/dot_cn.rst paddle_cn/elementwise_add_cn.rst paddle_cn/elementwise_div_cn.rst @@ -62,6 +65,7 @@ paddle paddle_cn/flatten_cn.rst paddle_cn/flip_cn.rst paddle_cn/floor_cn.rst + paddle_cn/full_cn.rst paddle_cn/full_like_cn.rst paddle_cn/gather_cn.rst paddle_cn/gather_nd_cn.rst @@ -93,18 +97,20 @@ paddle paddle_cn/log_cn.rst paddle_cn/manual_seed_cn.rst paddle_cn/matmul_cn.rst - paddle_cn/max_cn.rst - paddle_cn/maximum_cn.rst + paddle_cn/max_cn.rst + paddle_cn/maximum_cn.rst paddle_cn/mean_cn.rst paddle_cn/meshgrid_cn.rst - paddle_cn/min_cn.rst - paddle_cn/minimum_cn.rst + paddle_cn/min_cn.rst + paddle_cn/minimum_cn.rst paddle_cn/multiplex_cn.rst paddle_cn/mul_cn.rst - paddle_cn/name_scope_cn.rst - paddle_cn/no_grad_cn.rst + paddle_cn/name_scope_cn.rst + paddle_cn/no_grad_cn.rst paddle_cn/nonzero_cn.rst + paddle_cn/normal_cn.rst paddle_cn/not_equal_cn.rst + paddle_cn/numel_cn.rst paddle_cn/ones_cn.rst paddle_cn/ones_like_cn.rst paddle_cn/ParallelExecutor_cn.rst @@ -150,11 +156,13 @@ paddle paddle_cn/square_cn.rst paddle_cn/squeeze_cn.rst paddle_cn/stack_cn.rst + paddle_cn/standard_normal.rst paddle_cn/stanh_cn.rst paddle_cn/std_cn.rst paddle_cn/strided_slice_cn.rst paddle_cn/sums_cn.rst paddle_cn/tanh_cn.rst + paddle_cn/tile_cn.rst paddle_cn/topk_cn.rst paddle_cn/trace_cn.rst paddle_cn/transpose_cn.rst diff --git a/doc/fluid/api_cn/paddle_cn/clamp_cn.rst b/doc/fluid/api_cn/paddle_cn/clamp_cn.rst deleted file mode 100644 index 5e7a8fbb0143ff45f3c10d9b4df0ad827d4291bf..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/paddle_cn/clamp_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_paddle_cn_clamp: - -clamp -------------------------------- -:doc_source: paddle.tensor.clamp - - diff --git a/doc/fluid/api_cn/paddle_cn/clip_cn.rst b/doc/fluid/api_cn/paddle_cn/clip_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..bef260e12c8b4eb2389bda00a4def1348b0c4eac --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/clip_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_paddle_cn_clip: + +clip +------------------------------- +:doc_source: paddle.tensor.clip + + diff --git a/doc/fluid/api_cn/paddle_cn/diag_cn.rst b/doc/fluid/api_cn/paddle_cn/diag_cn.rst index de470c5af161ed1a83d0540f7ba116d3a02de2b1..f525efb5890531e85eee24367e96b3f62c8fb0ea 100644 --- a/doc/fluid/api_cn/paddle_cn/diag_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/diag_cn.rst @@ -2,6 +2,83 @@ diag ------------------------------- -:doc_source: paddle.fluid.layers.diag + +.. py:function:: paddle.diag(x, offset=0, padding_value=0, name=None) + + +如果 ``x`` 是向量(1-D张量),则返回带有 ``x`` 元素作为对角线的2-D方阵。 + +如果 ``x`` 是矩阵(2-D张量),则提取 ``x`` 的对角线元素,以1-D张量返回。 + +参数 ``offset`` 控制对角线偏移量: + +- 如果 ``offset`` = 0,则为主对角线。 +- 如果 ``offset`` > 0,则为上对角线。 +- 如果 ``offset`` < 0,则为下对角线。 + +参数 +::::::::: + - x(Tensor):输入的 `Tensor`。它的形状可以是一维或二维。其数据类型应为float32,float64,int32,int64。 + - offset(int,可选):对角线偏移量。正值表示上对角线,0表示主对角线,负值表示下对角线。 + - padding_value(int|float,可选):使用此值来填充指定对角线以外的区域。仅在输入为一维张量时生效。默认值为0。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +::::::::: +``Tensor``,方阵或向量。输出数据类型与输入数据类型相同。 + + +代码示例 1 +::::::::: + +.. code-block:: python + + import paddle + + paddle.disable_static() + x = paddle.to_tensor([1, 2, 3]) + y = paddle.diag(x) + print(y.numpy()) + # [[1 0 0] + # [0 2 0] + # [0 0 3]] + + y = paddle.diag(x, offset=1) + print(y.numpy()) + # [[0 1 0 0] + # [0 0 2 0] + # [0 0 0 3] + # [0 0 0 0]] + + y = paddle.diag(x, padding_value=6) + print(y.numpy()) + # [[1 6 6] + # [6 2 6] + # [6 6 3]] + + +代码示例 2 +::::::::: + +.. code-block:: python + + import paddle + + paddle.disable_static() + x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]]) + y = paddle.diag(x) + print(y.numpy()) + # [1 5] + + y = paddle.diag(x, offset=1) + print(y.numpy()) + # [2 6] + + y = paddle.diag(x, offset=-1) + print(y.numpy()) + # [4] + + + diff --git a/doc/fluid/api_cn/paddle_cn/distribution_cn.rst b/doc/fluid/api_cn/paddle_cn/distribution_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..acbdd00b7a187372a5c74f5f39ba238984331025 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/distribution_cn.rst @@ -0,0 +1,10 @@ +============ +distribution +============ + +.. toctree:: + :maxdepth: 1 + + distribution_cn/Distribution_cn.rst + distribution_cn/Normal_cn.rst + distribution_cn/Uniform_cn.rst diff --git a/doc/fluid/api_cn/paddle_cn/distribution_cn/Distribution_cn.rst b/doc/fluid/api_cn/paddle_cn/distribution_cn/Distribution_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c513c281df548f83a62a5183a6ef2b9f19e04ca9 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/distribution_cn/Distribution_cn.rst @@ -0,0 +1,49 @@ +.. _cn_api_distribution_Distribution: + +Distribution +------------------------------- + +.. py:class:: paddle.distribution.Distribution() + + + + +概率分布的抽象基类,在具体的分布中实现具体功能。 + + +.. py:function:: sample() + +从分布中采样 + +.. py:function:: entropy() + +分布的信息熵 + +.. py:function:: log_prob(value) + +对数概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。 + +.. py:function:: probs(value) + +概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。 + +.. py:function:: kl_divergence(other) + +两个分布之间的KL散度。 + +参数: + - **other** (Distribution) - Distribution的实例。 + + + + + + + + diff --git a/doc/fluid/api_cn/paddle_cn/distribution_cn/Normal_cn.rst b/doc/fluid/api_cn/paddle_cn/distribution_cn/Normal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c1bc0c8b57648787594e35f9ae9c9469e8eca81d --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/distribution_cn/Normal_cn.rst @@ -0,0 +1,128 @@ +.. _cn_api_distribution_Normal: + +Normal +------------------------------- + +.. py:class:: paddle.distribution.Normal(loc, scale, name=None) + + + + +正态分布 + +数学公式: + +.. math:: + + pdf(x; \mu, \sigma) = \frac{1}{Z}e^{\frac {-0.5 (x - \mu)^2} {\sigma^2} } + + Z = (2 \pi \sigma^2)^{0.5} + +上面的数学公式中: + +:math:`loc = \mu` : 平均值。 +:math:`scale = \sigma` : 标准差。 +:math:`Z`: 正态分布常量。 + +参数: + - **loc** (int|float|list|numpy.ndarray|Tensor) - 正态分布平均值。数据类型为int、float32、list、numpy.ndarray或Tensor。 + - **scale** (int|float|list|numpy.ndarray|Tensor) - 正态分布标准差。数据类型为int、float32、list、numpy.ndarray或Tensor。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + from paddle.distribution import Normal + + paddle.disable_static() + # Define a single scalar Normal distribution. + dist = Normal(loc=0., scale=3.) + # Define a batch of two scalar valued Normals. + # The first has mean 1 and standard deviation 11, the second 2 and 22. + dist = Normal(loc=[1., 2.], scale=[11., 22.]) + # Get 3 samples, returning a 3 x 2 tensor. + dist.sample([3]) + + # Define a batch of two scalar valued Normals. + # Both have mean 1, but different standard deviations. + dist = Normal(loc=1., scale=[11., 22.]) + + # Complete example + value_npdata = np.array([0.8], dtype="float32") + value_tensor = paddle.to_tensor(value_npdata) + + normal_a = Normal([0.], [1.]) + normal_b = Normal([0.5], [2.]) + sample = normal_a.sample([2]) + # a random tensor created by normal distribution with shape: [2, 1] + entropy = normal_a.entropy() + # [1.4189385] with shape: [1] + lp = normal_a.log_prob(value_tensor) + # [-1.2389386] with shape: [1] + p = normal_a.probs(value_tensor) + # [0.28969154] with shape: [1] + kl = normal_a.kl_divergence(normal_b) + # [0.34939718] with shape: [1] + + +.. py:function:: sample(shape, seed=0) + +生成指定维度的样本 + +参数: + - **shape** (list) - 1维列表,指定生成样本的维度。数据类型为int32。 + - **seed** (int) - 长整型数。 + +返回:预先设计好维度的张量, 数据类型为float32 + +返回类型:Tensor + +.. py:function:: entropy() + +信息熵 + +返回:正态分布的信息熵, 数据类型为float32 + +返回类型:Tensor + +.. py:function:: log_prob(value) + +对数概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。数据类型为float32或float64。 + +返回:对数概率, 数据类型与value相同 + +返回类型:Tensor + +.. py:function:: probs(value) + +概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。数据类型为float32或float64。 + +返回:概率, 数据类型与value相同 + +返回类型:Tensor + +.. py:function:: kl_divergence(other) + +两个正态分布之间的KL散度。 + +参数: + - **other** (Normal) - Normal的实例。 + +返回:两个正态分布之间的KL散度, 数据类型为float32 + +返回类型:Tensor + + + + + + diff --git a/doc/fluid/api_cn/paddle_cn/distribution_cn/Uniform_cn.rst b/doc/fluid/api_cn/paddle_cn/distribution_cn/Uniform_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..382d1e9c66ff2691e045caf41f37241f21ba5978 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/distribution_cn/Uniform_cn.rst @@ -0,0 +1,115 @@ +.. _cn_api_distribution_Uniform: + +Uniform +------------------------------- + +.. py:class:: paddle.distribution.Uniform(low, high, name=None) + + + + +均匀分布 + +概率密度函数(pdf)为: + +.. math:: + + pdf(x; a, b) = \frac{1}{Z}, a <=x < b + + Z = b - a + +上面的数学公式中: + +:math:`low = a` 。 +:math:`high = b` 。 +:math:`Z`: 正态分布常量。 + +参数low和high的维度必须能够支持广播。 + +参数: + - **low** (int|float|list|numpy.ndarray|Tensor) - 均匀分布的下边界。数据类型为int、float32、list、numpy.ndarray或Tensor。 + - **high** (int|float|list|numpy.ndarray|Tensor) - 均匀分布的上边界。数据类型为int、float32、list、numpy.ndarray或Tensor。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + from paddle.distribution import Uniform + + paddle.disable_static() + # Without broadcasting, a single uniform distribution [3, 4]: + u1 = Uniform(low=3.0, high=4.0) + # 2 distributions [1, 3], [2, 4] + u2 = Uniform(low=[1.0, 2.0], high=[3.0, 4.0]) + # 4 distributions + u3 = Uniform(low=[[1.0, 2.0], [3.0, 4.0]], + high=[[1.5, 2.5], [3.5, 4.5]]) + + # With broadcasting: + u4 = Uniform(low=3.0, high=[5.0, 6.0, 7.0]) + + # Complete example + value_npdata = np.array([0.8], dtype="float32") + value_tensor = paddle.to_tensor(value_npdata) + + uniform = Uniform([0.], [2.]) + + sample = uniform.sample([2]) + # a random tensor created by uniform distribution with shape: [2, 1] + entropy = uniform.entropy() + # [0.6931472] with shape: [1] + lp = uniform.log_prob(value_tensor) + # [-0.6931472] with shape: [1] + p = uniform.probs(value_tensor) + # [0.5] with shape: [1] + + +.. py:function:: sample(shape, seed=0) + +生成指定维度的样本 + +参数: + - **shape** (list) - 1维列表,指定生成样本的维度。数据类型为int32。 + - **seed** (int) - 长整型数。 + +返回:预先设计好维度的张量, 数据类型为float32 + +返回类型:Tensor + +.. py:function:: entropy() + +信息熵 + +返回:均匀分布的信息熵, 数据类型为float32 + +返回类型:Tensor + +.. py:function:: log_prob(value) + +对数概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。数据类型为float32或float64。 + +返回:对数概率, 数据类型与value相同 + +返回类型:Tensor + +.. py:function:: probs(value) + +概率密度函数 + +参数: + - **value** (Tensor) - 输入张量。数据类型为float32或float64。 + +返回:概率, 数据类型与value相同 + +返回类型:Tensor + + + + + diff --git a/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst b/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst index a5615e16b9fa5f782cd323e2d6afc22c799212fe..448bb6afbc2c509d6245c066c634326a74e68958 100644 --- a/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst @@ -2,6 +2,6 @@ expand_as ------------------------------- -:doc_source: paddle.fluid.layers.expand_as +:doc_source: paddle.tensor.expand_as diff --git a/doc/fluid/api_cn/paddle_cn/expand_cn.rst b/doc/fluid/api_cn/paddle_cn/expand_cn.rst index addb87a5ad2cc8674e33ab443ad8ea6e295a0baa..cdff8439ea3a3fb6e36436957c875552ee72caab 100644 --- a/doc/fluid/api_cn/paddle_cn/expand_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/expand_cn.rst @@ -2,6 +2,6 @@ expand ------------------------------- -:doc_source: paddle.fluid.layers.expand +:doc_source: paddle.tensor.expand diff --git a/doc/fluid/api_cn/paddle_cn/normal_cn.rst b/doc/fluid/api_cn/paddle_cn/normal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..637b99d5d9f486ad13c7fe0434516f2fdde8cf39 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/normal_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_paddle_cn_normal: + +normal +------------------------------- +:doc_source: paddle.tensor.normal + + diff --git a/doc/fluid/api_cn/paddle_cn/standard_normal_cn.rst b/doc/fluid/api_cn/paddle_cn/standard_normal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..43d8419574c17089c3ab231915aa9bce8c5cddd5 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/standard_normal_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_paddle_cn_standard_normal: + +standard_normal +------------------------------- +:doc_source: paddle.tensor.standard_normal + + diff --git a/doc/fluid/api_cn/paddle_cn/tile_cn.rst b/doc/fluid/api_cn/paddle_cn/tile_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..6d74f6795a6d484ddcf04c0d859ddda06c9af460 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/tile_cn.rst @@ -0,0 +1,6 @@ +.. _cn_api_paddle_cn_tile: + +tile +------------------------------- +:doc_source: paddle.tensor.tile + diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index 259cf4ab97da44815ff7a40a24ff959eae8bf8c8..e0892a4024fd42031fed4ede1d4050287ba5f9b5 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -23,7 +23,9 @@ paddle.tensor tensor_cn/cast_cn.rst tensor_cn/ceil_cn.rst tensor_cn/cholesky_cn.rst + tensor_cn/chunk_cn.rst tensor_cn/clamp_cn.rst + tensor_cn/clip_cn.rst tensor_cn/concat_cn.rst tensor_cn/cond_cn.rst tensor_cn/cos_cn.rst @@ -33,7 +35,11 @@ paddle.tensor tensor_cn/cumsum_cn.rst tensor_cn/diag_cn.rst tensor_cn/dist_cn.rst - tensor_cn/div_cn.rst + tensor_cn/divide_cn.rst + tensor_cn/floor_divide_cn.rst + tensor_cn/remainder_cn.rst + tensor_cn/mod_cn.rst + tensor_cn/floor_mod_cn.rst tensor_cn/dot_cn.rst tensor_cn/einsum_cn.rst tensor_cn/elementwise_add_cn.rst @@ -70,6 +76,7 @@ paddle.tensor tensor_cn/inverse_cn.rst tensor_cn/is_empty_cn.rst tensor_cn/isfinite_cn.rst + tensor_cn/isinf_cn.rst tensor_cn/isnan_cn.rst tensor_cn/kron_cn.rst tensor_cn/l2_normalize_cn.rst @@ -97,10 +104,13 @@ paddle.tensor tensor_cn/multiplex_cn.rst tensor_cn/nonzero_cn.rst tensor_cn/norm_cn.rst + tensor_cn/normal_cn.rst tensor_cn/not_equal_cn.rst + tensor_cn/numel_cn.rst tensor_cn/ones_cn.rst tensor_cn/ones_like_cn.rst tensor_cn/pow_cn.rst + tensor_cn/prod_cn.rst tensor_cn/rand_cn.rst tensor_cn/randint_cn.rst tensor_cn/randn_cn.rst @@ -137,6 +147,7 @@ paddle.tensor tensor_cn/square_cn.rst tensor_cn/squeeze_cn.rst tensor_cn/stack_cn.rst + tensor_cn/standard_normal_cn.rst tensor_cn/stanh_cn.rst tensor_cn/std_cn.rst tensor_cn/strided_slice_cn.rst @@ -145,12 +156,14 @@ paddle.tensor tensor_cn/t_cn.rst tensor_cn/tanh_cn.rst tensor_cn/tensordot_cn.rst + tensor_cn/tile_cn.rst tensor_cn/topk_cn.rst tensor_cn/trace_cn.rst tensor_cn/transpose_cn.rst tensor_cn/tril_cn.rst tensor_cn/triu_cn.rst tensor_cn/unbind_cn.rst + tensor_cn/uniform_cn.rst tensor_cn/unique_cn.rst tensor_cn/unique_with_counts_cn.rst tensor_cn/unsqueeze_cn.rst @@ -159,3 +172,4 @@ paddle.tensor tensor_cn/where_cn.rst tensor_cn/zeros_cn.rst tensor_cn/zeros_like_cn.rst + diff --git a/doc/fluid/api_cn/tensor_cn/argmax_cn.rst b/doc/fluid/api_cn/tensor_cn/argmax_cn.rst index 2b3a7857b80b29ecffbccb5f697267ef05afd81b..157806c38000bd4ae1866e55e4ecbe5bd90e7882 100644 --- a/doc/fluid/api_cn/tensor_cn/argmax_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/argmax_cn.rst @@ -3,67 +3,42 @@ argmax ------------------------------- -.. py:function:: paddle.argmax(input, axis=None, dtype=None, out=None, keepdims=False, name=None) +.. py:function:: paddle.argmax(x, axis=None, dtype=None, keepdim=False, name=None) -:alias_main: paddle.argmax -:alias: paddle.argmax,paddle.tensor.argmax,paddle.tensor.search.argmax -:update_api: paddle.fluid.layers.argmax +该OP沿 ``axis`` 计算输入 ``x`` 的最大元素的索引。 +参数 +:::::::: + - **x** (Tensor) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int16、int32、int64、uint8。 + - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 的维度个数, ``axis`` 为负数时,进行计算的 ``axis`` 与 ``axis`` + R 一致。默认值为None, 将会对输入的 `x` 进行平铺展开,返回最大值的索引。 + - **dtype** (np.dtype|str)- 输出Tensor的数据类型,可选值为int32,int64,默认值为None,将返回int64类型的结果。 + - **keepdim** (bool,可选)- 是否保留进行最大值索引操作的轴,默认值为False。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 +返回 +:::::::: +``Tensor``, 如果设置 :attr:`dtype` 为 `int32` 时,返回的tensor的数据类型为 `int32` ,其它情况将返回的tensor的数据类型为 `int64` 。 -该OP沿 ``axis`` 计算输入 ``input`` 的最大元素的索引。 -参数: - - **input** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int8、int16、int32、int64。 - - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 的Rank, ``axis`` -R与绝对值相同的R等价。默认值为0。 - - **dtype** (np.dtype|core.VarDesc.VarType|str)- 输出Tensor的数据类型,可选值为int32,int64,默认值为None,将返回int64类型的结果。 - - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 - - **keepdims** (bool,可选)- 是否保留进行max index操作的维度,默认值为False。 - - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - -返回: ``Tensor`` ,数据类型int64 - -返回类型:Variable - -**代码示例**: +示例代码 +:::::::: .. code-block:: python - import paddle - import paddle.fluid as fluid - import numpy as np - - in1 = np.array([[[5,8,9,5], - [0,0,1,7], - [6,9,2,4]], - [[5,2,4,2], - [4,7,7,9], - [1,7,0,6]]]) - with fluid.dygraph.guard(): - x = fluid.dygraph.to_variable(in1) - out1 = paddle.argmax(input=x, axis=-1) - out2 = paddle.argmax(input=x, axis=0) - out3 = paddle.argmax(input=x, axis=1) - out4 = paddle.argmax(input=x, axis=2) - out5 = paddle.argmax(input=x, axis=2, keepdims=True) - print(out1.numpy()) - # [[2 3 1] - # [0 3 1]] - print(out2.numpy()) - # [[0 0 0 0] - # [1 1 1 1] - # [0 0 0 1]] - print(out3.numpy()) - # [[2 2 0 1] - # [0 1 1 1]] - print(out4.numpy()) - # [[2 3 1] - # [0 3 1]] - print(out5.numpy()) - #array([[[2], - # [3], - # [1]], - # [[0], - # [3], - # [1]]]) + import numpy as np + import paddle + + paddle.disable_static() + data = [[5,8,9,5], + [0,0,1,7], + [6,9,2,4]] + x = paddle.to_tensor(data) + out1 = paddle.argmax(x) + print(out1.numpy()) # 2 + out2 = paddle.argmax(x, axis=1) + print(out2.numpy()) + # [2 3 1] + out3 = paddle.argmax(x, axis=-1) + print(out3.numpy()) + # [2 3 1] diff --git a/doc/fluid/api_cn/tensor_cn/argmin_cn.rst b/doc/fluid/api_cn/tensor_cn/argmin_cn.rst index 95842cc525cc87c3b8d7f8c84520feca1d5352fb..14082c452382ba2e7c17eb11306e190b087e0c70 100644 --- a/doc/fluid/api_cn/tensor_cn/argmin_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/argmin_cn.rst @@ -1,7 +1,43 @@ -.. _cn_api_tensor_cn_argmin: +.. _cn_api_tensor_argmin: argmin ------------------------------- -:doc_source: paddle.fluid.layers.argmin +.. py:function:: paddle.argmin(x, axis=None, dtype=None, keepdim=False, name=None) + +该OP沿 ``axis`` 计算输入 ``x`` 的最小元素的索引。 + +参数 +:::::::: + - **x** (Tensor) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int16、int32、int64、uint8。 + - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 的维度个数, ``axis`` 为负数时,进行计算的 ``axis`` 与 ``axis`` + R 一致。默认值为None, 将会对输入的 `x` 进行平铺展开,返回最小值的索引。 + - **dtype** (np.dtype|str)- 输出Tensor的数据类型,可选值为int32,int64,默认值为None,将返回int64类型的结果。 + - **keepdim** (bool,可选)- 是否保留进行最小值索引操作的轴,默认值为False。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回 +:::::::: +``Tensor``, 如果设置 :attr:`dtype` 为 `int32` 时,返回的tensor的数据类型为 `int32` ,其它情况将返回的tensor的数据类型为 `int64` 。 + +示例代码 +:::::::: + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + data = [[5,8,9,5], + [0,0,1,7], + [6,9,2,4]] + x = paddle.to_tensor(data) + out1 = paddle.argmin(x) + print(out1.numpy()) # 4 + out2 = paddle.argmin(x, axis=1) + print(out2.numpy()) + # [0 0 2] + out3 = paddle.argmin(x, axis=-1) + print(out3.numpy()) + # [0 0 2] diff --git a/doc/fluid/api_cn/tensor_cn/chunk_cn.rst b/doc/fluid/api_cn/tensor_cn/chunk_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d4c29bc421c7b4d287a99d51eac22e82c1bc9165 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/chunk_cn.rst @@ -0,0 +1,41 @@ +.. _cn_api_tensor_cn_chunk: + +chunk +------------------------------- + +.. py:function:: paddle.chunk(x, chunks, axis=0, name=None) + +该OP将输入Tensor分割成多个子Tensor。 + +**参数**: + - **x** (Tensor) - 输入变量,数据类型为bool, float16, float32,float64,int32,int64的多维Tensor。 + - **chunks** (int) - 如果 ``chunks`` 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。 + - **axis** (int|Tensor,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果 ``axis < 0`` ,则划分的维度为 ``rank(x) + axis`` 。默认值为0。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:分割后的Tensor列表。 + + +**代码示例** + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + # x is a Tensor which shape is [3, 9, 5] + x_np = np.random.random([3, 9, 5]).astype("int32") + x = paddle.to_tensor(x_np) + + out0, out1, out22 = paddle.chunk(x, chunks=3, axis=1) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 3, 5] + + + # axis is negative, the real axis is (rank(x) + axis) which real + # value is 1. + out0, out1, out2 = paddle.chunk(x, chunks=3, axis=-2) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] diff --git a/doc/fluid/api_cn/tensor_cn/clamp_cn.rst b/doc/fluid/api_cn/tensor_cn/clamp_cn.rst deleted file mode 100644 index 6584ec3695594ac5d93ccaeaf3ea35d8ebd7e95f..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/tensor_cn/clamp_cn.rst +++ /dev/null @@ -1,50 +0,0 @@ -.. _cn_api_tensor_clamp: - -clamp -------------------------------- - -.. py:function:: paddle.clamp(input, min=None, max=None, output=None, name=None) - -:alias_main: paddle.clamp -:alias: paddle.clamp,paddle.tensor.clamp,paddle.tensor.math.clamp - - - -该OP将输入的所有元素进行剪裁,使得输出元素限制在[min, max]内,具体公式如下: - -.. math:: - - Out = MIN(MAX(x, min), max) - -参数: - - **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是float32,float64。 - - **min** (float32|Variable, 可选) - 裁剪的最小值,输入中小于该值的元素将由该元素代替,若参数为空,则不对输入的最小值做限制。数据类型可以是float32或形状为[1]的Tensor,类型可以为int32,float32,float64,默认值为None。 - - **max** (float32|Variable, 可选) - 裁剪的最大值,输入中大于该值的元素将由该元素代替,若参数为空,则不对输入的最大值做限制。数据类型可以是float32或形状为[1]的Tensor,类型可以为int32,float32,float64,默认值为None。 - - **output** (Variable, 可选)- 输出Tensor或LoDTensor。如果为None,则创建一个新的Tensor作为输出Tensor,默认值为None。 - - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - -返回:返回一个和输入形状相同的Tensor。 - -返回类型:Variable - -**代码示例**: - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np - - in1 = np.array([[1.2,3.5], - [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) - print(out1.numpy()) - # [[3.5, 3.5] - # [4.5, 5.0]] - print(out2.numpy()) - # [[2.5, 3.5] - # [[4.5, 6.4] - diff --git a/doc/fluid/api_cn/tensor_cn/clip_cn.rst b/doc/fluid/api_cn/tensor_cn/clip_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..9bfeadbc41bc77df93195565d23ccebf4b9ed344 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/clip_cn.rst @@ -0,0 +1,46 @@ +.. _cn_api_tensor_clip: + +clip +------------------------------- + +.. py:function:: paddle.clip(x, min=None, max=None, name=None) + +:alias_main: paddle.clip +:alias: paddle.clip,paddle.tensor.clip,paddle.tensor.math.clip + + + +该OP将输入的所有元素进行剪裁,使得输出元素限制在[min, max]内,具体公式如下: + +.. math:: + + Out = MIN(MAX(x, min), max) + +参数: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64、int32、int64。 + - min (float32|Tensor, 可选) - 裁剪的最小值,输入中小于该值的元素将由该元素代替,若参数为空,则不对输入的最小值做限制。数据类型可以是float32或形状为[1]的Tensor,类型可以为int32,float32,float64,默认值为None。 + - max (float32|Tensor, 可选) - 裁剪的最大值,输入中大于该值的元素将由该元素代替,若参数为空,则不对输入的最大值做限制。数据类型可以是float32或形状为[1]的Tensor,类型可以为int32,float32,float64,默认值为None。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。 + +返回类型:Tensor + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x = np.array([[1.2,3.5], [4.5,6.4]]).astype('float32') + x1 = paddle.to_tensor(x) + out1 = paddle.clip(x1, min=3.5, max=5.0) + out2 = paddle.clip(x1, min=2.5) + print(out1.numpy()) + # [[3.5, 3.5] + # [4.5, 5.0]] + print(out2.numpy()) + # [[2.5, 3.5] + # [[4.5, 6.4] diff --git a/doc/fluid/api_cn/tensor_cn/concat_cn.rst b/doc/fluid/api_cn/tensor_cn/concat_cn.rst index aa36dd238d01ef6804bb8e4175650ab3b0244429..b66f67025f4171fa452534d173b3b63d86795b05 100644 --- a/doc/fluid/api_cn/tensor_cn/concat_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/concat_cn.rst @@ -28,16 +28,16 @@ concat import paddle import numpy as np - paddle.enable_imperative() # Now we are in imperative mode + paddle.disable_static() # Now we are in imperative mode in1 = np.array([[1, 2, 3], [4, 5, 6]]) in2 = np.array([[11, 12, 13], [14, 15, 16]]) in3 = np.array([[21, 22], [23, 24]]) - x1 = paddle.imperative.to_variable(in1) - x2 = paddle.imperative.to_variable(in2) - x3 = paddle.imperative.to_variable(in3) + x1 = paddle.to_tensor(in1) + x2 = paddle.to_tensor(in2) + x3 = paddle.to_tensor(in3) zero = paddle.full(shape=[1], dtype='int32', fill_value=0) # When the axis is negative, the real axis is (axis + Rank(x)) # As follow, axis is -1, Rank(x) is 2, the real axis is 1 diff --git a/doc/fluid/api_cn/tensor_cn/div_cn.rst b/doc/fluid/api_cn/tensor_cn/div_cn.rst deleted file mode 100644 index 14a6e051659f44d3a62c8b474eced5fe22681d1c..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/tensor_cn/div_cn.rst +++ /dev/null @@ -1,160 +0,0 @@ -.. _cn_api_tensor_div: - -div -------------------------------- - -.. py:function:: paddle.div(x, y, out=None, name=None) - -:alias_main: paddle.div -:alias: paddle.div,paddle.tensor.div,paddle.tensor.math.div -:update_api: paddle.fluid.layers.elementwise_div - - - -该OP是逐元素相除算子,输入 ``x`` 与输入 ``y`` 逐元素相除,并将各个位置的输出元素保存到返回结果中。 - -等式是: - -.. math:: - Out = X / Y - -- :math:`X` :多维Tensor。 -- :math:`Y` :维度必须小于等于X维度的Tensor。 - -对于这个运算算子有2种情况: - 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。 - 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。 - -对于情况2: - 1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。 - 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis= rank(X)-rank(Y)` 。 - 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 - -例如: - -.. code-block:: text - - shape(X) = (2, 3, 4, 5), shape(Y) = (,) - shape(X) = (2, 3, 4, 5), shape(Y) = (5,) - shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 - shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 - shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 - shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 - -参数: - - **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 - - **y** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 - - **out** (Variable,可选)- 指定存储运算结果的 ``Tensor`` 。如果设置为None或者不设置,将创建新的 ``Tensor`` 存储运算结果,默认值为None。 - - **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 - - -返回: 多维 ``Tensor`` 或 ``LoDTensor`` , 维度和数据类型都与 ``x`` 相同。 - -返回类型: Variable - -**代码示例 1** - -.. code-block:: python - - - import paddle - import paddle.fluid as fluid - import numpy as np - - def gen_data(): - return { - "x": np.array([2, 3, 4]).astype('float32'), - "y": np.array([1, 5, 2]).astype('float32') - } - - x = fluid.data(name="x", shape=[3], dtype='float32') - y = fluid.data(name="y", shape=[3], dtype='float32') - z = paddle.div(x, y) - # z = x / y - - place = fluid.CPUPlace() - exe = fluid.Executor(place) - z_value = exe.run(feed=gen_data(), - fetch_list=[z.name]) - - print(z_value) # [2., 0.6, 2.] - - -**代码示例 2** - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np - - def gen_data(): - return { - "x": np.ones((2, 3, 4, 5)).astype('float32'), - "y": np.zeros((4, 5)).astype('float32') - } - - x = fluid.data(name="x", shape=[2, 3, 4, 5], dtype='float32') - y = fluid.data(name="y", shape=[4, 5], dtype='float32') - z = paddle.div(x, y, name='z') - # z = x / y - - place = fluid.CPUPlace() - exe = fluid.Executor(place) - - z_value = exe.run(feed=gen_data(), - fetch_list=[z.name]) - - print(z_value[0]) - print(z_value[0].shape) # z.shape=[2,3,4,5] - - -**代码示例 3** - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np - - def gen_data(): - return { - "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), - "y": np.random.randint(1, 5, size=[5]).astype('float32') - } - - x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') - y = fluid.data(name="y", shape=[5], dtype='float32') - output = fluid.data(name="output", shape=[2,3,4,5], dtype="float32") - z = paddle.div(x, y, out=output) - # z = x / y - - place = fluid.CPUPlace() - exe = fluid.Executor(place) - - z_value = exe.run(feed=gen_data(), - fetch_list=[z.name]) - print(z_value[0]) - print(z_value[0].shape) # z.shape=[2,3,4,5] - - -**代码示例 4(动态图)** - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np - - with fluid.dygraph.guard(fluid.CPUPlace()): - np_x = np.array([2, 3, 4]).astype('float64') - np_y = np.array([1, 5, 2]).astype('float64') - x = fluid.dygraph.to_variable(np_x) - y = fluid.dygraph.to_variable(np_y) - z = paddle.div(x, y) - np_z = z.numpy() - print(np_z) # [2., 0.6, 2.] - - - - diff --git a/doc/fluid/api_cn/tensor_cn/divide_cn.rst b/doc/fluid/api_cn/tensor_cn/divide_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d0b0113c24644f5e5e55b4a3a73722da63610df4 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/divide_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_tensor_divide: + +divide +------------------------------- + +.. py:function:: paddle.divide(x, y, name=None) + +该OP是逐元素相除算子,输入 ``x`` 与输入 ``y`` 逐元素相除,并将各个位置的输出元素保存到返回结果中。 +输入 ``x`` 与输入 ``y`` 必须可以广播为相同形状, 关于广播规则,请参考 :ref:`use_guide_broadcasting` + +等式为: + +.. math:: + Out = X / Y + +- :math:`X` :多维Tensor。 +- :math:`Y` :多维Tensor。 + +参数: + - x(Tensor)- 多维Tensor。数据类型为float32 、float64、int32或int64。 + - y(Tensor)- 多维Tensor。数据类型为float32 、float64、int32或int64。 + - name(str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + + +返回: 多维 Tensor, 数据类型与 ``x`` 相同,维度为广播后的形状。 + +返回类型: Tensor + + +**代码示例** + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_x = np.array([2, 3, 4]).astype('float64') + np_y = np.array([1, 5, 2]).astype('float64') + x = paddle.to_tensor(np_x) + y = paddle.to_tensor(np_y) + z = paddle.divide(x, y) + print(z.numpy()) # [2., 0.6, 2.] diff --git a/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst b/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst index ab63e99bb5f95473a4e0eff0e8b3b1303ec0a1b4..2f62f67233c8e52f87f77e703c3e4499cb8fc40c 100644 --- a/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst @@ -1,7 +1,38 @@ -.. _cn_api_tensor_cn_expand_as: +.. _cn_api_tensor_expand_as: expand_as ------------------------------- -:doc_source: paddle.fluid.layers.expand_as +.. py:function:: paddle.expand_as(x, y, name=None) + +根据 ``y`` 的形状扩展 ``x`` ,扩展后, ``x`` 的形状和 ``y`` 的形状相同。 + +``x`` 的维数和 ``y`` 的维数应小于等于6,并且 ``y`` 的维数应该大于等于 ``x`` 的维数。扩展的维度的维度值应该为1。 + +参数 +::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:bool、float32、float64、int32或int64。 + - y (Tensor) - 给定输入 ``x`` 扩展后的形状。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor`` ,数据类型与 ``x`` 相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_data_x = np.array([1, 2, 3]).astype('int32') + np_data_y = np.array([[1, 2, 3], [4, 5, 6]]).astype('int32') + data_x = paddle.to_tensor(np_data_x) + data_y = paddle.to_tensor(np_data_y) + out = paddle.expand_as(data_x, data_y) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] diff --git a/doc/fluid/api_cn/tensor_cn/expand_cn.rst b/doc/fluid/api_cn/tensor_cn/expand_cn.rst index 5a9ae8cba10d48fdbbab02665f4cea10f9ac83e7..94af4e93fe13c2d5ff220c50b6a18f37e0491851 100644 --- a/doc/fluid/api_cn/tensor_cn/expand_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/expand_cn.rst @@ -1,7 +1,36 @@ -.. _cn_api_tensor_cn_expand: +.. _cn_api_tensor_expand: expand ------------------------------- -:doc_source: paddle.fluid.layers.expand +.. py:function:: paddle.expand(x, shape, name=None) + +根据 ``shape`` 指定的形状扩展 ``x`` ,扩展后, ``x`` 的形状和 ``shape`` 指定的形状一致。 + +``x`` 的维数和 ``shape`` 的元素数应小于等于6,并且 ``shape`` 中的元素数应该大于等于 ``x`` 的维数。扩展的维度的维度值应该为1。 + +参数 +::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:bool、float32、float64、int32或int64。 + - shape (tuple|list|Tensor) - 给定输入 ``x`` 扩展后的形状,若 ``shape`` 为list或者tuple,则其中的元素值应该为整数或者1-D Tensor,若 ``shape`` 类型为Tensor,则其应该为1-D Tensor。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor`` ,数据类型与 ``x`` 相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_data = np.array([1, 2, 3]).astype('int32') + data = paddle.to_tensor(np_data) + out = paddle.expand(data, [2, 3]) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] diff --git a/doc/fluid/api_cn/tensor_cn/eye_cn.rst b/doc/fluid/api_cn/tensor_cn/eye_cn.rst index 87e746f90024e97ad56e1bc05dc89ca683e10018..c105c4b06b517488c1f0100ffb4cd4ee26ac8f89 100644 --- a/doc/fluid/api_cn/tensor_cn/eye_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/eye_cn.rst @@ -8,9 +8,9 @@ eye 该OP用来构建二维Tensor(主对角线元素为1,其他元素为0)。 参数: - - **num_rows** (int) - 生成二维Tensor的行数,数据类型为非负int32。 - - **num_columns** (int,可选) - 生成二维Tensor的列数,数据类型为非负int32。若为None,则默认等于num_rows。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 返回Tensor的数据类型,可为float16,float32,float64, int32, int64。若为None, 则默认等于float32。 + - **num_rows** (int) - 生成2-D Tensor的行数,数据类型为非负int32。 + - **num_columns** (int,可选) - 生成2-D Tensor的列数,数据类型为非负int32。若为None,则默认等于num_rows。 + - **dtype** (np.dtype|str, 可选) - 返回Tensor的数据类型,可为float16,float32,float64, int32, int64。若为None, 则默认等于float32。 - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回: ``shape`` 为 [num_rows, num_columns]的Tensor。 @@ -25,7 +25,7 @@ eye .. code-block:: python import paddle - paddle.enable_imperative() # Now we are in imperative mode + paddle.disable_static() # Now we are in imperative mode data = paddle.eye(3, dtype='int32') # [[1 0 0] # [0 1 0] diff --git a/doc/fluid/api_cn/tensor_cn/floor_divide_cn.rst b/doc/fluid/api_cn/tensor_cn/floor_divide_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c63ae4fd10451f280169d67c8156fa30f92649d7 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/floor_divide_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_tensor_floor_divide: + +floor_divide +------------------------------- + +.. py:function:: paddle.floor_divide(x, y, name=None) + +该OP是逐元素整除算子,输入 ``x`` 与输入 ``y`` 逐元素整除,并将各个位置的输出元素保存到返回结果中。 +输入 ``x`` 与输入 ``y`` 必须可以广播为相同形状, 关于广播规则,请参考 :ref:`use_guide_broadcasting` + +等式为: + +.. math:: + Out = X // Y + +- :math:`X` :多维Tensor。 +- :math:`Y` :多维Tensor。 + +参数: + - x(Tensor)- 多维Tensor。数据类型为int32或int64。 + - y(Tensor)- 多维Tensor。数据类型为int32或int64。 + - name(str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + + +返回: 多维 Tensor, 数据类型与 ``x`` 相同,维度为广播后的形状。 + +返回类型: Tensor + + +**代码示例** + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_x = np.array([2, 3, 8, 7]) + np_y = np.array([1, 5, 3, 3]) + x = paddle.to_tensor(np_x) + y = paddle.to_tensor(np_y) + z = paddle.floor_divide(x, y) + print(z.numpy()) # [2, 0, 2, 2] \ No newline at end of file diff --git a/doc/fluid/api_cn/tensor_cn/floor_mod_cn.rst b/doc/fluid/api_cn/tensor_cn/floor_mod_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..e9b9773c09dfef8d15f85f62edd4ebcb09c86b4b --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/floor_mod_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_tensor_cn_floor_mod: + +floor_mod +------------------------------- +:doc_source: paddle.tensor.remainder + + diff --git a/doc/fluid/api_cn/tensor_cn/full_cn.rst b/doc/fluid/api_cn/tensor_cn/full_cn.rst index 68dc4d658d9fe4b33ac852f1a8c91191a56363bf..5c38053f3aec97423bf7207acbe2085d08ba5236 100644 --- a/doc/fluid/api_cn/tensor_cn/full_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/full_cn.rst @@ -7,12 +7,12 @@ full -该OP创建形状大小为shape并且数据类型为dtype的Tensor,其中元素值均为 ``fill_value``。 +该OP创建形状大小为 ``shape`` 并且数据类型为 ``dtype`` 的Tensor,其中元素值均为 ``fill_value`` 。 参数: - **shape** (list|tuple|Tensor) – 指定创建Tensor的形状(shape), 数据类型为int32 或者int64。 - **fill_value** (bool|float|int|Tensor) - 用于初始化输出Tensor的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若为None,则输出变量的数据类型和输入变量相同,默认值为None。 + - **dtype** (np.dtype|str, 可选)- 输出变量的数据类型。若为None,则输出变量的数据类型和输入变量相同,默认值为None。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:返回一个存储结果的Tensor,数据类型和dtype相同。 @@ -28,13 +28,13 @@ full import paddle - paddle.enable_imperative() # Now we are in imperative mode + paddle.disable_static() # Now we are in imperative mode data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64') #[[0] # [0]] # attr shape is a list which contains Tensor. - positive_3 = paddle.fill_constant([1], "int32", 2) + positive_2 = paddle.fill_constant([1], "int32", 2) data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5) # [[1.5 1.5]] @@ -46,6 +46,6 @@ full # attr fill_value is a Tensor. val = paddle.fill_constant([1], "float32", 2.0) - data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') i + data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') # [[2.0] # [2.0]] diff --git a/doc/fluid/api_cn/tensor_cn/full_like_cn.rst b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst index f0f26348adf85937abf5ad43d992918a557b2826..577143ace8809b55f167750ce475f86110a663d2 100644 --- a/doc/fluid/api_cn/tensor_cn/full_like_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst @@ -11,7 +11,7 @@ full_like 参数: - **x** (Tensor) – 输入Tensor, 输出Tensor和x具有相同的形状,x的数据类型可以是bool,float16,float32,float64,int32,int64。 - **fill_value** (bool|float|int) - 用于初始化输出张量的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为None,则输出变量的数据类型和输入变量相同,默认值为None。 + - **dtype** (np.dtype|str, 可选)- 输出变量的数据类型。若参数为None,则输出变量的数据类型和输入变量相同,默认值为None。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:返回一个存储结果的Tensor,数据类型和dtype相同。 @@ -27,7 +27,7 @@ full_like import paddle import numpy as np - paddle.enable_imperative() # Now we are in imperative mode + paddle.disable_static() # Now we are in imperative mode input = paddle.full(shape=[2, 3], fill_value=0.0, dtype='float32', name='input') output = paddle.full_like(input, 2.0) # [[2. 2. 2.] diff --git a/doc/fluid/api_cn/tensor_cn/index_select_cn.rst b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst index dfb235db5b4f72f04c85dd6b878b7b5568f4344e..0a964a98127467d812da9e49abae0210f293f74f 100644 --- a/doc/fluid/api_cn/tensor_cn/index_select_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst @@ -11,7 +11,7 @@ index_select **参数**: - **x** (Tensor)– 输入Tensor。 ``x`` 的数据类型可以是float32,float64,int32,int64。 - - **index** (Tensor)– 包含索引下标的一维Tensor。 + - **index** (Tensor)– 包含索引下标的1-D Tensor。 - **axis** (int, 可选) – 索引轴,若未指定,则默认选取第0维。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 @@ -36,8 +36,8 @@ index_select [9.0, 10.0, 11.0, 12.0]]) data_index = np.array([0, 1, 1]).astype('int32') - x = paddle.to_variable(data) - index = paddle.to_variable(data_index) + x = paddle.to_tensor(data) + index = paddle.to_tensor(data_index) out_z1 = paddle.index_select(x=x, index=index) #[[1. 2. 3. 4.] # [5. 6. 7. 8.] diff --git a/doc/fluid/api_cn/tensor_cn/isfinite_cn.rst b/doc/fluid/api_cn/tensor_cn/isfinite_cn.rst index 3610ae0c48068f714ac339d240e1295276f8dff5..0cc20e3e2335cc100d6275c6936d7bc347b17454 100644 --- a/doc/fluid/api_cn/tensor_cn/isfinite_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/isfinite_cn.rst @@ -1,7 +1,30 @@ -.. _cn_api_tensor_cn_isfinite: +.. _cn_api_tensor_isfinite: isfinite -------------------------------- -:doc_source: paddle.fluid.layers.isfinite +----------------------------- +.. py:function:: paddle.tensor.isfinite(x, name=None) +返回输入tensor的每一个值是否为 `Finite` (既非 `+/-INF` 也非 `+/-NaN` )。 + +参数 +::::::::: + - **x** (Tensor): 输入的 `Tensor` ,数据类型为:float16、float32、float64、int32、int64。 + - **name** (str, 可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor``, 每个元素是一个bool值,表示输入 `x` 的每个元素是否为 `Finite` (既非 `+/-INF` 也非 `+/-NaN` )。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + x_np = np.array([float('-inf'), -2, 3.6, float('inf'), 0, float('-nan'), float('nan')]) + x = paddle.to_tensor(x_np) + out = paddle.tensor.isfinite(x) + print(out.numpy()) # [False True True False True False False] diff --git a/doc/fluid/api_cn/tensor_cn/isinf_cn.rst b/doc/fluid/api_cn/tensor_cn/isinf_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..1fdd20485f6c504d5dfcbd18198a5475eac79872 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/isinf_cn.rst @@ -0,0 +1,30 @@ +.. _cn_api_tensor_isinf: + +isinf +----------------------------- + +.. py:function:: paddle.tensor.isinf(x, name=None) + +返回输入tensor的每一个值是否为 `+/-INF` 。 + +参数 +::::::::: + - **x** (Tensor): 输入的 `Tensor` ,数据类型为:float16、float32、float64、int32、int64。 + - **name** (str, 可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor``, 每个元素是一个bool值,表示输入 `x` 的每个元素是否为 `+/-INF` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + x_np = np.array([float('-inf'), -2, 3.6, float('inf'), 0, float('-nan'), float('nan')]) + x = paddle.to_tensor(x_np) + out = paddle.tensor.isinf(x) + print(out.numpy()) # [ True False False True False False False] diff --git a/doc/fluid/api_cn/tensor_cn/isnan_cn.rst b/doc/fluid/api_cn/tensor_cn/isnan_cn.rst index 2f22289cc74472058687a5ace267fc7ff66ebe00..5765ebf184254b87a72c9b5eb8a142d6cef879b1 100644 --- a/doc/fluid/api_cn/tensor_cn/isnan_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/isnan_cn.rst @@ -1,3 +1,30 @@ +.. _cn_api_tensor_isnan: + isnan -------------------------------- -**版本升级,文档正在开发中** +----------------------------- + +.. py:function:: paddle.tensor.isnan(x, name=None) + +返回输入tensor的每一个值是否为 `+/-NaN` 。 + +参数 +::::::::: + - **x** (Tensor): 输入的 `Tensor` ,数据类型为:float16、float32、float64、int32、int64。 + - **name** (str, 可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor``, 每个元素是一个bool值,表示输入 `x` 的每个元素是否为 `+/-NaN` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + x_np = np.array([float('-inf'), -2, 3.6, float('inf'), 0, float('-nan'), float('nan')]) + x = paddle.to_tensor(x_np) + out = paddle.tensor.isnan(x) + print(out.numpy()) # [False False False False False True True] diff --git a/doc/fluid/api_cn/tensor_cn/linspace_cn.rst b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst index 7c228c413e9f167ca92fd547a25c8aa3ad233aeb..818a8da568e09547ce0279788a64f18ae0f35c97 100644 --- a/doc/fluid/api_cn/tensor_cn/linspace_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst @@ -5,36 +5,32 @@ linspace .. py:function:: paddle.linspace(start, stop, num, dtype=None, name=None) -:alias_main: paddle.linspace -:alias: paddle.tensor.linspace, paddle.tensor.creation.linspace - - - 该OP返回一个Tensor,Tensor的值为在区间start和stop上均匀间隔的num个值,输出Tensor的长度为num。 - **注意:该OP不进行梯度计算** 参数: - - **start** (float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **stop** (float|Tensor) – ``end`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **start** (int|float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32,float64,int32 或者int64。 + - **stop** (int|float|Tensor) – ``stop`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32,float64,int32或者int64。 - **num** (int|Tensor) – ``num`` 是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 - - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) – 输出Tensor的数据类型,可以是float32或者是float64。如果dtype为None,默认类型为float32。 - - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - -返回:输出结果的数据类型是float32或float64,表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。 + - **dtype** (np.dtype|str, 可选) – 输出Tensor的数据类型。数据类型可以是float32,float64,int32,int64。如果dtype的数据类型为None,输出Tensor数据类型为float32。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回类型:Variable +返回:表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。 抛出异常: - - ``TypeError`` - 当start或者stop的数据类型不是float32或者float64。 - - ``TypeError`` - 当num的数据类型不是float32或者float64。 - - ``TypeError`` - 当dtype的类型不是float32或者float64。 + - ``TypeError`` - 当 ``start`` 或者 ``stop`` 的数据类型不是float32,float64,int32或者int64。 + - ``TypeError`` - 当 ``dtype`` 的类型不是float32,float64,int32或者int64。 + - ``TypeError`` - ``num`` 的类型必须是int当 ``num`` 不是Tensor的时候。 + - ``TypeError`` - ``num`` 的数据类型必须是int32当 ``num`` 是Tensor的时候。 + **代码示例**: .. code-block:: python import paddle + + paddle.disable_static() data = paddle.linspace(0, 10, 5, dtype='float32') # [0.0, 2.5, 5.0, 7.5, 10.0] data = paddle.linspace(0, 10, 1, dtype='float32') # [0.0] diff --git a/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst b/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst index a339972f9c24ebacdd555a3f04580957e2ad01a8..c95d8d611840f53c99f2205dad88139a0633694f 100644 --- a/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst @@ -3,52 +3,35 @@ logsumexp ------------------------------- -.. py:function:: paddle.tensor.math.logsumexp(x, dim=None, keepdim=False, out=None, name=None) +.. py:function:: paddle.tensor.math.logsumexp(x, axis=None, keepdim=False, name=None) -:alias_main: paddle.logsumexp -:alias: paddle.logsumexp,paddle.tensor.logsumexp,paddle.tensor.math.logsumexp - - - -该OP对输入Tensor的元素以e为底做指数运算,然后根据指定维度做求和之后取自然对数 +该OP沿着 ``axis`` 计算 ``x`` 的以e为底的指数的和的自然对数。计算公式如下: .. math:: logsumexp(x) = \log\sum exp(x) -参数: - - **x** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64 - - **dim** (list | int ,可选)- 求和运算的维度。如果为None,则计算所有元素的和并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 - - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - - **out** (Variable , 可选)- 显示指定的输出变量 - - **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 +参数 +:::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64 。 + - axis (int|list|tuple, 可选) - 指定对 ``x`` 进行计算的轴。``axis`` 可以是int、list(int)、tuple(int)。如果 ``axis`` 包含多个维度,则沿着 ``axis`` 中的所有轴进行计算。``axis`` 或者其中的元素值应该在范围[-D, D)内,D是 ``x`` 的维度。如果 ``axis`` 或者其中的元素值小于0,则等价于 :math:`axis + D` 。如果 ``axis`` 是None,则对 ``x`` 的全部元素计算平均值。默认值为None。 + - keepdim (bool, 可选) - 是否在输出Tensor中保留减小的维度。如果 ``keepdim`` 为True,则输出Tensor和 ``x`` 具有相同的维度(减少的维度除外,减少的维度的大小为1)。否则,输出Tensor的形状会在 ``axis`` 上进行squeeze操作。默认值为False。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 -返回: Tensor,数据类型和输入数据类型一致。 +返回 +:::::::::: + ``Tensor`` ,沿着 ``axis`` 进行logsumexp计算的结果,数据类型和 ``x`` 相同。 -返回类型:Variable +代码示例 +:::::::::: -**代码示例1** - -.. code-block:: python +.. code-block:: python import paddle - import paddle.fluid as fluid import numpy as np - 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()) - -**代码示例2** - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np + paddle.disable_static() - 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()) + x = np.array([[-1.5, 0., 2.], [3., 1.2, -2.4]]) + x = paddle.to_tensor(x) + out1 = paddle.logsumexp(x) # [3.4691226] + out2 = paddle.logsumexp(x, 1) # [2.15317821, 3.15684602] diff --git a/doc/fluid/api_cn/tensor_cn/mod_cn.rst b/doc/fluid/api_cn/tensor_cn/mod_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b7f34c81e5937ac5ed96e7b63a9d2cc080c5b01d --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/mod_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_tensor_cn_mod: + +mod +------------------------------- +:doc_source: paddle.tensor.remainder + + diff --git a/doc/fluid/api_cn/tensor_cn/normal_cn.rst b/doc/fluid/api_cn/tensor_cn/normal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..bcefb2f566e339cbc7fa220f33cda0f7e9e21749 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/normal_cn.rst @@ -0,0 +1,48 @@ +.. _cn_api_tensor_normal: + +normal +------------------------------- + +.. py:function:: paddle.normal(mean=0.0, std=1.0, shape=None, name=None) + + +该OP返回符合正态分布(均值为 ``mean`` ,标准差为 ``std`` 的正态随机分布)的随机Tensor。 + +如果 ``mean`` 是Tensor,则输出Tensor和 ``mean`` 具有相同的形状和数据类型。 +如果 ``mean`` 不是Tensor,且 ``std`` 是Tensor,则输出Tensor和 ``std`` 具有相同的形状和数据类型。 +如果 ``mean`` 和 ``std`` 都不是Tensor,则输出Tensor的形状为 ``shape``,数据类型为float32。 + +如果 ``mean`` 和 ``std`` 都是Tensor,则 ``mean`` 和 ``std`` 的元素个数应该相同。 + +参数 +:::::::::: + - mean (float|Tensor, 可选) - 输出Tensor的正态分布的平均值。如果 ``mean`` 是float,则表示输出Tensor中所有元素的正态分布的平均值。如果 ``mean`` 是Tensor(支持的数据类型为float32、float64),则表示输出Tensor中每个元素的正态分布的平均值。默认值为0.0 + - std (float|Tensor, 可选) - 输出Tensor的正态分布的标准差。如果 ``std`` 是float,则表示输出Tensor中所有元素的正态分布的标准差。如果 ``std`` 是Tensor(支持的数据类型为float32、float64),则表示输出Tensor中每个元素的正态分布的标准差。默认值为0.0 + - shape (list|tuple|Tensor, 可选) - 生成的随机Tensor的形状。如果 ``shape`` 是list、tuple,则其中的元素可以是int,或者是形状为[1]且数据类型为int32、int64的Tensor。如果 ``shape`` 是Tensor,则是数据类型为int32、int64的1-D Tensor。如果 ``mean`` 或者 ``std`` 是Tensor,输出Tensor的形状和 ``mean`` 或者 ``std`` 相同(此时 ``shape`` 无效)。默认值为None。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + Tensor:符合正态分布(均值为 ``mean`` ,标准差为 ``std`` 的正态随机分布)的随机Tensor。 + +示例代码 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + out1 = paddle.normal(shape=[2, 3]) + # [[ 0.17501129 0.32364586 1.561118 ] + # [-1.7232178 1.1545963 -0.76156676]] + + mean_tensor = paddle.to_tensor(np.array([1.0, 2.0, 3.0])) + out2 = paddle.normal(mean=mean_tensor) + # [ 0.18644847 -1.19434458 3.93694787] + + std_tensor = paddle.to_tensor(np.array([1.0, 2.0, 3.0])) + out3 = paddle.normal(mean=mean_tensor, std=std_tensor) + # [1.00780561 3.78457445 5.81058198] diff --git a/doc/fluid/api_cn/tensor_cn/numel_cn.rst b/doc/fluid/api_cn/tensor_cn/numel_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..55972ed200888334d8a040ad1adfb77e76dd5b9b --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/numel_cn.rst @@ -0,0 +1,29 @@ +.. _cn_api_tensor_numel: + +numel +------------------------------- + +.. py:function:: paddle.numel(x) + + +该OP返回一个长度为1并且元素值为输入 ``x`` 元素个数的Tensor。 + +参数: + - **x** (Tensor) - 输入Tensor,数据类型为int32,int64, float16, float32, float64, int32, int64 。 + +返回: 返回长度为1并且元素值为 ``x`` 元素个数的Tensor。 + + +抛出异常: + - ``TypeError`` - 当 ``x`` 不是Tensor或者 ``x`` 的数据类型不是bool、float16、float32、float64、int32或int64中的一个的时候 + +**代码示例**: + +.. code-block:: python + + import paddle + + paddle.disable_static() + x = paddle.full(shape=[4, 5, 7], fill_value=0, dtype='int32') + numel = paddle.numel(x) # 140 + diff --git a/doc/fluid/api_cn/tensor_cn/ones_cn.rst b/doc/fluid/api_cn/tensor_cn/ones_cn.rst index fa13c3412fd1d741d129987b415e4ac33a956557..05e9ded48eab47f1a2530e8f45f11a727fd71796 100644 --- a/doc/fluid/api_cn/tensor_cn/ones_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/ones_cn.rst @@ -11,7 +11,7 @@ ones 参数: - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。如果 ``dtype`` 为None,默认数据类型为float32。 + - **dtype** (np.dtype|str, 可选) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。如果 ``dtype`` 为None,默认数据类型为float32。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。 @@ -27,7 +27,7 @@ ones import paddle - paddle.enable_imperative() + paddle.disable_static() #default dtype for ones OP data1 = paddle.ones(shape=[3, 2]) diff --git a/doc/fluid/api_cn/tensor_cn/prod_cn.rst b/doc/fluid/api_cn/tensor_cn/prod_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2956d791176f1f779690587be4d494fdde00ed13 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/prod_cn.rst @@ -0,0 +1,72 @@ +.. _cn_api_tensor_cn_prod: + +prod +------------------------------- + +.. py:function:: paddle.prod(x, axis=None, keepdim=False, dtype=None, name=None) + + + +对指定维度上的Tensor元素进行求乘积运算,并输出相应的计算结果。 + +参数: + - **x** (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64、int32、int64。 + - **axis** (int|list|tuple,可选) - 求乘积运算的维度。如果是None,则计算所有元素的乘积并返回包含单个元素的Tensor,否则该参数必须在 :math:`[-x.ndim, x.ndim)` 范围内。如果 :math:`axis[i] < 0` ,则维度将变为 :math:`x.ndim + axis[i]` ,默认为None。 + - **keepdim** (bool,可选) - 是否在输出 `Tensor` 中保留减小的维度。如 `keepdim` 为True,否则结果张量的维度将比输入张量小,默认值为False。 + - **dtype** (str,可选) - 输出Tensor的数据类型,支持int32、int64、float32、float64。如果指定了该参数,那么在执行操作之前,输入Tensor将被转换为dtype类型. 这对于防止数据类型溢出非常有用。若参数为空,则输出变量的数据类型和输入变量相同,默认为:None。 + - **name** (str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回:指定axis上累乘的结果的Tensor。 + +抛出异常: + - :code:`ValueError`:``dtype`` 的数据类型不是float32、float64、int32或int64时。 + - :code:`ValueError`:``axis`` 的数据类型不是int、list或tuple时 + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + # the axis is a int element + data_x = np.array([[0.2, 0.3, 0.5, 0.9], + [0.1, 0.2, 0.6, 0.7]]).astype(np.float32) + x = paddle.to_tensor(data_x) + out1 = paddle.prod(x) + print(out1.numpy()) + # [0.0002268] + + out2 = paddle.prod(x, -1) + print(out2.numpy()) + # [0.027 0.0084] + + out3 = paddle.prod(x, 0) + print(out3.numpy()) + # [0.02 0.06 0.3 0.63] + print(out3.numpy().dtype) + # float32 + + out4 = paddle.prod(x, 0, keepdim=True) + print(out4.numpy()) + # [[0.02 0.06 0.3 0.63]] + + out5 = paddle.prod(x, 0, dtype='int64') + print(out5.numpy()) + # [0 0 0 0] + print(out5.numpy().dtype) + # int64 + + # the axis is list + data_y = np.array([[[1.0, 2.0], [3.0, 4.0]], + [[5.0, 6.0], [7.0, 8.0]]]) + y = paddle.to_tensor(data_y) + out6 = paddle.prod(y, [0, 1]) + print(out6.numpy()) + # [105. 384.] + + out7 = paddle.prod(y, (1, 2)) + print(out7.numpy()) + # [ 24. 1680.] diff --git a/doc/fluid/api_cn/tensor_cn/remainder_cn.rst b/doc/fluid/api_cn/tensor_cn/remainder_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ccf124eb8a344c65e216f368d8b748c20c484a0f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/remainder_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_tensor_remainder: + +remainder +------------------------------- + +.. py:function:: paddle.remainder(x, y, name=None) + +该OP是逐元素取模算子,输入 ``x`` 与输入 ``y`` 逐元素取模,并将各个位置的输出元素保存到返回结果中。 +输入 ``x`` 与输入 ``y`` 必须可以广播为相同形状, 关于广播规则,请参考 :ref:`use_guide_broadcasting` + +等式为: + +.. math:: + Out = X \% Y + +- :math:`X` :多维Tensor。 +- :math:`Y` :多维Tensor。 + +参数: + - x(Tensor)- 多维Tensor。数据类型为float32 、float64、int32或int64。 + - y(Tensor)- 多维Tensor。数据类型为float32 、float64、int32或int64。 + - name(str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + + +返回: 多维 Tensor, 数据类型与 ``x`` 相同,维度为广播后的形状。 + +返回类型: Tensor + + +**代码示例** + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + np_x = np.array([2, 3, 8, 7]) + np_y = np.array([1, 5, 3, 3]) + x = paddle.to_tensor(np_x) + y = paddle.to_tensor(np_y) + z = paddle.remainder(x, y) + print(z.numpy()) # [0, 3, 2, 1] \ No newline at end of file diff --git a/doc/fluid/api_cn/tensor_cn/reshape_cn.rst b/doc/fluid/api_cn/tensor_cn/reshape_cn.rst index 9b70e1c224120eb4e1ce256172b72679923eac35..df0989ac47d62f5953012c253f872905134437d8 100644 --- a/doc/fluid/api_cn/tensor_cn/reshape_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/reshape_cn.rst @@ -2,6 +2,68 @@ reshape ------------------------------- -:doc_source: paddle.fluid.layers.reshape +.. py:function:: paddle.reshape(x, shape, name=None) +:alias_main: paddle.reshape +:alias: paddle.reshape,paddle.tensor.reshape,paddle.tensor.manipulation.reshape + + +该OP在保持输入 ``x`` 数据不变的情况下,改变 ``x`` 的形状。 + +在指定目标shape时存在一些技巧: + +.. code-block:: text + + 1. -1 表示这个维度的值是从x的元素总数和剩余维度推断出来的。因此,有且只有一个维度可以被设置为-1。 + 2. 0 表示实际的维数是从x的对应维数中复制出来的,因此shape中0的索引值不能超过x的维度。 + + +这里有一些例子来解释它们: + +.. code-block:: text + + 1. 给定一个形状为[2,4,6]的三维张量x,目标形状为[6,8],则将x变换为形状为[6,8]的2-D张量,且x的数据保持不变。 + 2. 给定一个形状为[2,4,6]的三维张量x,目标形状为[2,3,-1,2],则将x变换为形状为[2,3,4,2]的4-D张量,且x的数据保持不变。在这种情况下,目标形状的一个维度被设置为-1,这个维度的值是从x的元素总数和剩余维度推断出来的。 + 3. 给定一个形状为[2,4,6]的三维张量x,目标形状为[-1,0,3,2],则将x变换为形状为[2,4,3,2]的4-D张量,且x的数据保持不变。在这种情况下,0对应位置的维度值将从x的对应维数中复制,-1对应位置的维度值由x的元素总数和剩余维度推断出来。 + + +参数: + - **x** (Tensor)- 多维 ``Tensor``,数据类型为 ``float32``,``float64``,``int32``,或 ``int64``。 + - **shape** (list|tuple|Tensor)- 数据类型是 ``int32`` 。定义目标形状。目标形状最多只能有一个维度为-1。如果 ``shape`` 的类型是 list 或 tuple, 它的元素可以是整数或者形状为[1]的 ``Tensor`` 或 ``LoDTensor``。如果 ``shape`` 的类型是 ``Tensor``,则是1-D的 ``Tensor`` 或 ``LoDTensor``。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置。默认值: ``None``。 + +返回: +::::::::: +``Tensor``, 改变形状后的 ``Tensor``,数据类型与 ``x`` 相同。 + + +抛出异常: + - :code:`TypeError`:``starts`` 的类型应该是list、tuple 或 Tensor。 + - :code:`ValueError`:``shape`` 中至多有一个元素可以是-1。 + - :code:`ValueError`:``shape`` 中的元素为0时,对应的维度应该小于等于``x``的维度。 + - :code:`ValueError`:``shape`` 中的元素除了-1之外,都应该是非负值。 + +**代码示例** + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + + data = np.random.random([2, 4, 6]).astype("float32") + x = paddle.to_tensor(data) + + positive_four = paddle.fill_constant([1], "int32", 4) + + out_1 = paddle.reshape(x, [-1, 0, 3, 2]) + # the shape of out_1 is [2,4,3,2]. + + out_2 = paddle.reshape(x, shape=[positive_four, 12]) + # the shape of out_2 is [4, 12]. + + shape_tensor = paddle.to_tensor(np.array([8, 6]).astype("int32")) + out_3 = paddle.reshape(x, shape=shape_tensor) + # the shape of out_2 is [8, 6]. diff --git a/doc/fluid/api_cn/tensor_cn/sign_cn.rst b/doc/fluid/api_cn/tensor_cn/sign_cn.rst index becd204197a6fcb00f0260ed8a5c20b2d444da08..e1443fc2dfa3aedf65a2997f6b10bd91593d6325 100644 --- a/doc/fluid/api_cn/tensor_cn/sign_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/sign_cn.rst @@ -1,7 +1,30 @@ -.. _cn_api_tensor_cn_sign: +.. _cn_api_tensor_sign: sign ------------------------------- -:doc_source: paddle.fluid.layers.sign +.. py:function:: paddle.sign(x, name=None) + +此OP对输入x中每个元素进行正负判断,并且输出正负判断值:1代表正,-1代表负,0代表零。 + +参数: + - **x** (Tensor) – 进行正负值判断的多维Tensor,数据类型为 float16, float32或float64。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:输出正负号Tensor,数据的shape大小及数据类型和输入 ``x`` 一致。 + +返回类型:Tensor + +**代码示例** + +.. code-block:: python + + import numpy as np + import paddle + + data = np.array([3.0, 0.0, -2.0, 1.7], dtype='float32') + paddle.disable_static() + x = paddle.to_tensor(data) + out = paddle.sign(x=x) + print(out) # [1.0, 0.0, -1.0, 1.0] diff --git a/doc/fluid/api_cn/tensor_cn/split_cn.rst b/doc/fluid/api_cn/tensor_cn/split_cn.rst index 52f85fcccef62b2dc97d34bb4626b8fbefa1435b..9c1293baf3fb9793ff079a38d18459d24bef7cf8 100644 --- a/doc/fluid/api_cn/tensor_cn/split_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/split_cn.rst @@ -17,7 +17,7 @@ split 返回:分割后的Tensor列表。 抛出异常: - - :code:`TypeError`:``x`` 的数据类型不是float16、float32、float64、int32或int64时 。 + - :code:`TypeError`:``x`` 的数据类型不是bool、float16、float32、float64、int32或int64时 。 - :code:`TypeError`:``num_or_sections`` 不是int、list 或 tuple时。 - :code:`TypeError`:``axis`` 不是 int 或 Tensor时。当 ``axis`` 为Tensor,其数据类型不是int32或int64时。 @@ -28,10 +28,10 @@ split import numpy as np import paddle - paddle.enable_imperative() + paddle.disable_static() # x is a Tensor which shape is [3, 9, 5] x_np = np.random.random([3, 9, 5]).astype("int32") - x = paddle.imperative.to_variable(x_np) + x = paddle.to_tensor(x_np) out0, out1, out22 = paddle.split(x, num_or_sections=3, axis=1) # out0.shape [3, 3, 5] diff --git a/doc/fluid/api_cn/tensor_cn/standard_normal_cn.rst b/doc/fluid/api_cn/tensor_cn/standard_normal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ef21c863e5e9c7608cfa439d3c79f85150a942dc --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/standard_normal_cn.rst @@ -0,0 +1,56 @@ +.. _cn_api_tensor_random_standard_normal: + +standard_normal +------------------------------- + +.. py:function:: paddle.standard_normal(shape, dtype=None, name=None) + + +该OP返回符合标准正态分布(均值为0,标准差为1的正态随机分布)的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +参数 +:::::::::: + - **shape** (list|tuple|Tensor) - 生成的随机Tensor的形状。如果 ``shape`` 是list、tuple,则其中的元素可以是int,或者是形状为[1]且数据类型为int32、int64的Tensor。如果 ``shape`` 是Tensor,则是数据类型为int32、int64的1-D Tensor。 + - **dtype** (str|np.dtype|core.VarDesc.VarType, 可选) - 输出Tensor的数据类型,支持float32、float64。当该参数值为None时, 输出Tensor的数据类型为float32。默认值为None. + - **name** (str, 可选) - 输出的名字。一般无需设置,默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + +返回 +:::::::::: + Tensor:符合标准正态分布的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +抛出异常 +:::::::::: + - ``TypeError`` - 如果 ``shape`` 的类型不是list、tuple、Tensor。 + - ``TypeError`` - 如果 ``dtype`` 不是float32、float64。 + +示例代码 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + # example 1: attr shape is a list which doesn't contain Tensor. + result_1 = paddle.standard_normal(shape=[2, 3]) + # [[-2.923464 , 0.11934398, -0.51249987], + # [ 0.39632758, 0.08177969, 0.2692008 ]] + + # example 2: attr shape is a list which contains Tensor. + dim_1 = paddle.fill_constant([1], "int64", 2) + dim_2 = paddle.fill_constant([1], "int32", 3) + result_2 = paddle.standard_normal(shape=[dim_1, dim_2, 2]) + # [[[-2.8852394 , -0.25898588], + # [-0.47420555, 0.17683524], + # [-0.7989969 , 0.00754541]], + # [[ 0.85201347, 0.32320443], + # [ 1.1399018 , 0.48336947], + # [ 0.8086993 , 0.6868893 ]]] + + # example 3: attr shape is a Tensor, the data type must be int64 or int32. + var_shape = paddle.to_tensor(np.array([2, 3])) + result_3 = paddle.standard_normal(var_shape) + # [[-2.878077 , 0.17099959, 0.05111201] + # [-0.3761474, -1.044801 , 1.1870178 ]] diff --git a/doc/fluid/api_cn/tensor_cn/std_cn.rst b/doc/fluid/api_cn/tensor_cn/std_cn.rst index 30aa83d07a730c336e7f1ca7c6df79a88dd93778..eb30280cc8b88e4ced5e54e1ad62ecda4af5f5d1 100644 --- a/doc/fluid/api_cn/tensor_cn/std_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/std_cn.rst @@ -1,39 +1,37 @@ +.. _cn_api_tensor_cn_std: + std ------------------------------- -.. py:function:: paddle.std(input, axis=None, keepdim=False, unbiased=True, out=None, name=None) - -:alias_main: paddle.std -:alias: paddle.std,paddle.tensor.std,paddle.tensor.stat.std - - - -根据指定的axis计算input的标准差。 +.. py:function:: paddle.std(x, axis=None, unbiased=True, keepdim=False, name=None) -参数: - - **input** (Variable) - 数据类型为float32,float64。要计算标准差的输入。 - - **axis** (list|int, 可选) - 根据axis计算标准差。如果设为 `None`,计算 :attr:`input` 的所有元素的标准差并返回shape为[1]的单个结果。如果不是 `None`, 则设定的axis的值必须在 :math:`[-rank(input), rank(input))` 范围内。 如果 :math:`axis[i] < 0`, 则要计算的axis是 :math:`rank(input) + axis[i]`。 - - **keepdim** (bool, 可选) - 是否在输出中保留减小的维度。如 keep_dim 为False,输出张量的维度将比输入张量小, 为True时则维度相同。默认值:False。 - - **unbiased** (bool, 可选) - 是否使用无偏估计来计算标准差。使用 :math:`N` 来代表在axis上的维度,如果 unbiased 为True, 则在计算中使用 :math:`N - 1` 作为除数。为False时将使用 :math:`N` 作为除数。默认值:True。 - - **out** (Variable, 可选) - 如果out不是None, 则将标准差结果存储在out中。默认值:None。 - - **name** (str,可选) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值:None。 +沿给定的轴 ``axis`` 计算 ``x`` 中元素的标准差。 +参数 +:::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。 + - axis (int|list|tuple, 可选) - 指定对 ``x`` 进行计算的轴。``axis`` 可以是int、list(int)、tuple(int)。如果 ``axis`` 包含多个维度,则沿着 ``axis`` 中的所有轴进行计算。``axis`` 或者其中的元素值应该在范围[-D, D)内,D是 ``x`` 的维度。如果 ``axis`` 或者其中的元素值小于0,则等价于 :math:`axis + D` 。如果 ``axis`` 是None,则对 ``x`` 的全部元素计算标准差。默认值为None。 + - unbiased (bool, 可选) - 是否使用无偏估计来计算标准差。使用 :math:`N` 来代表在 axis 上的维度,如果 ``unbiased`` 为True, 则在计算中使用 :math:`N - 1` 作为除数。为 False 时将使用 :math:`N` 作为除数。默认值为True。 + - keepdim (bool, 可选) - 是否在输出Tensor中保留减小的维度。如果 ``keepdim`` 为True,则输出Tensor和 ``x`` 具有相同的维度(减少的维度除外,减少的维度的大小为1)。否则,输出Tensor的形状会在 ``axis`` 上进行squeeze操作。默认值为False。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 -返回: 计算出来的标准差。 +返回 +:::::::::: + ``Tensor`` ,沿着 ``axis`` 进行标准差计算的结果,数据类型和 ``x`` 相同。 -返回类型: Variable(Tensor) ,数据类型和 :attr:`input` 相同。如果 :attr:`out = None`, 返回包含标准差的新Variable , 否则的话返回 :attr:`out` 的引用。 - -**代码示例** +代码示例 +:::::::::: .. code-block:: python - + import paddle - import paddle.fluid as fluid - # x is a Tensor variable with following elements: - # [[0.2, 0.3, 0.5, 0.9] - # [0.1, 0.2, 0.6, 0.7]] - # Each example is followed by the corresponding output tensor. - x = fluid.data(name='x', shape=[2, 4], dtype='float32') - paddle.std(x) # [0.28252685] - paddle.std(x, axis=[0]) # [0.0707107, 0.07071075, 0.07071064, 0.1414217] - paddle.std(x, axis=[-1]) # [0.30956957, 0.29439208] \ No newline at end of file + import numpy as np + + paddle.disable_static() + + x = np.array([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]]) + x = paddle.to_tensor(x) + out1 = paddle.std(x) + # [1.63299316] + out2 = paddle.std(x, axis=1) + # [1. 2.081666] diff --git a/doc/fluid/api_cn/tensor_cn/sum_cn.rst b/doc/fluid/api_cn/tensor_cn/sum_cn.rst index 89825e0b4254f68efd155310f7db1edbd391c82e..47afc379c37747e1c87c2e53d0eea7276899818b 100644 --- a/doc/fluid/api_cn/tensor_cn/sum_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/sum_cn.rst @@ -3,47 +3,45 @@ sum ------------------------------- -.. py:function:: paddle.sum(input, dim=None, dtype=None, keep_dim=False, name=None) - -:alias_main: paddle.sum -:alias: paddle.sum,paddle.tensor.sum,paddle.tensor.math.sum -:update_api: paddle.fluid.layers.reduce_sum - - +.. py:function:: paddle.sum(x, axis=None, dtype=None, keepdim=False, name=None) 该OP是对指定维度上的Tensor元素进行求和运算,并输出相应的计算结果。 参数: - - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 - - **dim** (list | int ,可选)- 求和运算的维度。如果为None,则计算所有元素的和并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **x** (Tensor)- 输入变量为多维Tensor,支持数据类型为float32,float64,int32,int64。 + - **axis** (int | list | tuple ,可选)- 求和运算的维度。如果为None,则计算所有元素的和并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(x),rank(x)]` 范围内。如果 :math:`axis [i] <0` ,则维度将变为 :math:`rank+axis[i]` ,默认值为None。 - **dtype** (str , 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。 - - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 + - **keepdim** (bool)- 是否在输出Tensor中保留减小的维度。如 keepdim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回: 在指定dim上进行求和运算的Tensor,数据类型和输入数据类型一致。 +返回: + ``Tensor``,在指定维度上进行求和运算的Tensor,数据类型和输入数据类型一致。 -返回类型: 变量(Variable) **代码示例** .. code-block:: python - import paddle - import paddle.fluid as fluid - # x是一个Tensor,元素如下: - # [[0.2, 0.3, 0.5, 0.9] - # [0.1, 0.2, 0.6, 0.7]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - x = fluid.data(name='x', shape=[2, 4], dtype='float32') - out1 = paddle.sum(x) # [3.5] - out2 = paddle.sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6] - out3 = paddle.sum(x, dim=-1) # [1.9, 1.6] - out4 = paddle.sum(x, dim=1, keep_dim=True) # [[1.9], [1.6]] - - # y 是一个shape为[2, 2, 2]的Tensor元素如下: - # [[[1, 2], [3, 4]], - # [[5, 6], [7, 8]]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') - out5 = paddle.sum(y, dim=[1, 2]) # [10, 26] - out6 = paddle.sum(y, dim=[0, 1]) # [16, 20] + import numpy as np + import paddle + paddle.disable_static() + + # x is a Tensor variable with following elements: + # [[0.2, 0.3, 0.5, 0.9] + # [0.1, 0.2, 0.6, 0.7]] + # Each example is followed by the corresponding output tensor. + x_data = np.array([[0.2, 0.3, 0.5, 0.9],[0.1, 0.2, 0.6, 0.7]]).astype('float32') + x = paddle.to_tensor(x_data) + out1 = paddle.sum(x) # [3.5] + out2 = paddle.sum(x, axis=0) # [0.3, 0.5, 1.1, 1.6] + out3 = paddle.sum(x, axis=-1) # [1.9, 1.6] + out4 = paddle.sum(x, axis=1, keepdim=True) # [[1.9], [1.6]] + + # y is a Tensor variable with shape [2, 2, 2] and elements as below: + # [[[1, 2], [3, 4]], + # [[5, 6], [7, 8]]] + # Each example is followed by the corresponding output tensor. + y_data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]).astype('float32') + y = paddle.to_tensor(y_data) + out5 = paddle.sum(y, axis=[1, 2]) # [10, 26] + out6 = paddle.sum(y, axis=[0, 1]) # [16, 20] diff --git a/doc/fluid/api_cn/tensor_cn/tanh_cn.rst b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst index 84e295cb73c3be0d40d43ca571500232d0dbc7ac..ee81756c3cf07006510b44204f56ebdc43ffa442 100644 --- a/doc/fluid/api_cn/tensor_cn/tanh_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst @@ -3,44 +3,35 @@ tanh ------------------------------- -.. py:function:: paddle.tanh(x, name=None, out=None) - -:alias_main: paddle.tanh -:alias: paddle.tanh,paddle.tensor.tanh,paddle.tensor.math.tanh -:update_api: paddle.fluid.layers.tanh - +.. py:function:: paddle.tanh(x, name=None) tanh 激活函数 .. math:: - out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} - + out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} 参数: - - **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。 - - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **x** (Tensor) - Tanh算子的输入, 多维Tensor,数据类型为 float16,float32或float64。 + - **name** (str, 可选) - 该层名称(可选,默认为None)。具体用法请参见 :ref:`api_guide_Name`。 -返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 +返回: tanh的输出Tensor,和输入有着相同类型和shape。 + +返回类型: Tensor **代码示例**: .. code-block:: python - import numpy as np - import paddle - import paddle.fluid as fluid - - inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') - output = paddle.tanh(inputs) + import paddle + import numpy as np - exe = fluid.Executor(fluid.CPUPlace()) - exe.run(fluid.default_startup_program()) + paddle.disable_static() - img = np.array([0, 0.5, 0.3]).astype(np.float32) + x_data = np.array([-0.4, -0.2, 0.1, 0.3]) + x = paddle.to_tensor(x_data) + out = paddle.tanh(x) + print(out.numpy()) + # [-0.37994896 -0.19737532 0.09966799 0.29131261] - res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) - print(res) - # [array([0., 0.46211717, 0.2913126], dtype=float32)] diff --git a/doc/fluid/api_cn/tensor_cn/tile_cn.rst b/doc/fluid/api_cn/tensor_cn/tile_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3d8e989d4fbf50ce7e87148fd101adc417b567e5 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/tile_cn.rst @@ -0,0 +1,45 @@ +.. _cn_api_tensor_tile: + +tile +------------------------------- + +.. py:function:: paddle.tile(x, repeat_times, name=None) + +根据参数 ``repeat_times`` 对输入 ``x`` 的各维度进行复制。 + +``x`` 的维数和 ``repeat_times`` 中的元素数量应小于等于6,并且repeat_times中的元素数量应该小于等于6。 + +参数 +::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:bool、float32、float64、int32或int64。 + - repeat_times (list|tuple|Tensor) - 指定输入 ``x`` 每个维度的复制次数。如果 ``repeat_times`` 的类型是list或tuple,它的元素可以是整数或者数据类型为int32的1-D Tensor。如果 ``repeat_times`` 的类型是Tensor,则是数据类型为int32的1-D Tensor。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor`` ,数据类型与 ``x`` 相同。返回值的第i维的大小等于 ``x[i] * repeat_times[i]`` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_data = np.array([1, 2, 3]).astype('int32') + data = paddle.to_tensor(np_data) + out = paddle.tile(data, repeat_times=[2, 1]) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] + + out = paddle.tile(data, repeat_times=[2, 2]) + np_out = out.numpy() + # [[1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3]] + + np_repeat_times = np.array([2, 1]).astype("int32") + repeat_times = paddle.to_tensor(np_repeat_times) + out = paddle.tile(data, repeat_times=repeat_times) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] diff --git a/doc/fluid/api_cn/tensor_cn/uniform_cn.rst b/doc/fluid/api_cn/tensor_cn/uniform_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..f5996a72d4f88a38ad0d71fc84b002c3a69bbd2d --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/uniform_cn.rst @@ -0,0 +1,77 @@ +.. _cn_api_tensor_uniform: + +uniform +------------------------------- + +.. py:function:: paddle.uniform(shape, dtype='float32', min=-1.0, max=1.0, seed=0, name=None) + + + + +该OP返回数值服从范围[``min``, ``max``)内均匀分布的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +:: + + 示例1: + 给定: + shape=[1,2] + 则输出为: + result=[[0.8505902, 0.8397286]] + +参数: + - **shape** (list|tuple|Tensor) - 生成的随机Tensor的形状。如果 ``shape`` 是list、tuple,则其中的元素可以是int,或者是形状为[1]且数据类型为int32、int64的Tensor。如果 ``shape`` 是Tensor,则是数据类型为int32、int64的1-D Tensor。 + - **dtype** (str|np.dtype, 可选) - 输出Tensor的数据类型,支持float32、float64。默认值为float32。 + - **min** (float|int,可选) - 要生成的随机值范围的下限,min包含在范围中。支持的数据类型:float、int。默认值为-1.0。 + - **max** (float|int,可选) - 要生成的随机值范围的上限,max不包含在范围中。支持的数据类型:float、int。默认值为1.0。 + - **seed** (int,可选) - 随机种子,用于生成样本。0表示使用系统生成的种子。注意如果种子不为0,该操作符每次都生成同样的随机数。支持的数据类型:int。默认为 0。 + - **name** (str, 可选) - 输出的名字。一般无需设置,默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + +返回: + Tensor:数值服从范围[``min``, ``max``)内均匀分布的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +抛出异常: + - ``TypeError`` - 如果 ``shape`` 的类型不是list、tuple、Tensor。 + - ``TypeError`` - 如果 ``dtype`` 不是float32、float64。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + + # example 1: + # attr shape is a list which doesn't contain Tensor. + result_1 = paddle.uniform(shape=[3, 4]) + # [[ 0.84524226, 0.6921872, 0.56528175, 0.71690357], + # [-0.34646994, -0.45116323, -0.09902662, -0.11397249], + # [ 0.433519, 0.39483607, -0.8660099, 0.83664286]] + + # example 2: + # attr shape is a list which contains Tensor. + dim_1 = paddle.fill_constant([1], "int64", 2) + dim_2 = paddle.fill_constant([1], "int32", 3) + result_2 = paddle.uniform(shape=[dim_1, dim_2]) + # [[-0.9951253, 0.30757582, 0.9899647 ], + # [ 0.5864527, 0.6607096, -0.8886161 ]] + + # example 3: + # attr shape is a Tensor, the data type must be int64 or int32. + shape = np.array([2, 3]) + shape_tensor = paddle.to_tensor(shape) + + result_3 = paddle.uniform(shape_tensor) + # if shape_tensor's value is [2, 3] + # result_3 is: + # [[-0.8517412, -0.4006908, 0.2551912 ], + # [ 0.3364414, 0.36278176, -0.16085452]] + + + + + + + + diff --git a/doc/fluid/api_cn/tensor_cn/var_cn.rst b/doc/fluid/api_cn/tensor_cn/var_cn.rst index a0ee9e9b7edb2da0371c43bfc160a1ae33c46699..c44af2301a4ee0d192ec66738433014fced92eb2 100644 --- a/doc/fluid/api_cn/tensor_cn/var_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/var_cn.rst @@ -1,38 +1,37 @@ +.. _cn_api_tensor_cn_var: + var ------------------------------- -.. py:function:: paddle.var(input, axis=None, keepdim=False, unbiased=True, out=None, name=None) - -:alias_main: paddle.var -:alias: paddle.var,paddle.tensor.var,paddle.tensor.stat.var - +.. py:function:: paddle.var(x, axis=None, unbiased=True, keepdim=False, name=None) +沿给定的轴 ``axis`` 计算 ``x`` 中元素的方差。 - 沿给定的轴 axis 计算输入变量所有元素的方差。 +参数 +:::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。 + - axis (int|list|tuple, 可选) - 指定对 ``x`` 进行计算的轴。``axis`` 可以是int、list(int)、tuple(int)。如果 ``axis`` 包含多个维度,则沿着 ``axis`` 中的所有轴进行计算。``axis`` 或者其中的元素值应该在范围[-D, D)内,D是 ``x`` 的维度。如果 ``axis`` 或者其中的元素值小于0,则等价于 :math:`axis + D` 。如果 ``axis`` 是None,则对 ``x`` 的全部元素计算方差。默认值为None。 + - unbiased (bool, 可选) - 是否使用无偏估计来计算方差。使用 :math:`N` 来代表在 axis 上的维度,如果 ``unbiased`` 为True, 则在计算中使用 :math:`N - 1` 作为除数。为 False 时将使用 :math:`N` 作为除数。默认值为True。 + - keepdim (bool, 可选) - 是否在输出Tensor中保留减小的维度。如果 ``keepdim`` 为True,则输出Tensor和 ``x`` 具有相同的维度(减少的维度除外,减少的维度的大小为1)。否则,输出Tensor的形状会在 ``axis`` 上进行squeeze操作。默认值为False。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 - 参数: - - **input** (Variable) - 要计算方差的输入变量,支持的数据类型为 float32 或 float64。 - - **axis** (list|int, 可选) - 给定的轴。如果设为 `None`,计算 :attr:`input` 的所有元素的方差并返回形状为 [1] 的单个结果。如果非 `None`, 则给定的 axis 的值必须在 :math:`[-rank(input), rank(input))` 范围内。 如果 :math:`axis[i] < 0`, 则实际的 axis 是 :math:`rank(input) + axis[i]`。 - - **keepdim** (bool, 可选) - 是否在输出中保留被规约的维度。如 keep_dim 为False,输出张量的维度将比输入张量小, 为True时则维度相同。默认值:False。 - - **unbiased** (bool, 可选) - 是否使用无偏估计来计算方差。使用 :math:`N` 来代表在 axis 上的维度,如果 unbiased 为True, 则在计算中使用 :math:`N - 1` 作为除数。为 False 时将使用 :math:`N` 作为除数。默认值:True。 - - **out** (Variable, 可选) - 如果out不是None, 则将方差结果存储在 out 中。默认值:None。 - - **name** (str,可选) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值:None。 +返回 +:::::::::: + ``Tensor`` ,沿着 ``axis`` 进行方差计算的结果,数据类型和 ``x`` 相同。 - - 返回: 计算出来的方差。 +代码示例 +:::::::::: - 返回类型: Variable(Tensor) ,数据类型和 :attr:`input` 相同。如果 :attr:`out = None`, 返回包含方差的新 Variable , 否则返回 :attr:`out` 的引用。 +.. code-block:: python - **代码示例** + import paddle + import numpy as np + + paddle.disable_static() - .. code-block:: python - - import numpy as np - import paddle - import paddle.fluid.dygraph as dg - a = np.array([[1.0, 2.0], [3.0, 4.0]]).astype("float32") - with dg.guard(): - data = dg.to_variable(a) - variance = paddle.var(data, axis=[1]) - print(variance.numpy()) - # [0.5 0.5] + x = np.array([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]]) + x = paddle.to_tensor(x) + out1 = paddle.var(x) + # [2.66666667] + out2 = paddle.var(x, axis=1) + # [1. 4.33333333] diff --git a/doc/fluid/api_cn/tensor_cn/zeros_cn.rst b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst index e84538f784551d1d0becbf6933bfcadcaaa26413..40e54e0daaeb91e9bf2d15b4f32ce65a987748e7 100644 --- a/doc/fluid/api_cn/tensor_cn/zeros_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst @@ -25,7 +25,7 @@ zeros .. code-block:: python import paddle - paddle.enable_imperative() # Now we are in imperative mode + paddle.disable_static() # Now we are in imperative mode data = paddle.zeros(shape=[3, 2], dtype='float32') # [[0. 0.] # [0. 0.]