Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4106e54c
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4106e54c
编写于
8月 28, 2020
作者:
L
LielinJiang
提交者:
GitHub
8月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix hapi transform bug (#26738)
* fix bug
上级
64df9b99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
2 deletion
+29
-2
python/paddle/incubate/hapi/tests/test_transforms.py
python/paddle/incubate/hapi/tests/test_transforms.py
+6
-1
python/paddle/incubate/hapi/vision/transforms/functional.py
python/paddle/incubate/hapi/vision/transforms/functional.py
+22
-0
python/paddle/incubate/hapi/vision/transforms/transforms.py
python/paddle/incubate/hapi/vision/transforms/transforms.py
+1
-1
未找到文件。
python/paddle/incubate/hapi/tests/test_transforms.py
浏览文件 @
4106e54c
...
...
@@ -64,6 +64,11 @@ class TestTransforms(unittest.TestCase):
self
.
do_transform
(
trans
)
def
test_normalize
(
self
):
normalize
=
transforms
.
Normalize
(
mean
=
0.5
,
std
=
0.5
)
trans
=
transforms
.
Compose
([
transforms
.
Permute
(
mode
=
'CHW'
),
normalize
])
self
.
do_transform
(
trans
)
def
test_trans_resize
(
self
):
trans
=
transforms
.
Compose
([
transforms
.
Resize
(
300
,
[
0
,
1
]),
...
...
@@ -165,7 +170,7 @@ class TestTransforms(unittest.TestCase):
fake_img
=
np
.
random
.
rand
(
500
,
400
,
3
).
astype
(
'float32'
)
fake_img_gray
=
trans_gray
(
fake_img
)
np
.
testing
.
assert_equal
(
len
(
fake_img_gray
.
shape
),
2
)
np
.
testing
.
assert_equal
(
len
(
fake_img_gray
.
shape
),
3
)
np
.
testing
.
assert_equal
(
fake_img_gray
.
shape
[
0
],
500
)
np
.
testing
.
assert_equal
(
fake_img_gray
.
shape
[
1
],
400
)
...
...
python/paddle/incubate/hapi/vision/transforms/functional.py
浏览文件 @
4106e54c
...
...
@@ -16,6 +16,7 @@ import sys
import
collections
import
random
import
math
import
functools
import
cv2
import
numbers
...
...
@@ -31,6 +32,23 @@ else:
__all__
=
[
'flip'
,
'resize'
,
'pad'
,
'rotate'
,
'to_grayscale'
]
def
keepdims
(
func
):
"""Keep the dimension of input images unchanged"""
@
functools
.
wraps
(
func
)
def
wrapper
(
image
,
*
args
,
**
kwargs
):
if
len
(
image
.
shape
)
!=
3
:
raise
ValueError
(
"Expect image have 3 dims, but got {} dims"
.
format
(
len
(
image
.
shape
)))
ret
=
func
(
image
,
*
args
,
**
kwargs
)
if
len
(
ret
.
shape
)
==
2
:
ret
=
ret
[:,
:,
np
.
newaxis
]
return
ret
return
wrapper
@
keepdims
def
flip
(
image
,
code
):
"""
Accordding to the code (the type of flip), flip the input image
...
...
@@ -62,6 +80,7 @@ def flip(image, code):
return
cv2
.
flip
(
image
,
flipCode
=
code
)
@
keepdims
def
resize
(
img
,
size
,
interpolation
=
cv2
.
INTER_LINEAR
):
"""
resize the input data to given size
...
...
@@ -103,6 +122,7 @@ def resize(img, size, interpolation=cv2.INTER_LINEAR):
return
cv2
.
resize
(
img
,
size
[::
-
1
],
interpolation
=
interpolation
)
@
keepdims
def
pad
(
img
,
padding
,
fill
=
(
0
,
0
,
0
),
padding_mode
=
'constant'
):
"""Pads the given CV Image on all sides with speficified padding mode and fill value.
...
...
@@ -193,6 +213,7 @@ def pad(img, padding, fill=(0, 0, 0), padding_mode='constant'):
return
img
@
keepdims
def
rotate
(
img
,
angle
,
interpolation
=
cv2
.
INTER_LINEAR
,
...
...
@@ -266,6 +287,7 @@ def rotate(img,
return
dst
.
astype
(
dtype
)
@
keepdims
def
to_grayscale
(
img
,
num_output_channels
=
1
):
"""Converts image to grayscale version of image.
...
...
python/paddle/incubate/hapi/vision/transforms/transforms.py
浏览文件 @
4106e54c
...
...
@@ -505,7 +505,7 @@ class Normalize(object):
mean
=
[
mean
,
mean
,
mean
]
if
isinstance
(
std
,
numbers
.
Number
):
mean
=
[
std
,
std
,
std
]
std
=
[
std
,
std
,
std
]
self
.
mean
=
np
.
array
(
mean
,
dtype
=
np
.
float32
).
reshape
(
len
(
mean
),
1
,
1
)
self
.
std
=
np
.
array
(
std
,
dtype
=
np
.
float32
).
reshape
(
len
(
std
),
1
,
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录