Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
5a7cd9c6
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5a7cd9c6
编写于
7月 25, 2019
作者:
W
wangguanzhong
提交者:
GitHub
7月 25, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add multiscale-training & refine train+eval (#2911)
上级
b0683058
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
25 addition
and
12 deletion
+25
-12
ppdet/data/transform/operators.py
ppdet/data/transform/operators.py
+22
-9
tools/train.py
tools/train.py
+3
-3
未找到文件。
ppdet/data/transform/operators.py
浏览文件 @
5a7cd9c6
...
@@ -127,18 +127,24 @@ class ResizeImage(BaseOperator):
...
@@ -127,18 +127,24 @@ class ResizeImage(BaseOperator):
use_cv2
=
True
):
use_cv2
=
True
):
"""
"""
Args:
Args:
target_size (int): the taregt size of image's short side
target_size (int|list): the target size of image's short side,
multi-scale training is adopted when type is list.
max_size (int): the max size of image
max_size (int): the max size of image
interp (int): the interpolation method
interp (int): the interpolation method
use_cv2 (bool): use the cv2 interpolation method or use PIL interpolation method
use_cv2 (bool): use the cv2 interpolation method or use PIL
interpolation method
"""
"""
super
(
ResizeImage
,
self
).
__init__
()
super
(
ResizeImage
,
self
).
__init__
()
self
.
target_size
=
int
(
target_size
)
self
.
max_size
=
int
(
max_size
)
self
.
max_size
=
int
(
max_size
)
self
.
interp
=
int
(
interp
)
self
.
interp
=
int
(
interp
)
self
.
use_cv2
=
use_cv2
self
.
use_cv2
=
use_cv2
if
not
(
isinstance
(
self
.
target_size
,
int
)
and
isinstance
(
if
not
(
isinstance
(
target_size
,
int
)
or
isinstance
(
target_size
,
list
)):
self
.
max_size
,
int
)
and
isinstance
(
self
.
interp
,
int
)):
raise
TypeError
(
"Type of target_size is invalid. Must be Integer or List, now is {}"
.
format
(
type
(
target_size
)))
self
.
target_size
=
target_size
if
not
(
isinstance
(
self
.
max_size
,
int
)
and
isinstance
(
self
.
interp
,
int
)):
raise
TypeError
(
"{}: input type is invalid."
.
format
(
self
))
raise
TypeError
(
"{}: input type is invalid."
.
format
(
self
))
def
__call__
(
self
,
sample
,
context
=
None
):
def
__call__
(
self
,
sample
,
context
=
None
):
...
@@ -152,10 +158,15 @@ class ResizeImage(BaseOperator):
...
@@ -152,10 +158,15 @@ class ResizeImage(BaseOperator):
im_shape
=
im
.
shape
im_shape
=
im
.
shape
im_size_min
=
np
.
min
(
im_shape
[
0
:
2
])
im_size_min
=
np
.
min
(
im_shape
[
0
:
2
])
im_size_max
=
np
.
max
(
im_shape
[
0
:
2
])
im_size_max
=
np
.
max
(
im_shape
[
0
:
2
])
if
isinstance
(
self
.
target_size
,
list
):
# Case for multi-scale training
selected_size
=
random
.
choice
(
self
.
target_size
)
else
:
selected_size
=
self
.
target_size
if
float
(
im_size_min
)
==
0
:
if
float
(
im_size_min
)
==
0
:
raise
ZeroDivisionError
(
'{}: min size of image is 0'
.
format
(
self
))
raise
ZeroDivisionError
(
'{}: min size of image is 0'
.
format
(
self
))
if
self
.
max_size
!=
0
:
if
self
.
max_size
!=
0
:
im_scale
=
float
(
sel
f
.
target
_size
)
/
float
(
im_size_min
)
im_scale
=
float
(
sel
ected
_size
)
/
float
(
im_size_min
)
# Prevent the biggest axis from being more than max_size
# Prevent the biggest axis from being more than max_size
if
np
.
round
(
im_scale
*
im_size_max
)
>
self
.
max_size
:
if
np
.
round
(
im_scale
*
im_size_max
)
>
self
.
max_size
:
im_scale
=
float
(
self
.
max_size
)
/
float
(
im_size_max
)
im_scale
=
float
(
self
.
max_size
)
/
float
(
im_size_max
)
...
@@ -168,8 +179,8 @@ class ResizeImage(BaseOperator):
...
@@ -168,8 +179,8 @@ class ResizeImage(BaseOperator):
],
],
dtype
=
np
.
float32
)
dtype
=
np
.
float32
)
else
:
else
:
im_scale_x
=
float
(
sel
f
.
target
_size
)
/
float
(
im_shape
[
1
])
im_scale_x
=
float
(
sel
ected
_size
)
/
float
(
im_shape
[
1
])
im_scale_y
=
float
(
sel
f
.
target
_size
)
/
float
(
im_shape
[
0
])
im_scale_y
=
float
(
sel
ected
_size
)
/
float
(
im_shape
[
0
])
if
self
.
use_cv2
:
if
self
.
use_cv2
:
im
=
cv2
.
resize
(
im
=
cv2
.
resize
(
im
,
im
,
...
@@ -180,7 +191,9 @@ class ResizeImage(BaseOperator):
...
@@ -180,7 +191,9 @@ class ResizeImage(BaseOperator):
interpolation
=
self
.
interp
)
interpolation
=
self
.
interp
)
else
:
else
:
im
=
Image
.
fromarray
(
im
)
im
=
Image
.
fromarray
(
im
)
im
=
im
.
resize
((
self
.
target_size
,
self
.
target_size
),
self
.
interp
)
resize_w
=
selected_size
*
im_scale_x
resize_h
=
selected_size
*
im_scale_y
im
=
im
.
resize
((
resize_w
,
resize_h
),
self
.
interp
)
im
=
np
.
array
(
im
)
im
=
np
.
array
(
im
)
sample
[
'image'
]
=
im
sample
[
'image'
]
=
im
...
...
tools/train.py
浏览文件 @
5a7cd9c6
...
@@ -171,8 +171,9 @@ def main():
...
@@ -171,8 +171,9 @@ def main():
it
,
np
.
mean
(
outs
[
-
1
]),
logs
,
end_time
-
start_time
)
it
,
np
.
mean
(
outs
[
-
1
]),
logs
,
end_time
-
start_time
)
logger
.
info
(
strs
)
logger
.
info
(
strs
)
if
it
>
0
and
it
%
cfg
.
snapshot_iter
==
0
:
if
it
>
0
and
it
%
cfg
.
snapshot_iter
==
0
or
it
==
cfg
.
max_iters
-
1
:
checkpoint
.
save
(
exe
,
train_prog
,
os
.
path
.
join
(
save_dir
,
str
(
it
)))
save_name
=
str
(
it
)
if
it
!=
cfg
.
max_iters
-
1
else
"model_final"
checkpoint
.
save
(
exe
,
train_prog
,
os
.
path
.
join
(
save_dir
,
save_name
))
if
FLAGS
.
eval
:
if
FLAGS
.
eval
:
# evaluation
# evaluation
...
@@ -184,7 +185,6 @@ def main():
...
@@ -184,7 +185,6 @@ def main():
eval_results
(
results
,
eval_feed
,
cfg
.
metric
,
resolution
,
eval_results
(
results
,
eval_feed
,
cfg
.
metric
,
resolution
,
FLAGS
.
output_file
)
FLAGS
.
output_file
)
checkpoint
.
save
(
exe
,
train_prog
,
os
.
path
.
join
(
save_dir
,
"model_final"
))
train_pyreader
.
reset
()
train_pyreader
.
reset
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录