From f401907775beec285ca3e9ab4ed21a3cf5b76e6b Mon Sep 17 00:00:00 2001 From: Li Fuchen Date: Wed, 4 Nov 2020 15:33:05 +0800 Subject: [PATCH] modified sample code of CTCLoss & ctc_loss by remove disable_static() & print([.*].numpy()) & alias, test=document_fix (#28403) --- python/paddle/nn/functional/loss.py | 5 ++--- python/paddle/nn/layer/loss.py | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/python/paddle/nn/functional/loss.py b/python/paddle/nn/functional/loss.py index b056029fb5a..ae04cdcc931 100644 --- a/python/paddle/nn/functional/loss.py +++ b/python/paddle/nn/functional/loss.py @@ -1112,7 +1112,6 @@ def ctc_loss(log_probs, 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) @@ -1123,14 +1122,14 @@ def ctc_loss(log_probs, label_lengths, blank=0, reduction='none') - print(loss.numpy()) #[3.9179852 2.9076521] + print(loss) #[3.9179852 2.9076521] loss = F.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0, reduction='mean') - print(loss.numpy()) #[1.1376063] + print(loss) #[1.1376063] """ diff --git a/python/paddle/nn/layer/loss.py b/python/paddle/nn/layer/loss.py index 5ce4baca557..351afc97a2a 100644 --- a/python/paddle/nn/layer/loss.py +++ b/python/paddle/nn/layer/loss.py @@ -883,8 +883,6 @@ class MarginRankingLoss(fluid.dygraph.Layer): class CTCLoss(fluid.dygraph.Layer): """ - :alias_main: paddle.nn.CTCLoss - :alias: paddle.nn.CTCLoss, paddle.nn.layer.CTCLoss, paddle.nn.layer.loss.CTCLoss An operator integrating the open source Warp-CTC library (https://github.com/baidu-research/warp-ctc) to compute Connectionist Temporal Classification (CTC) loss. @@ -941,7 +939,6 @@ class CTCLoss(fluid.dygraph.Layer): 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) @@ -950,12 +947,12 @@ class CTCLoss(fluid.dygraph.Layer): loss = paddle.nn.CTCLoss(blank=0, reduction='none')(log_probs, labels, input_lengths, label_lengths) - print(loss.numpy()) #[3.9179852 2.9076521] + print(loss) #[3.9179852 2.9076521] loss = paddle.nn.CTCLoss(blank=0, reduction='mean')(log_probs, labels, input_lengths, label_lengths) - print(loss.numpy()) #[1.1376063] + print(loss) #[1.1376063] """ def __init__(self, blank=0, reduction='mean'): -- GitLab