Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
30a031d8
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
30a031d8
编写于
9月 29, 2018
作者:
Q
qingqing01
提交者:
GitHub
9月 29, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support Python3 in DeepLab v3+ (#1321)
上级
6e239c97
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
59 addition
and
31 deletion
+59
-31
fluid/deeplabv3+/.gitignore
fluid/deeplabv3+/.gitignore
+3
-0
fluid/deeplabv3+/README.md
fluid/deeplabv3+/README.md
+8
-7
fluid/deeplabv3+/eval.py
fluid/deeplabv3+/eval.py
+6
-3
fluid/deeplabv3+/models.py
fluid/deeplabv3+/models.py
+7
-4
fluid/deeplabv3+/reader.py
fluid/deeplabv3+/reader.py
+25
-11
fluid/deeplabv3+/train.py
fluid/deeplabv3+/train.py
+7
-5
fluid/face_detection/.gitignore
fluid/face_detection/.gitignore
+1
-0
fluid/image_classification/README_cn.md
fluid/image_classification/README_cn.md
+1
-1
fluid/object_detection/.gitignore
fluid/object_detection/.gitignore
+1
-0
未找到文件。
fluid/deeplabv3+/.gitignore
0 → 100644
浏览文件 @
30a031d8
deeplabv3plus_xception65_initialize.params
deeplabv3plus.params
deeplabv3plus.tar.gz
fluid/deeplabv3+/README.md
浏览文件 @
30a031d8
DeepLab运行本目录下的程序示例需要使用PaddlePaddle
develop最新版本。如果您的PaddlePaddle安装版本低于此要求,请按照
[
安装文档
](
http://www.paddlepaddle.org/docs/develop/documentation/zh/build_and_install/pip_install_cn.html
)
中的说明更新PaddlePaddle安装
版本。
DeepLab运行本目录下的程序示例需要使用PaddlePaddle
Fluid v1.0.0版本或以上。如果您的PaddlePaddle安装版本低于此要求,请按照安装文档中的说明更新PaddlePaddle安装版本,如果使用GPU,该程序需要使用cuDNN v7
版本。
## 代码结构
...
...
@@ -41,10 +41,12 @@ data/cityscape/
如果需要从头开始训练模型,用户需要下载我们的初始化模型
```
wget http://paddlemodels.cdn.bcebos.com/deeplab/deeplabv3plus_xception65_initialize.tar.gz
tar -xf deeplabv3plus_xception65_initialize.tar.gz && rm deeplabv3plus_xception65_initialize.tar.gz
```
如果需要最终训练模型进行fine tune或者直接用于预测,请下载我们的最终模型
```
wget http://paddlemodels.cdn.bcebos.com/deeplab/deeplabv3plus.tar.gz
tar -xf deeplabv3plus.tar.gz && rm deeplabv3plus.tar.gz
```
...
...
@@ -70,11 +72,11 @@ python train.py --help
```
python ./train.py \
--batch_size=8 \
--parallel=true
--parallel=true
\
--train_crop_size=769 \
--total_step=90000 \
--init_weights_path=
$INIT_WEIGHTS_PATH
\
--save_weights_path=
$SAVE_WEIGHTS_PATH
\
--init_weights_path=
deeplabv3plus_xception65_initialize.params
\
--save_weights_path=
output
\
--dataset_path=$DATASET_PATH
```
...
...
@@ -82,11 +84,10 @@ python ./train.py \
执行以下命令在
`Cityscape`
测试数据集上进行测试:
```
python ./eval.py \
--init_weights
_path=$INIT_WEIGHTS_PATH
\
--init_weights
=deeplabv3plus.params
\
--dataset_path=$DATASET_PATH
```
需要通过选项
`--model_path`
指定模型文件。
测试脚本的输出的评估指标为
[
mean IoU
](
)。
需要通过选项
`--model_path`
指定模型文件。测试脚本的输出的评估指标为mean IoU。
## 实验结果
...
...
fluid/deeplabv3+/eval.py
浏览文件 @
30a031d8
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
os
.
environ
[
'FLAGS_fraction_of_gpu_memory_to_use'
]
=
'0.98'
...
...
@@ -91,7 +94,7 @@ exe = fluid.Executor(place)
exe
.
run
(
sp
)
if
args
.
init_weights_path
:
print
"load from:"
,
args
.
init_weights_path
print
(
"load from:"
,
args
.
init_weights_path
)
load_model
()
dataset
=
CityscapeDataset
(
args
.
dataset_path
,
'val'
)
...
...
@@ -118,7 +121,7 @@ for i, imgs, labels, names in batches:
mp
=
(
wrong
+
right
)
!=
0
miou2
=
np
.
mean
((
right
[
mp
]
*
1.0
/
(
right
[
mp
]
+
wrong
[
mp
])))
if
args
.
verbose
:
print
'step: %s, mIoU: %s'
%
(
i
+
1
,
miou2
)
print
(
'step: %s, mIoU: %s'
%
(
i
+
1
,
miou2
)
)
else
:
print
'
\r
step: %s, mIoU: %s'
%
(
i
+
1
,
miou2
),
print
(
'
\r
step: %s, mIoU: %s'
%
(
i
+
1
,
miou2
))
sys
.
stdout
.
flush
()
fluid/deeplabv3+/models.py
浏览文件 @
30a031d8
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
...
...
@@ -50,7 +53,7 @@ def append_op_result(result, name):
def
conv
(
*
args
,
**
kargs
):
kargs
[
'param_attr'
]
=
name_scope
+
'weights'
if
kargs
.
has_key
(
'bias_attr'
)
and
kargs
[
'bias_attr'
]:
if
'bias_attr'
in
kargs
and
kargs
[
'bias_attr'
]:
kargs
[
'bias_attr'
]
=
name_scope
+
'biases'
else
:
kargs
[
'bias_attr'
]
=
False
...
...
@@ -62,7 +65,7 @@ def group_norm(input, G, eps=1e-5, param_attr=None, bias_attr=None):
N
,
C
,
H
,
W
=
input
.
shape
if
C
%
G
!=
0
:
print
"group can not divide channle:"
,
C
,
G
print
(
"group can not divide channle:"
,
C
,
G
)
for
d
in
range
(
10
):
for
t
in
[
d
,
-
d
]:
if
G
+
t
<=
0
:
continue
...
...
@@ -70,7 +73,7 @@ def group_norm(input, G, eps=1e-5, param_attr=None, bias_attr=None):
G
=
G
+
t
break
if
C
%
G
==
0
:
print
"use group size:"
,
G
print
(
"use group size:"
,
G
)
break
assert
C
%
G
==
0
param_shape
=
(
G
,
)
...
...
@@ -139,7 +142,7 @@ def seq_conv(input, channel, stride, filter, dilation=1, act=None):
filter
,
stride
,
groups
=
input
.
shape
[
1
],
padding
=
(
filter
/
2
)
*
dilation
,
padding
=
(
filter
/
/
2
)
*
dilation
,
dilation
=
dilation
)
input
=
bn
(
input
)
if
act
:
input
=
act
(
input
)
...
...
fluid/deeplabv3+/reader.py
浏览文件 @
30a031d8
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
cv2
import
numpy
as
np
import
os
import
six
default_config
=
{
"shuffle"
:
True
,
...
...
@@ -30,7 +35,7 @@ def slice_with_pad(a, s, value=0):
pr
=
0
pads
.
append
([
pl
,
pr
])
slices
.
append
([
l
,
r
])
slices
=
map
(
lambda
x
:
slice
(
x
[
0
],
x
[
1
],
1
),
slices
)
slices
=
list
(
map
(
lambda
x
:
slice
(
x
[
0
],
x
[
1
],
1
),
slices
)
)
a
=
a
[
slices
]
a
=
np
.
pad
(
a
,
pad_width
=
pads
,
mode
=
'constant'
,
constant_values
=
value
)
return
a
...
...
@@ -38,11 +43,17 @@ def slice_with_pad(a, s, value=0):
class
CityscapeDataset
:
def
__init__
(
self
,
dataset_dir
,
subset
=
'train'
,
config
=
default_config
):
import
commands
label_dirname
=
dataset_dir
+
'gtFine/'
+
subset
label_files
=
commands
.
getoutput
(
"find %s -type f | grep labelTrainIds | sort"
%
label_dirname
).
splitlines
()
label_dirname
=
os
.
path
.
join
(
dataset_dir
,
'gtFine/'
+
subset
)
if
six
.
PY2
:
import
commands
label_files
=
commands
.
getoutput
(
"find %s -type f | grep labelTrainIds | sort"
%
label_dirname
).
splitlines
()
else
:
import
subprocess
label_files
=
subprocess
.
getstatusoutput
(
"find %s -type f | grep labelTrainIds | sort"
%
label_dirname
)[
-
1
].
splitlines
()
self
.
label_files
=
label_files
self
.
label_dirname
=
label_dirname
self
.
index
=
0
...
...
@@ -50,7 +61,7 @@ class CityscapeDataset:
self
.
dataset_dir
=
dataset_dir
self
.
config
=
config
self
.
reset
()
print
"total number"
,
len
(
label_files
)
print
(
"total number"
,
len
(
label_files
)
)
def
reset
(
self
,
shuffle
=
False
):
self
.
index
=
0
...
...
@@ -66,13 +77,14 @@ class CityscapeDataset:
shape
=
self
.
config
[
"crop_size"
]
while
True
:
ln
=
self
.
label_files
[
self
.
index
]
img_name
=
self
.
dataset_dir
+
'leftImg8bit/'
+
self
.
subset
+
ln
[
len
(
self
.
label_dirname
):]
img_name
=
os
.
path
.
join
(
self
.
dataset_dir
,
'leftImg8bit/'
+
self
.
subset
+
ln
[
len
(
self
.
label_dirname
):])
img_name
=
img_name
.
replace
(
'gtFine_labelTrainIds'
,
'leftImg8bit'
)
label
=
cv2
.
imread
(
ln
)
img
=
cv2
.
imread
(
img_name
)
if
img
is
None
:
print
"load img failed:"
,
img_name
print
(
"load img failed:"
,
img_name
)
self
.
next_img
()
else
:
break
...
...
@@ -128,5 +140,7 @@ class CityscapeDataset:
from
prefetch_generator
import
BackgroundGenerator
batches
=
BackgroundGenerator
(
batches
,
100
)
except
:
print
"You can install 'prefetch_generator' for acceleration of data reading."
print
(
"You can install 'prefetch_generator' for acceleration of data reading."
)
return
batches
fluid/deeplabv3+/train.py
浏览文件 @
30a031d8
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
os
.
environ
[
'FLAGS_fraction_of_gpu_memory_to_use'
]
=
'0.98'
...
...
@@ -126,13 +129,12 @@ exe = fluid.Executor(place)
exe
.
run
(
sp
)
if
args
.
init_weights_path
:
print
"load from:"
,
args
.
init_weights_path
print
(
"load from:"
,
args
.
init_weights_path
)
load_model
()
dataset
=
CityscapeDataset
(
args
.
dataset_path
,
'train'
)
if
args
.
parallel
:
print
"Using ParallelExecutor."
exe_p
=
fluid
.
ParallelExecutor
(
use_cuda
=
True
,
loss_name
=
loss_mean
.
name
,
main_program
=
tp
)
...
...
@@ -149,9 +151,9 @@ for i, imgs, labels, names in batches:
'label'
:
labels
},
fetch_list
=
[
pred
,
loss_mean
])
if
i
%
100
==
0
:
print
"Model is saved to"
,
args
.
save_weights_path
print
(
"Model is saved to"
,
args
.
save_weights_path
)
save_model
()
print
"step %s, loss: %s"
%
(
i
,
np
.
mean
(
retv
[
1
]
))
print
(
"step %s, loss: %s"
%
(
i
,
np
.
mean
(
retv
[
1
])
))
print
"Training done. Model is saved to"
,
args
.
save_weights_path
print
(
"Training done. Model is saved to"
,
args
.
save_weights_path
)
save_model
()
fluid/face_detection/.gitignore
浏览文件 @
30a031d8
...
...
@@ -10,3 +10,4 @@ output*
pred
eval_tools
box*
PyramidBox_WiderFace*
fluid/image_classification/README_cn.md
浏览文件 @
30a031d8
...
...
@@ -14,7 +14,7 @@
## 安装
在当前目录下运行样例代码需要PadddlePaddle Fluid的v0.13.0或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据
[
安装文档
](
http://www.paddlepaddle.org/docs/develop/documentation/zh/build_and_install/pip_install_cn.html
)
中的说明来更新PaddlePaddle。
在当前目录下运行样例代码需要PadddlePaddle Fluid的v0.13.0或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据
安装文档
中的说明来更新PaddlePaddle。
## 数据准备
...
...
fluid/object_detection/.gitignore
浏览文件 @
30a031d8
...
...
@@ -20,3 +20,4 @@ data/pascalvoc/trainval.txt
log*
*.log
ssd_mobilenet_v1_pascalvoc*
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录