Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
34df32d6
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
34df32d6
编写于
12月 03, 2020
作者:
J
Jack Zhou
提交者:
GitHub
12月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix nll_loss doc;test=document_fix; (#29247) (#29311)
fix nll_loss doc;test=document_fix
上级
7b94934a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
25 deletion
+16
-25
python/paddle/nn/functional/loss.py
python/paddle/nn/functional/loss.py
+8
-11
python/paddle/nn/layer/loss.py
python/paddle/nn/layer/loss.py
+8
-14
未找到文件。
python/paddle/nn/functional/loss.py
浏览文件 @
34df32d6
...
...
@@ -767,23 +767,20 @@ def nll_loss(input,
Examples:
.. code-block:: python
import paddle
import numpy as np
from paddle.nn.functional import nll_loss
log_softmax = paddle.nn.LogSoftmax(axis=1)
input_np = np.array([[0.88103855, 0.9908683 , 0.6226845 ],
[0.53331435, 0.07999352, 0.8549948 ],
[0.25879037, 0.39530203, 0.698465 ],
[0.73427284, 0.63575995, 0.18827209],
[0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32)
label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64)
input = paddle.to_tensor(input_np)
input = paddle.to_tensor([[0.88103855, 0.9908683 , 0.6226845 ],
[0.53331435, 0.07999352, 0.8549948 ],
[0.25879037, 0.39530203, 0.698465 ],
[0.73427284, 0.63575995, 0.18827209],
[0.05689114, 0.0862954 , 0.6325046 ]], "float32")
log_out = log_softmax(input)
label = paddle.to_tensor(
label_np
)
label = paddle.to_tensor(
[0, 2, 1, 1, 0], "int64"
)
result = nll_loss(log_out, label)
print(result) #
[1.0720209]
print(result) #
Tensor(shape=[1], dtype=float32, place=CPUPlace, stop_gradient=True, [1.07202101])
"""
if
reduction
not
in
[
'sum'
,
'mean'
,
'none'
]:
raise
ValueError
(
...
...
python/paddle/nn/layer/loss.py
浏览文件 @
34df32d6
...
...
@@ -690,25 +690,19 @@ class NLLLoss(fluid.dygraph.Layer):
.. code-block:: python
import paddle
import numpy as np
nll_loss = paddle.nn.l
ayer
.NLLLoss()
nll_loss = paddle.nn.l
oss
.NLLLoss()
log_softmax = paddle.nn.LogSoftmax(axis=1)
input_np = np.array([[0.88103855, 0.9908683 , 0.6226845 ],
[0.53331435, 0.07999352, 0.8549948 ],
[0.25879037, 0.39530203, 0.698465 ],
[0.73427284, 0.63575995, 0.18827209],
[0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32)
label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64)
place = paddle.CPUPlace()
paddle.disable_static(place)
input = paddle.to_tensor(input_np)
input = paddle.to_tensor([[0.88103855, 0.9908683 , 0.6226845 ],
[0.53331435, 0.07999352, 0.8549948 ],
[0.25879037, 0.39530203, 0.698465 ],
[0.73427284, 0.63575995, 0.18827209],
[0.05689114, 0.0862954 , 0.6325046 ]], "float32")
log_out = log_softmax(input)
label = paddle.to_tensor(
label_np
)
label = paddle.to_tensor(
[0, 2, 1, 1, 0], "int64"
)
result = nll_loss(log_out, label)
print(result
.numpy()) # [1.0720209]
print(result
) # Tensor(shape=[1], dtype=float32, place=CPUPlace, stop_gradient=True, [1.07202101])
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录