Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
3fa39034
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
286
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3fa39034
编写于
9月 24, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update confusion matrix calculation
上级
e9a2881d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
11 deletion
+24
-11
dygraph/paddleseg/core/val.py
dygraph/paddleseg/core/val.py
+1
-2
dygraph/paddleseg/utils/metrics.py
dygraph/paddleseg/utils/metrics.py
+21
-7
dygraph/val.py
dygraph/val.py
+2
-2
未找到文件。
dygraph/paddleseg/core/val.py
浏览文件 @
3fa39034
...
...
@@ -49,7 +49,6 @@ def evaluate(model,
for
iter
,
(
im
,
im_info
,
label
)
in
tqdm
.
tqdm
(
enumerate
(
eval_dataset
),
total
=
total_iters
):
im
=
to_variable
(
im
)
# pred, _ = model(im)
logits
=
model
(
im
)
pred
=
paddle
.
argmax
(
logits
[
0
],
axis
=
1
)
pred
=
pred
.
numpy
().
astype
(
'float32'
)
...
...
@@ -68,7 +67,7 @@ def evaluate(model,
pred
=
pred
.
astype
(
'int64'
)
mask
=
label
!=
ignore_index
# To-DO Test Execution Time
conf_mat
.
calculate
(
pred
=
pred
,
label
=
label
,
ignore
=
mask
)
conf_mat
.
calculate
(
pred
=
pred
,
label
=
label
,
mask
=
mask
)
_
,
iou
=
conf_mat
.
mean_iou
()
time_iter
=
timer
.
elapsed_time
()
...
...
dygraph/paddleseg/utils/metrics.py
浏览文件 @
3fa39034
...
...
@@ -29,18 +29,32 @@ class ConfusionMatrix(object):
self
.
num_classes
=
num_classes
self
.
streaming
=
streaming
def
calculate
(
self
,
pred
,
label
,
ignore
=
None
):
def
calculate
(
self
,
pred
,
label
,
mask
):
"""
Calculate confusion matrix
Args:
pred (np.ndarray): The prediction of input image by model.
label (np.ndarray): The ground truth of input image.
mask (np.ndarray): The mask which pixel is valid. The dtype should be bool.
"""
# If not in streaming mode, clear matrix everytime when call `calculate`
if
not
self
.
streaming
:
self
.
zero_matrix
()
label
=
np
.
transpose
(
label
,
(
0
,
2
,
3
,
1
)
)
ignore
=
np
.
transpose
(
ignore
,
(
0
,
2
,
3
,
1
)
)
mask
=
np
.
array
(
ignore
)
==
1
pred
=
np
.
squeeze
(
pred
)
label
=
np
.
squeeze
(
label
)
mask
=
np
.
squeeze
(
mask
)
label
=
np
.
asarray
(
label
)[
mask
]
pred
=
np
.
asarray
(
pred
)[
mask
]
one
=
np
.
ones_like
(
pred
)
if
not
pred
.
shape
==
label
.
shape
==
mask
.
shape
:
raise
ValueError
(
'Shape of `pred`, `label` and `mask` should be equal, '
'but there are {}, {} and {}.'
.
format
(
pred
.
shape
,
label
.
shape
,
mask
.
shape
))
label
=
label
[
mask
]
pred
=
pred
[
mask
]
one
=
np
.
ones_like
(
pred
).
astype
(
'int64'
)
# Accumuate ([row=label, col=pred], 1) into sparse
spm
=
csr_matrix
((
one
,
(
label
,
pred
)),
shape
=
(
self
.
num_classes
,
self
.
num_classes
))
...
...
dygraph/val.py
浏览文件 @
3fa39034
...
...
@@ -18,8 +18,8 @@ import paddle
from
paddle.distributed
import
ParallelEnv
import
paddleseg
from
paddleseg.cvlibs
import
manager
from
paddleseg.utils
import
get_environ_info
,
Config
,
logger
from
paddleseg.cvlibs
import
manager
,
Config
from
paddleseg.utils
import
get_environ_info
,
logger
from
paddleseg.core
import
evaluate
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录