Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
89f1a4d6
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看板
提交
89f1a4d6
编写于
1月 28, 2019
作者:
Z
zhengya01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update reader
上级
179be88c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
7 addition
and
27 deletion
+7
-27
fluid/PaddleCV/metric_learning/imgtool.py
fluid/PaddleCV/metric_learning/imgtool.py
+2
-15
fluid/PaddleCV/metric_learning/reader.py
fluid/PaddleCV/metric_learning/reader.py
+5
-12
未找到文件。
fluid/PaddleCV/metric_learning/imgtool.py
浏览文件 @
89f1a4d6
...
...
@@ -13,15 +13,14 @@ import os
is_ce
=
int
(
os
.
environ
.
get
(
'is_ce'
,
0
))
#random.seed(0)
if
is_ce
:
random
.
seed
(
0
)
def
rotate_image
(
img
):
""" rotate_image """
(
h
,
w
)
=
img
.
shape
[:
2
]
center
=
(
w
//
2
,
h
//
2
)
angle
=
random
.
randint
(
-
10
,
10
)
if
is_ce
:
aggle
=
0
M
=
cv2
.
getRotationMatrix2D
(
center
,
angle
,
1.0
)
rotated
=
cv2
.
warpAffine
(
img
,
M
,
(
w
,
h
))
return
rotated
...
...
@@ -32,8 +31,6 @@ def random_crop(img, size, scale=None, ratio=None):
ratio
=
[
3.
/
4.
,
4.
/
3.
]
if
ratio
is
None
else
ratio
aspect_ratio
=
math
.
sqrt
(
random
.
uniform
(
*
ratio
))
if
is_ce
:
aspect_ratio
=
math
.
sqrt
(
1.
)
w
=
1.
*
aspect_ratio
h
=
1.
/
aspect_ratio
...
...
@@ -43,17 +40,12 @@ def random_crop(img, size, scale=None, ratio=None):
scale_min
=
min
(
scale
[
0
],
bound
)
target_area
=
img
.
shape
[
0
]
*
img
.
shape
[
1
]
*
random
.
uniform
(
scale_min
,
scale_max
)
if
is_ce
:
target_area
=
img
.
shape
[
0
]
*
img
.
shape
[
1
]
*
(
scale_min
+
scale_max
)
/
2.
target_size
=
math
.
sqrt
(
target_area
)
w
=
int
(
target_size
*
w
)
h
=
int
(
target_size
*
h
)
i
=
random
.
randint
(
0
,
img
.
shape
[
0
]
-
h
)
j
=
random
.
randint
(
0
,
img
.
shape
[
1
]
-
w
)
if
is_ce
:
i
=
int
(
img
.
shape
[
0
]
-
h
)
//
2
j
=
int
(
img
.
shape
[
1
]
-
w
)
//
2
img
=
img
[
i
:
i
+
h
,
j
:
j
+
w
,
:]
resized
=
cv2
.
resize
(
img
,
(
size
,
size
),
interpolation
=
cv2
.
INTER_LANCZOS4
)
...
...
@@ -80,9 +72,6 @@ def crop_image(img, target_size, center):
else
:
w_start
=
random
.
randint
(
0
,
width
-
size
)
h_start
=
random
.
randint
(
0
,
height
-
size
)
if
is_ce
:
w_start
=
(
width
-
size
)
//
2
h_start
=
(
height
-
size
)
//
2
w_end
=
w_start
+
size
h_end
=
h_start
+
size
img
=
img
[
h_start
:
h_end
,
w_start
:
w_end
,
:]
...
...
@@ -107,8 +96,6 @@ def process_image(sample, mode, color_jitter, rotate,
img
=
distort_color
(
img
)
if
random
.
randint
(
0
,
1
)
==
1
:
img
=
img
[:,
::
-
1
,
:]
if
is_ce
:
img
=
img
[:,
::
-
1
,
:]
else
:
if
crop_size
>
0
:
img
=
resize_short
(
img
,
crop_size
)
...
...
fluid/PaddleCV/metric_learning/reader.py
浏览文件 @
89f1a4d6
...
...
@@ -34,8 +34,7 @@ def init_sop(mode):
if
label
not
in
train_data
:
train_data
[
label
]
=
[]
train_data
[
label
].
append
(
path
)
if
not
is_ce
:
random
.
shuffle
(
train_image_list
)
random
.
shuffle
(
train_image_list
)
print
(
"{} dataset size: {}"
.
format
(
mode
,
len
(
train_data
)))
return
train_data
,
train_image_list
else
:
...
...
@@ -70,15 +69,13 @@ def common_iterator(data, settings):
lab_num
=
len
(
labs
)
ind
=
list
(
range
(
0
,
lab_num
))
while
True
:
if
not
is_ce
:
random
.
shuffle
(
ind
)
random
.
shuffle
(
ind
)
ind_sample
=
ind
[:
class_num
]
for
ind_i
in
ind_sample
:
lab
=
labs
[
ind_i
]
data_list
=
data
[
lab
]
data_ind
=
list
(
range
(
0
,
len
(
data_list
)))
if
not
is_ce
:
random
.
shuffle
(
data_ind
)
random
.
shuffle
(
data_ind
)
anchor_ind
=
data_ind
[:
samples_each_class
]
for
anchor_ind_i
in
anchor_ind
:
...
...
@@ -95,21 +92,17 @@ def triplet_iterator(data, settings):
lab_num
=
len
(
labs
)
ind
=
list
(
range
(
0
,
lab_num
))
while
True
:
if
not
is_ce
:
random
.
shuffle
(
ind
)
random
.
shuffle
(
ind
)
ind_pos
,
ind_neg
=
ind
[:
2
]
lab_pos
=
labs
[
ind_pos
]
pos_data_list
=
data
[
lab_pos
]
data_ind
=
list
(
range
(
0
,
len
(
pos_data_list
)))
if
not
is_ce
:
random
.
shuffle
(
data_ind
)
random
.
shuffle
(
data_ind
)
anchor_ind
,
pos_ind
=
data_ind
[:
2
]
lab_neg
=
labs
[
ind_neg
]
neg_data_list
=
data
[
lab_neg
]
neg_ind
=
random
.
randint
(
0
,
len
(
neg_data_list
)
-
1
)
if
is_ce
:
neg_ind
=
1
anchor_path
=
DATA_DIR
+
pos_data_list
[
anchor_ind
]
yield
anchor_path
,
lab_pos
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录