Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
a0576250
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看板
未验证
提交
a0576250
编写于
12月 16, 2022
作者:
R
Ryan
提交者:
GitHub
12月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2St] transforms.RandomCrop Support static mode (#49057)
* add RandomCrop * 10e-5 => eps * add same shape test
上级
73ec9b78
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
2 deletion
+50
-2
python/paddle/tests/test_transforms_static.py
python/paddle/tests/test_transforms_static.py
+44
-0
python/paddle/vision/transforms/transforms.py
python/paddle/vision/transforms/transforms.py
+6
-2
未找到文件。
python/paddle/tests/test_transforms_static.py
浏览文件 @
a0576250
...
@@ -60,6 +60,8 @@ class TestTransformUnitTestBase(unittest.TestCase):
...
@@ -60,6 +60,8 @@ class TestTransformUnitTestBase(unittest.TestCase):
def
test_transform
(
self
):
def
test_transform
(
self
):
dy_res
=
self
.
dynamic_transform
()
dy_res
=
self
.
dynamic_transform
()
if
isinstance
(
dy_res
,
paddle
.
Tensor
):
dy_res
=
dy_res
.
numpy
()
st_res
=
self
.
static_transform
()
st_res
=
self
.
static_transform
()
np
.
testing
.
assert_almost_equal
(
dy_res
,
st_res
)
np
.
testing
.
assert_almost_equal
(
dy_res
,
st_res
)
...
@@ -98,5 +100,47 @@ class TestRandomVerticalFlip1(TestTransformUnitTestBase):
...
@@ -98,5 +100,47 @@ class TestRandomVerticalFlip1(TestTransformUnitTestBase):
self
.
api
=
transforms
.
RandomVerticalFlip
(
prob
=
1
)
self
.
api
=
transforms
.
RandomVerticalFlip
(
prob
=
1
)
class
TestRandomCrop_random
(
TestTransformUnitTestBase
):
def
get_shape
(
self
):
return
(
3
,
240
,
240
)
def
set_trans_api
(
self
):
self
.
crop_size
=
(
224
,
224
)
self
.
api
=
transforms
.
RandomCrop
(
self
.
crop_size
)
def
assert_test_random_equal
(
self
,
res
,
eps
=
10e-5
):
_
,
h
,
w
=
self
.
get_shape
()
c_h
,
c_w
=
self
.
crop_size
res_assert
=
True
for
y
in
range
(
h
-
c_h
):
for
x
in
range
(
w
-
c_w
):
diff_abs_sum
=
np
.
abs
(
(
self
.
img
[:,
y
:
y
+
c_h
,
x
:
x
+
c_w
]
-
res
)
).
sum
()
if
diff_abs_sum
<
eps
:
res_assert
=
False
break
if
not
res_assert
:
break
assert
not
res_assert
def
test_transform
(
self
):
dy_res
=
self
.
dynamic_transform
().
numpy
()
st_res
=
self
.
static_transform
()
self
.
assert_test_random_equal
(
dy_res
)
self
.
assert_test_random_equal
(
st_res
)
class
TestRandomCrop_same
(
TestTransformUnitTestBase
):
def
get_shape
(
self
):
return
(
3
,
224
,
224
)
def
set_trans_api
(
self
):
self
.
crop_size
=
(
224
,
224
)
self
.
api
=
transforms
.
RandomCrop
(
self
.
crop_size
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
python/paddle/vision/transforms/transforms.py
浏览文件 @
a0576250
...
@@ -1138,8 +1138,12 @@ class RandomCrop(BaseTransform):
...
@@ -1138,8 +1138,12 @@ class RandomCrop(BaseTransform):
if
w
==
tw
and
h
==
th
:
if
w
==
tw
and
h
==
th
:
return
0
,
0
,
h
,
w
return
0
,
0
,
h
,
w
i
=
random
.
randint
(
0
,
h
-
th
)
if
paddle
.
in_dynamic_mode
():
j
=
random
.
randint
(
0
,
w
-
tw
)
i
=
random
.
randint
(
0
,
h
-
th
)
j
=
random
.
randint
(
0
,
w
-
tw
)
else
:
i
=
paddle
.
randint
(
low
=
0
,
high
=
h
-
th
)
j
=
paddle
.
randint
(
low
=
0
,
high
=
w
-
tw
)
return
i
,
j
,
th
,
tw
return
i
,
j
,
th
,
tw
def
_apply_image
(
self
,
img
):
def
_apply_image
(
self
,
img
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录