Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
a0a381fc
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看板
未验证
提交
a0a381fc
编写于
9月 02, 2018
作者:
B
Bai Yifan
提交者:
GitHub
9月 02, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix random.shuffle (#1204)
上级
5cbd9353
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
34 deletion
+37
-34
fluid/face_detection/image_util.py
fluid/face_detection/image_util.py
+32
-28
fluid/face_detection/reader.py
fluid/face_detection/reader.py
+5
-6
未找到文件。
fluid/face_detection/image_util.py
浏览文件 @
a0a381fc
...
...
@@ -79,9 +79,9 @@ def bbox_area(src_bbox):
def
generate_sample
(
sampler
,
image_width
,
image_height
):
scale
=
random
.
uniform
(
sampler
.
min_scale
,
sampler
.
max_scale
)
aspect_ratio
=
random
.
uniform
(
sampler
.
min_aspect_ratio
,
sampler
.
max_aspect_ratio
)
scale
=
np
.
random
.
uniform
(
sampler
.
min_scale
,
sampler
.
max_scale
)
aspect_ratio
=
np
.
random
.
uniform
(
sampler
.
min_aspect_ratio
,
sampler
.
max_aspect_ratio
)
aspect_ratio
=
max
(
aspect_ratio
,
(
scale
**
2.0
))
aspect_ratio
=
min
(
aspect_ratio
,
1
/
(
scale
**
2.0
))
...
...
@@ -97,8 +97,8 @@ def generate_sample(sampler, image_width, image_height):
xmin_bound
=
1
-
bbox_width
ymin_bound
=
1
-
bbox_height
xmin
=
random
.
uniform
(
0
,
xmin_bound
)
ymin
=
random
.
uniform
(
0
,
ymin_bound
)
xmin
=
np
.
random
.
uniform
(
0
,
xmin_bound
)
ymin
=
np
.
random
.
uniform
(
0
,
ymin_bound
)
xmax
=
xmin
+
bbox_width
ymax
=
ymin
+
bbox_height
sampled_bbox
=
bbox
(
xmin
,
ymin
,
xmax
,
ymax
)
...
...
@@ -141,25 +141,29 @@ def data_anchor_sampling(sampler, bbox_labels, image_width, image_height,
min_resize_val
=
scale_array
[
rand_idx_size
]
/
2.0
max_resize_val
=
min
(
2.0
*
scale_array
[
rand_idx_size
],
2
*
math
.
sqrt
(
wid
*
hei
))
scale_choose
=
random
.
uniform
(
min_resize_val
,
max_resize_val
)
scale_choose
=
np
.
random
.
uniform
(
min_resize_val
,
max_resize_val
)
sample_bbox_size
=
wid
*
resize_width
/
scale_choose
w_off_orig
=
0.0
h_off_orig
=
0.0
if
sample_bbox_size
<
max
(
image_height
,
image_width
):
if
wid
<=
sample_bbox_size
:
w_off_orig
=
random
.
uniform
(
xmin
+
wid
-
sample_bbox_size
,
xmin
)
w_off_orig
=
np
.
random
.
uniform
(
xmin
+
wid
-
sample_bbox_size
,
xmin
)
else
:
w_off_orig
=
random
.
uniform
(
xmin
,
xmin
+
wid
-
sample_bbox_size
)
w_off_orig
=
np
.
random
.
uniform
(
xmin
,
xmin
+
wid
-
sample_bbox_size
)
if
hei
<=
sample_bbox_size
:
h_off_orig
=
random
.
uniform
(
ymin
+
hei
-
sample_bbox_size
,
ymin
)
h_off_orig
=
np
.
random
.
uniform
(
ymin
+
hei
-
sample_bbox_size
,
ymin
)
else
:
h_off_orig
=
random
.
uniform
(
ymin
,
ymin
+
hei
-
sample_bbox_size
)
h_off_orig
=
np
.
random
.
uniform
(
ymin
,
ymin
+
hei
-
sample_bbox_size
)
else
:
w_off_orig
=
random
.
uniform
(
image_width
-
sample_bbox_size
,
0.0
)
h_off_orig
=
random
.
uniform
(
image_height
-
sample_bbox_size
,
0.0
)
w_off_orig
=
np
.
random
.
uniform
(
image_width
-
sample_bbox_size
,
0.0
)
h_off_orig
=
np
.
random
.
uniform
(
image_height
-
sample_bbox_size
,
0.0
)
w_off_orig
=
math
.
floor
(
w_off_orig
)
h_off_orig
=
math
.
floor
(
h_off_orig
)
...
...
@@ -418,36 +422,36 @@ def crop_image_sampling(img, bbox_labels, sample_bbox, image_width,
def
random_brightness
(
img
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
if
prob
<
settings
.
brightness_prob
:
delta
=
random
.
uniform
(
-
settings
.
brightness_delta
,
settings
.
brightness_delta
)
+
1
delta
=
np
.
random
.
uniform
(
-
settings
.
brightness_delta
,
settings
.
brightness_delta
)
+
1
img
=
ImageEnhance
.
Brightness
(
img
).
enhance
(
delta
)
return
img
def
random_contrast
(
img
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
if
prob
<
settings
.
contrast_prob
:
delta
=
random
.
uniform
(
-
settings
.
contrast_delta
,
settings
.
contrast_delta
)
+
1
delta
=
np
.
random
.
uniform
(
-
settings
.
contrast_delta
,
settings
.
contrast_delta
)
+
1
img
=
ImageEnhance
.
Contrast
(
img
).
enhance
(
delta
)
return
img
def
random_saturation
(
img
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
if
prob
<
settings
.
saturation_prob
:
delta
=
random
.
uniform
(
-
settings
.
saturation_delta
,
settings
.
saturation_delta
)
+
1
delta
=
np
.
random
.
uniform
(
-
settings
.
saturation_delta
,
settings
.
saturation_delta
)
+
1
img
=
ImageEnhance
.
Color
(
img
).
enhance
(
delta
)
return
img
def
random_hue
(
img
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
if
prob
<
settings
.
hue_prob
:
delta
=
random
.
uniform
(
-
settings
.
hue_delta
,
settings
.
hue_delta
)
delta
=
np
.
random
.
uniform
(
-
settings
.
hue_delta
,
settings
.
hue_delta
)
img_hsv
=
np
.
array
(
img
.
convert
(
'HSV'
))
img_hsv
[:,
:,
0
]
=
img_hsv
[:,
:,
0
]
+
delta
img
=
Image
.
fromarray
(
img_hsv
,
mode
=
'HSV'
).
convert
(
'RGB'
)
...
...
@@ -455,7 +459,7 @@ def random_hue(img, settings):
def
distort_image
(
img
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
# Apply different distort order
if
prob
>
0.5
:
img
=
random_brightness
(
img
,
settings
)
...
...
@@ -471,14 +475,14 @@ def distort_image(img, settings):
def
expand_image
(
img
,
bbox_labels
,
img_width
,
img_height
,
settings
):
prob
=
random
.
uniform
(
0
,
1
)
prob
=
np
.
random
.
uniform
(
0
,
1
)
if
prob
<
settings
.
expand_prob
:
if
settings
.
expand_max_ratio
-
1
>=
0.01
:
expand_ratio
=
random
.
uniform
(
1
,
settings
.
expand_max_ratio
)
expand_ratio
=
np
.
random
.
uniform
(
1
,
settings
.
expand_max_ratio
)
height
=
int
(
img_height
*
expand_ratio
)
width
=
int
(
img_width
*
expand_ratio
)
h_off
=
math
.
floor
(
random
.
uniform
(
0
,
height
-
img_height
))
w_off
=
math
.
floor
(
random
.
uniform
(
0
,
width
-
img_width
))
h_off
=
math
.
floor
(
np
.
random
.
uniform
(
0
,
height
-
img_height
))
w_off
=
math
.
floor
(
np
.
random
.
uniform
(
0
,
width
-
img_width
))
expand_bbox
=
bbox
(
-
w_off
/
img_width
,
-
h_off
/
img_height
,
(
width
-
w_off
)
/
img_width
,
(
height
-
h_off
)
/
img_height
)
...
...
fluid/face_detection/reader.py
浏览文件 @
a0a381fc
...
...
@@ -18,7 +18,6 @@ from __future__ import print_function
import
image_util
from
paddle.utils.image_util
import
*
import
random
from
PIL
import
Image
from
PIL
import
ImageDraw
import
numpy
as
np
...
...
@@ -98,7 +97,7 @@ def preprocess(img, bbox_labels, mode, settings, image_path):
# sampling
batch_sampler
=
[]
prob
=
random
.
uniform
(
0.
,
1.
)
prob
=
np
.
random
.
uniform
(
0.
,
1.
)
if
prob
>
settings
.
data_anchor_sampling_prob
:
scale_array
=
np
.
array
([
16
,
32
,
64
,
128
,
256
,
512
])
batch_sampler
.
append
(
...
...
@@ -109,7 +108,7 @@ def preprocess(img, bbox_labels, mode, settings, image_path):
settings
.
resize_width
,
settings
.
resize_height
)
img
=
np
.
array
(
img
)
if
len
(
sampled_bbox
)
>
0
:
idx
=
int
(
random
.
uniform
(
0
,
len
(
sampled_bbox
)))
idx
=
int
(
np
.
random
.
uniform
(
0
,
len
(
sampled_bbox
)))
img
,
sampled_labels
=
image_util
.
crop_image_sampling
(
img
,
bbox_labels
,
sampled_bbox
[
idx
],
img_width
,
img_height
,
settings
.
resize_width
,
settings
.
resize_height
,
...
...
@@ -140,7 +139,7 @@ def preprocess(img, bbox_labels, mode, settings, image_path):
img
=
np
.
array
(
img
)
if
len
(
sampled_bbox
)
>
0
:
idx
=
int
(
random
.
uniform
(
0
,
len
(
sampled_bbox
)))
idx
=
int
(
np
.
random
.
uniform
(
0
,
len
(
sampled_bbox
)))
img
,
sampled_labels
=
image_util
.
crop_image
(
img
,
bbox_labels
,
sampled_bbox
[
idx
],
img_width
,
img_height
,
settings
.
resize_width
,
settings
.
resize_height
,
...
...
@@ -153,7 +152,7 @@ def preprocess(img, bbox_labels, mode, settings, image_path):
img
=
np
.
array
(
img
)
if
mode
==
'train'
:
mirror
=
int
(
random
.
uniform
(
0
,
2
))
mirror
=
int
(
np
.
random
.
uniform
(
0
,
2
))
if
mirror
==
1
:
img
=
img
[:,
::
-
1
,
:]
for
i
in
six
.
moves
.
xrange
(
len
(
sampled_labels
)):
...
...
@@ -225,7 +224,7 @@ def train_generator(settings, file_list, batch_size, shuffle=True):
file_dict
=
load_file_list
(
file_list
)
while
True
:
if
shuffle
:
random
.
shuffle
(
file_dict
)
np
.
random
.
shuffle
(
file_dict
)
images
,
face_boxes
,
head_boxes
,
label_ids
=
[],
[],
[],
[]
label_offs
=
[
0
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录