Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
bbb07bd3
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
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看板
提交
bbb07bd3
编写于
7月 14, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update dataset and compute iou in origin images
上级
dc837a2e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
36 deletion
+35
-36
dygraph/datasets/dataset.py
dygraph/datasets/dataset.py
+12
-4
dygraph/infer.py
dygraph/infer.py
+0
-1
dygraph/train.py
dygraph/train.py
+0
-2
dygraph/val.py
dygraph/val.py
+23
-29
未找到文件。
dygraph/datasets/dataset.py
浏览文件 @
bbb07bd3
...
...
@@ -14,10 +14,12 @@
import
os
from
paddle.fluid.io
import
Dataset
import
paddle.fluid
as
fluid
import
numpy
as
np
from
PIL
import
Image
class
Dataset
(
Dataset
):
class
Dataset
(
fluid
.
io
.
Dataset
):
def
__init__
(
self
,
data_dir
,
num_classes
,
...
...
@@ -85,12 +87,18 @@ class Dataset(Dataset):
def
__getitem__
(
self
,
idx
):
image_path
,
grt_path
=
self
.
file_list
[
idx
]
im
,
im_info
,
label
=
self
.
transforms
(
im
=
image_path
,
label
=
grt_path
)
if
self
.
mode
==
'train'
:
im
,
im_info
,
label
=
self
.
transforms
(
im
=
image_path
,
label
=
grt_path
)
return
im
,
label
elif
self
.
mode
==
'eval'
:
return
im
,
label
im
,
im_info
,
_
=
self
.
transforms
(
im
=
image_path
)
im
=
im
[
np
.
newaxis
,
...]
label
=
np
.
asarray
(
Image
.
open
(
grt_path
))
label
=
label
[
np
.
newaxis
,
np
.
newaxis
,
:,
:]
return
im
,
im_info
,
label
if
self
.
mode
==
'test'
:
im
,
im_info
,
_
=
self
.
transforms
(
im
=
image_path
)
im
=
im
[
np
.
newaxis
,
...]
return
im
,
im_info
,
image_path
def
__len__
(
self
):
...
...
dygraph/infer.py
浏览文件 @
bbb07bd3
...
...
@@ -98,7 +98,6 @@ def infer(model, test_dataset=None, model_dir=None, save_dir='output'):
logging
.
info
(
"Start to predict..."
)
for
im
,
im_info
,
im_path
in
tqdm
.
tqdm
(
test_dataset
):
im
=
im
[
np
.
newaxis
,
...]
im
=
to_variable
(
im
)
pred
,
_
=
model
(
im
,
mode
=
'test'
)
pred
=
pred
.
numpy
()
...
...
dygraph/train.py
浏览文件 @
bbb07bd3
...
...
@@ -230,10 +230,8 @@ def train(model,
mean_iou
,
mean_acc
=
evaluate
(
model
,
eval_dataset
,
places
=
places
,
model_dir
=
current_save_dir
,
num_classes
=
num_classes
,
batch_size
=
batch_size
,
ignore_index
=
ignore_index
,
epoch_id
=
epoch
+
1
)
if
mean_iou
>
best_mean_iou
:
...
...
dygraph/val.py
浏览文件 @
bbb07bd3
...
...
@@ -16,8 +16,10 @@ import argparse
import
os
import
math
from
paddle.fluid.dygraph.base
import
to_variable
import
numpy
as
np
import
tqdm
import
cv2
from
paddle.fluid.dygraph.base
import
to_variable
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.fluid.io
import
DataLoader
...
...
@@ -61,12 +63,6 @@ def parse_args():
nargs
=
2
,
default
=
[
512
,
512
],
type
=
int
)
parser
.
add_argument
(
'--batch_size'
,
dest
=
'batch_size'
,
help
=
'Mini batch size'
,
type
=
int
,
default
=
2
)
parser
.
add_argument
(
'--model_dir'
,
dest
=
'model_dir'
,
...
...
@@ -79,10 +75,8 @@ def parse_args():
def
evaluate
(
model
,
eval_dataset
=
None
,
places
=
None
,
model_dir
=
None
,
num_classes
=
None
,
batch_size
=
2
,
ignore_index
=
255
,
epoch_id
=
None
):
ckpt_path
=
os
.
path
.
join
(
model_dir
,
'model'
)
...
...
@@ -90,15 +84,7 @@ def evaluate(model,
model
.
set_dict
(
para_state_dict
)
model
.
eval
()
batch_sampler
=
BatchSampler
(
eval_dataset
,
batch_size
=
batch_size
,
shuffle
=
False
,
drop_last
=
False
)
loader
=
DataLoader
(
eval_dataset
,
batch_sampler
=
batch_sampler
,
places
=
places
,
return_list
=
True
,
)
total_steps
=
len
(
batch_sampler
)
total_steps
=
len
(
eval_dataset
)
conf_mat
=
ConfusionMatrix
(
num_classes
,
streaming
=
True
)
logging
.
info
(
...
...
@@ -106,15 +92,25 @@ def evaluate(model,
len
(
eval_dataset
),
total_steps
))
timer
=
Timer
()
timer
.
start
()
for
step
,
data
in
enumerate
(
loader
):
images
=
data
[
0
]
labels
=
data
[
1
].
astype
(
'int64'
)
pred
,
_
=
model
(
images
,
mode
=
'eval'
)
for
step
,
(
im
,
im_info
,
label
)
in
enumerate
(
eval_dataset
):
im
=
to_variable
(
im
)
pred
,
_
=
model
(
im
,
mode
=
'eval'
)
pred
=
pred
.
numpy
()
labels
=
labels
.
numpy
()
mask
=
labels
!=
ignore_index
conf_mat
.
calculate
(
pred
=
pred
,
label
=
labels
,
ignore
=
mask
)
pred
=
np
.
squeeze
(
pred
).
astype
(
'uint8'
)
for
info
in
im_info
[::
-
1
]:
if
info
[
0
]
==
'resize'
:
h
,
w
=
info
[
1
][
0
],
info
[
1
][
1
]
pred
=
cv2
.
resize
(
pred
,
(
w
,
h
),
cv2
.
INTER_NEAREST
)
elif
info
[
0
]
==
'padding'
:
h
,
w
=
info
[
1
][
0
],
info
[
1
][
1
]
pred
=
pred
[
0
:
h
,
0
:
w
]
else
:
raise
Exception
(
"Unexpected info '{}' in im_info"
.
format
(
info
[
0
]))
pred
=
pred
[
np
.
newaxis
,
:,
:,
np
.
newaxis
]
mask
=
label
!=
ignore_index
conf_mat
.
calculate
(
pred
=
pred
,
label
=
label
,
ignore
=
mask
)
_
,
iou
=
conf_mat
.
mean_iou
()
time_step
=
timer
.
elapsed_time
()
...
...
@@ -163,10 +159,8 @@ def main(args):
evaluate
(
model
,
eval_dataset
,
places
=
places
,
model_dir
=
args
.
model_dir
,
num_classes
=
eval_dataset
.
num_classes
,
batch_size
=
args
.
batch_size
)
num_classes
=
eval_dataset
.
num_classes
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录