Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e357cfdd
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看板
未验证
提交
e357cfdd
编写于
5月 10, 2021
作者:
W
Wenyu
提交者:
GitHub
5月 10, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update unittest for uint8 problem (#32790)
上级
5fc734ce
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
23 deletion
+27
-23
python/paddle/tests/test_transforms.py
python/paddle/tests/test_transforms.py
+27
-23
未找到文件。
python/paddle/tests/test_transforms.py
浏览文件 @
e357cfdd
...
...
@@ -525,10 +525,10 @@ class TestFunctional(unittest.TestCase):
image_load
(
'tmp.jpg'
,
backend
=
1
)
def
test_normalize
(
self
):
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)).
astype
(
'uint8'
)
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)
*
255
).
astype
(
'uint8'
)
pil_img
=
Image
.
fromarray
(
np_img
)
tensor_img
=
F
.
to_tensor
(
pil_img
)
tensor_img_hwc
=
F
.
to_tensor
(
pil_img
,
data_format
=
'HWC'
)
tensor_img_hwc
=
F
.
to_tensor
(
pil_img
,
data_format
=
'HWC'
)
*
255
mean
=
[
0.5
,
0.5
,
0.5
]
std
=
[
0.5
,
0.5
,
0.5
]
...
...
@@ -539,17 +539,17 @@ class TestFunctional(unittest.TestCase):
normalized_img_pil
=
F
.
normalize
(
pil_img
,
mean
,
std
,
data_format
=
'HWC'
)
normalized_img_np
=
F
.
normalize
(
np_img
,
mean
,
std
,
data_format
=
'HWC'
,
to_rgb
=
Tru
e
)
np_img
,
mean
,
std
,
data_format
=
'HWC'
,
to_rgb
=
Fals
e
)
np
.
testing
.
assert_almost_equal
(
np
.
array
(
normalized_img_pil
),
normalized_img_np
)
np
.
testing
.
assert_almost_equal
(
normalized_img_tensor
.
numpy
(),
normalized_img_np
)
np
.
testing
.
assert_almost_equal
(
normalized_img_tensor
.
numpy
(),
normalized_img_np
,
decimal
=
4
)
def
test_center_crop
(
self
):
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)).
astype
(
'uint8'
)
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)
*
255
).
astype
(
'uint8'
)
pil_img
=
Image
.
fromarray
(
np_img
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
data_format
=
'CHW'
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
data_format
=
'CHW'
)
*
255
np_cropped_img
=
F
.
center_crop
(
np_img
,
4
)
pil_cropped_img
=
F
.
center_crop
(
pil_img
,
4
)
...
...
@@ -557,23 +557,25 @@ class TestFunctional(unittest.TestCase):
np
.
testing
.
assert_almost_equal
(
np_cropped_img
,
np
.
array
(
pil_cropped_img
))
np
.
testing
.
assert_almost_equal
(
np_cropped_img
,
tensor_cropped_img
.
numpy
().
transpose
(
(
1
,
2
,
0
)))
np
.
testing
.
assert_almost_equal
(
np_cropped_img
,
tensor_cropped_img
.
numpy
().
transpose
((
1
,
2
,
0
)),
decimal
=
4
)
def
test_pad
(
self
):
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)).
astype
(
'uint8'
)
np_img
=
(
np
.
random
.
rand
(
28
,
24
,
3
)
*
255
).
astype
(
'uint8'
)
pil_img
=
Image
.
fromarray
(
np_img
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
'CHW'
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
'CHW'
)
*
255
np_padded_img
=
F
.
pad
(
np_img
,
[
1
,
2
],
padding_mode
=
'reflect'
)
pil_padded_img
=
F
.
pad
(
pil_img
,
[
1
,
2
],
padding_mode
=
'reflect'
)
tensor_padded_img
=
F
.
pad
(
tensor_img
,
[
1
,
2
],
padding_mode
=
'reflect'
)
np
.
testing
.
assert_almost_equal
(
np_padded_img
,
np
.
array
(
pil_padded_img
))
np
.
testing
.
assert_almost_equal
(
np_padded_img
,
tensor_padded_img
.
numpy
().
transpose
(
(
1
,
2
,
0
)))
np
.
testing
.
assert_almost_equal
(
np_padded_img
,
tensor_padded_img
.
numpy
().
transpose
((
1
,
2
,
0
)),
decimal
=
3
)
tensor_padded_img
=
F
.
pad
(
tensor_img
,
1
,
padding_mode
=
'reflect'
)
tensor_padded_img
=
F
.
pad
(
tensor_img
,
[
1
,
2
,
1
,
2
],
...
...
@@ -584,9 +586,9 @@ class TestFunctional(unittest.TestCase):
pil_padded_img
=
F
.
pad
(
pil_p_img
,
[
1
,
2
],
padding_mode
=
'reflect'
)
def
test_resize
(
self
):
np_img
=
(
np
.
zeros
([
28
,
24
,
3
])).
astype
(
'uint8'
)
np_img
=
(
np
.
zeros
([
28
,
24
,
3
])
*
255
).
astype
(
'uint8'
)
pil_img
=
Image
.
fromarray
(
np_img
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
'CHW'
)
tensor_img
=
F
.
to_tensor
(
pil_img
,
'CHW'
)
*
255
np_reseized_img
=
F
.
resize
(
np_img
,
40
)
pil_reseized_img
=
F
.
resize
(
pil_img
,
40
)
...
...
@@ -595,12 +597,14 @@ class TestFunctional(unittest.TestCase):
np
.
testing
.
assert_almost_equal
(
np_reseized_img
,
np
.
array
(
pil_reseized_img
))
np
.
testing
.
assert_almost_equal
(
np_reseized_img
,
tensor_reseized_img
.
numpy
().
transpose
(
(
1
,
2
,
0
)))
np
.
testing
.
assert_almost_equal
(
np_reseized_img
,
tensor_reseized_img2
.
numpy
().
transpose
(
(
1
,
2
,
0
)))
np
.
testing
.
assert_almost_equal
(
np_reseized_img
,
tensor_reseized_img
.
numpy
().
transpose
((
1
,
2
,
0
)),
decimal
=
3
)
np
.
testing
.
assert_almost_equal
(
np_reseized_img
,
tensor_reseized_img2
.
numpy
().
transpose
((
1
,
2
,
0
)),
decimal
=
3
)
gray_img
=
(
np
.
zeros
([
28
,
32
])).
astype
(
'uint8'
)
gray_resize_img
=
F
.
resize
(
gray_img
,
40
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录