Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
4106e54c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
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):
...
@@ -64,6 +64,11 @@ class TestTransforms(unittest.TestCase):
self
.
do_transform
(
trans
)
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
):
def
test_trans_resize
(
self
):
trans
=
transforms
.
Compose
([
trans
=
transforms
.
Compose
([
transforms
.
Resize
(
300
,
[
0
,
1
]),
transforms
.
Resize
(
300
,
[
0
,
1
]),
...
@@ -165,7 +170,7 @@ class TestTransforms(unittest.TestCase):
...
@@ -165,7 +170,7 @@ class TestTransforms(unittest.TestCase):
fake_img
=
np
.
random
.
rand
(
500
,
400
,
3
).
astype
(
'float32'
)
fake_img
=
np
.
random
.
rand
(
500
,
400
,
3
).
astype
(
'float32'
)
fake_img_gray
=
trans_gray
(
fake_img
)
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
[
0
],
500
)
np
.
testing
.
assert_equal
(
fake_img_gray
.
shape
[
1
],
400
)
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
...
@@ -16,6 +16,7 @@ import sys
import
collections
import
collections
import
random
import
random
import
math
import
math
import
functools
import
cv2
import
cv2
import
numbers
import
numbers
...
@@ -31,6 +32,23 @@ else:
...
@@ -31,6 +32,23 @@ else:
__all__
=
[
'flip'
,
'resize'
,
'pad'
,
'rotate'
,
'to_grayscale'
]
__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
):
def
flip
(
image
,
code
):
"""
"""
Accordding to the code (the type of flip), flip the input image
Accordding to the code (the type of flip), flip the input image
...
@@ -62,6 +80,7 @@ def flip(image, code):
...
@@ -62,6 +80,7 @@ def flip(image, code):
return
cv2
.
flip
(
image
,
flipCode
=
code
)
return
cv2
.
flip
(
image
,
flipCode
=
code
)
@
keepdims
def
resize
(
img
,
size
,
interpolation
=
cv2
.
INTER_LINEAR
):
def
resize
(
img
,
size
,
interpolation
=
cv2
.
INTER_LINEAR
):
"""
"""
resize the input data to given size
resize the input data to given size
...
@@ -103,6 +122,7 @@ def resize(img, size, interpolation=cv2.INTER_LINEAR):
...
@@ -103,6 +122,7 @@ def resize(img, size, interpolation=cv2.INTER_LINEAR):
return
cv2
.
resize
(
img
,
size
[::
-
1
],
interpolation
=
interpolation
)
return
cv2
.
resize
(
img
,
size
[::
-
1
],
interpolation
=
interpolation
)
@
keepdims
def
pad
(
img
,
padding
,
fill
=
(
0
,
0
,
0
),
padding_mode
=
'constant'
):
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.
"""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'):
...
@@ -193,6 +213,7 @@ def pad(img, padding, fill=(0, 0, 0), padding_mode='constant'):
return
img
return
img
@
keepdims
def
rotate
(
img
,
def
rotate
(
img
,
angle
,
angle
,
interpolation
=
cv2
.
INTER_LINEAR
,
interpolation
=
cv2
.
INTER_LINEAR
,
...
@@ -266,6 +287,7 @@ def rotate(img,
...
@@ -266,6 +287,7 @@ def rotate(img,
return
dst
.
astype
(
dtype
)
return
dst
.
astype
(
dtype
)
@
keepdims
def
to_grayscale
(
img
,
num_output_channels
=
1
):
def
to_grayscale
(
img
,
num_output_channels
=
1
):
"""Converts image to grayscale version of image.
"""Converts image to grayscale version of image.
...
...
python/paddle/incubate/hapi/vision/transforms/transforms.py
浏览文件 @
4106e54c
...
@@ -505,7 +505,7 @@ class Normalize(object):
...
@@ -505,7 +505,7 @@ class Normalize(object):
mean
=
[
mean
,
mean
,
mean
]
mean
=
[
mean
,
mean
,
mean
]
if
isinstance
(
std
,
numbers
.
Number
):
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
.
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
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录