Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
b709c11e
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看板
提交
b709c11e
编写于
7月 15, 2020
作者:
R
root
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dygraph' of
https://github.com/wuyefeilin/PaddleSeg
into dygraph
上级
f2c91805
e4cf4ee7
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
370 deletion
+54
-370
dygraph/datasets/dataset.py
dygraph/datasets/dataset.py
+10
-2
dygraph/infer.py
dygraph/infer.py
+8
-7
dygraph/train.py
dygraph/train.py
+0
-2
dygraph/transforms/transforms.py
dygraph/transforms/transforms.py
+11
-329
dygraph/val.py
dygraph/val.py
+25
-30
未找到文件。
dygraph/datasets/dataset.py
浏览文件 @
b709c11e
...
...
@@ -15,6 +15,8 @@
import
os
import
paddle.fluid
as
fluid
import
numpy
as
np
from
PIL
import
Image
class
Dataset
(
fluid
.
io
.
Dataset
):
...
...
@@ -85,12 +87,18 @@ class Dataset(fluid.io.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
浏览文件 @
b709c11e
...
...
@@ -98,19 +98,20 @@ 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
()
pred
=
np
.
squeeze
(
pred
).
astype
(
'uint8'
)
keys
=
list
(
im_info
.
keys
())
for
k
in
keys
[::
-
1
]:
if
k
==
'shape_before_resize'
:
h
,
w
=
im_info
[
k
][
0
],
im_info
[
k
][
1
]
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
k
==
'shape_before_
padding'
:
h
,
w
=
i
m_info
[
k
][
0
],
im_info
[
k
][
1
]
elif
info
[
0
]
==
'
padding'
:
h
,
w
=
i
nfo
[
1
][
0
],
info
[
1
][
1
]
pred
=
pred
[
0
:
h
,
0
:
w
]
else
:
raise
Exception
(
"Unexpected info '{}' in im_info"
.
format
(
info
[
0
]))
im_file
=
im_path
.
replace
(
test_dataset
.
data_dir
,
''
)
if
im_file
[
0
]
==
'/'
:
...
...
dygraph/train.py
浏览文件 @
b709c11e
...
...
@@ -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/transforms/transforms.py
浏览文件 @
b709c11e
此差异已折叠。
点击以展开。
dygraph/val.py
浏览文件 @
b709c11e
...
...
@@ -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,26 @@ 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'
)
pred
=
pred
.
numpy
()
labels
=
labels
.
numpy
()
mask
=
labels
!=
ignore_index
conf_mat
.
calculate
(
pred
=
pred
,
label
=
labels
,
ignore
=
mask
)
for
step
,
(
im
,
im_info
,
label
)
in
enumerate
(
eval_dataset
):
im
=
to_variable
(
im
)
pred
,
_
=
model
(
im
,
mode
=
'eval'
)
pred
=
pred
.
numpy
().
astype
(
'float32'
)
pred
=
np
.
squeeze
(
pred
)
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
]
pred
=
pred
.
astype
(
'int64'
)
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 +160,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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录