Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
497e0e27
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
未验证
提交
497e0e27
编写于
12月 10, 2019
作者:
W
wangguanzhong
提交者:
GitHub
12月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix im_info (#93)
上级
843e49a5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
30 deletion
+32
-30
ppdet/data/transform/operators.py
ppdet/data/transform/operators.py
+32
-30
未找到文件。
ppdet/data/transform/operators.py
浏览文件 @
497e0e27
...
...
@@ -287,8 +287,8 @@ class ResizeImage(BaseOperator):
im_scale_x
=
im_scale
im_scale_y
=
im_scale
resize_w
=
np
.
round
(
im_scale_x
*
float
(
im_shape
[
1
])
)
resize_h
=
np
.
round
(
im_scale_y
*
float
(
im_shape
[
0
])
)
resize_w
=
im_scale_x
*
float
(
im_shape
[
1
]
)
resize_h
=
im_scale_y
*
float
(
im_shape
[
0
]
)
im_info
=
[
resize_h
,
resize_w
,
im_scale
]
if
'im_info'
in
sample
and
sample
[
'im_info'
][
2
]
!=
1.
:
sample
[
'im_info'
]
=
np
.
append
(
...
...
@@ -311,8 +311,12 @@ class ResizeImage(BaseOperator):
fy
=
im_scale_y
,
interpolation
=
self
.
interp
)
else
:
if
self
.
max_size
!=
0
:
raise
TypeError
(
'If you set max_size to cap the maximum size of image,'
'please set use_cv2 to True to resize the image.'
)
im
=
Image
.
fromarray
(
im
)
im
=
im
.
resize
((
resize_w
,
resize_h
),
self
.
interp
)
im
=
im
.
resize
((
int
(
resize_w
),
int
(
resize_h
)
),
self
.
interp
)
im
=
np
.
array
(
im
)
sample
[
'image'
]
=
im
...
...
@@ -1009,9 +1013,8 @@ class Resize(BaseOperator):
'random' (for randomized interpolation).
default to `cv2.INTER_LINEAR`.
"""
def
__init__
(
self
,
target_dim
=
[],
interp
=
cv2
.
INTER_LINEAR
):
def
__init__
(
self
,
target_dim
=
[],
interp
=
cv2
.
INTER_LINEAR
):
super
(
Resize
,
self
).
__init__
()
self
.
target_dim
=
target_dim
self
.
interp
=
interp
# 'random' for yolov3
...
...
@@ -1032,10 +1035,9 @@ class Resize(BaseOperator):
scale_x
=
dim
/
w
scale_y
=
dim
/
h
if
'gt_bbox'
in
sample
and
len
(
sample
[
'gt_bbox'
])
>
0
:
scale_array
=
np
.
array
([
scale_x
,
scale_y
]
*
2
,
dtype
=
np
.
float32
)
sample
[
'gt_bbox'
]
=
np
.
clip
(
sample
[
'gt_bbox'
]
*
scale_array
,
0
,
dim
-
1
)
scale_array
=
np
.
array
([
scale_x
,
scale_y
]
*
2
,
dtype
=
np
.
float32
)
sample
[
'gt_bbox'
]
=
np
.
clip
(
sample
[
'gt_bbox'
]
*
scale_array
,
0
,
dim
-
1
)
sample
[
'h'
]
=
resize_h
sample
[
'w'
]
=
resize_w
...
...
@@ -1060,6 +1062,7 @@ class ColorDistort(BaseOperator):
random_apply (bool): whether to apply in random (yolo) or fixed (SSD)
order.
"""
def
__init__
(
self
,
hue
=
[
-
18
,
18
,
0.5
],
saturation
=
[
0.5
,
1.5
,
0.5
],
...
...
@@ -1084,14 +1087,10 @@ class ColorDistort(BaseOperator):
delta
=
np
.
random
.
uniform
(
low
,
high
)
u
=
np
.
cos
(
delta
*
np
.
pi
)
w
=
np
.
sin
(
delta
*
np
.
pi
)
bt
=
np
.
array
([[
1.0
,
0.0
,
0.0
],
[
0.0
,
u
,
-
w
],
[
0.0
,
w
,
u
]])
tyiq
=
np
.
array
([[
0.299
,
0.587
,
0.114
],
[
0.596
,
-
0.274
,
-
0.321
],
bt
=
np
.
array
([[
1.0
,
0.0
,
0.0
],
[
0.0
,
u
,
-
w
],
[
0.0
,
w
,
u
]])
tyiq
=
np
.
array
([[
0.299
,
0.587
,
0.114
],
[
0.596
,
-
0.274
,
-
0.321
],
[
0.211
,
-
0.523
,
0.311
]])
ityiq
=
np
.
array
([[
1.0
,
0.956
,
0.621
],
[
1.0
,
-
0.272
,
-
0.647
],
ityiq
=
np
.
array
([[
1.0
,
0.956
,
0.621
],
[
1.0
,
-
0.272
,
-
0.647
],
[
1.0
,
-
1.107
,
1.705
]])
t
=
np
.
dot
(
np
.
dot
(
ityiq
,
bt
),
tyiq
).
T
img
=
np
.
dot
(
img
,
t
)
...
...
@@ -1135,10 +1134,8 @@ class ColorDistort(BaseOperator):
img
=
sample
[
'image'
]
if
self
.
random_apply
:
distortions
=
np
.
random
.
permutation
([
self
.
apply_brightness
,
self
.
apply_contrast
,
self
.
apply_saturation
,
self
.
apply_hue
self
.
apply_brightness
,
self
.
apply_contrast
,
self
.
apply_saturation
,
self
.
apply_hue
])
for
func
in
distortions
:
img
=
func
(
img
)
...
...
@@ -1167,6 +1164,7 @@ class NormalizePermute(BaseOperator):
mean (list): mean values in RGB order.
std (list): std values in RGB order.
"""
def
__init__
(
self
,
mean
=
[
123.675
,
116.28
,
103.53
],
std
=
[
58.395
,
57.120
,
57.375
]):
...
...
@@ -1197,7 +1195,8 @@ class RandomExpand(BaseOperator):
prob (float): probability to expand.
fill_value (list): color value used to fill the canvas. in RGB order.
"""
def
__init__
(
self
,
ratio
=
4.
,
prob
=
0.5
,
fill_value
=
(
127.5
,)
*
3
):
def
__init__
(
self
,
ratio
=
4.
,
prob
=
0.5
,
fill_value
=
(
127.5
,
)
*
3
):
super
(
RandomExpand
,
self
).
__init__
()
assert
ratio
>
1.01
,
"expand ratio must be larger than 1.01"
self
.
ratio
=
ratio
...
...
@@ -1205,7 +1204,7 @@ class RandomExpand(BaseOperator):
assert
isinstance
(
fill_value
,
(
Number
,
Sequence
)),
\
"fill value must be either float or sequence"
if
isinstance
(
fill_value
,
Number
):
fill_value
=
(
fill_value
,)
*
3
fill_value
=
(
fill_value
,
)
*
3
if
not
isinstance
(
fill_value
,
tuple
):
fill_value
=
tuple
(
fill_value
)
self
.
fill_value
=
fill_value
...
...
@@ -1251,6 +1250,7 @@ class RandomCrop(BaseOperator):
allow_no_crop (bool): allow return without actually cropping them.
cover_all_box (bool): ensure all bboxes are covered in the final crop.
"""
def
__init__
(
self
,
aspect_ratio
=
[.
5
,
2.
],
thresholds
=
[.
0
,
.
1
,
.
3
,
.
5
,
.
7
,
.
9
],
...
...
@@ -1295,15 +1295,16 @@ class RandomCrop(BaseOperator):
for
i
in
range
(
self
.
num_attempts
):
scale
=
np
.
random
.
uniform
(
*
self
.
scaling
)
min_ar
,
max_ar
=
self
.
aspect_ratio
aspect_ratio
=
np
.
random
.
uniform
(
max
(
min_ar
,
scale
**
2
),
min
(
max_ar
,
scale
**-
2
))
aspect_ratio
=
np
.
random
.
uniform
(
max
(
min_ar
,
scale
**
2
),
min
(
max_ar
,
scale
**-
2
))
crop_h
=
int
(
h
*
scale
/
np
.
sqrt
(
aspect_ratio
))
crop_w
=
int
(
w
*
scale
*
np
.
sqrt
(
aspect_ratio
))
crop_y
=
np
.
random
.
randint
(
0
,
h
-
crop_h
)
crop_x
=
np
.
random
.
randint
(
0
,
w
-
crop_w
)
crop_box
=
[
crop_x
,
crop_y
,
crop_x
+
crop_w
,
crop_y
+
crop_h
]
iou
=
self
.
_iou_matrix
(
gt_bbox
,
np
.
array
([
crop_box
],
dtype
=
np
.
float32
))
iou
=
self
.
_iou_matrix
(
gt_bbox
,
np
.
array
(
[
crop_box
],
dtype
=
np
.
float32
))
if
iou
.
max
()
<
thresh
:
continue
...
...
@@ -1311,7 +1312,8 @@ class RandomCrop(BaseOperator):
continue
cropped_box
,
valid_ids
=
self
.
_crop_box_with_center_constraint
(
gt_bbox
,
np
.
array
(
crop_box
,
dtype
=
np
.
float32
))
gt_bbox
,
np
.
array
(
crop_box
,
dtype
=
np
.
float32
))
if
valid_ids
.
size
>
0
:
found
=
True
break
...
...
@@ -1349,8 +1351,8 @@ class RandomCrop(BaseOperator):
cropped_box
[:,
2
:]
-=
crop
[:
2
]
centers
=
(
box
[:,
:
2
]
+
box
[:,
2
:])
/
2
valid
=
np
.
logical_and
(
crop
[:
2
]
<=
centers
,
centers
<
crop
[
2
:]).
all
(
axis
=
1
)
valid
=
np
.
logical_and
(
crop
[:
2
]
<=
centers
,
centers
<
crop
[
2
:]).
all
(
axis
=
1
)
valid
=
np
.
logical_and
(
valid
,
(
cropped_box
[:,
:
2
]
<
cropped_box
[:,
2
:]).
all
(
axis
=
1
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录