Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f246ebba
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看板
未验证
提交
f246ebba
编写于
10月 13, 2022
作者:
N
Nyakku Shigure
提交者:
GitHub
10月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove compat.round (#46923)
上级
f4a5fe95
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
45 deletion
+15
-45
python/paddle/compat.py
python/paddle/compat.py
+0
-28
python/paddle/fluid/tests/unittests/test_compat.py
python/paddle/fluid/tests/unittests/test_compat.py
+0
-12
python/paddle/fluid/tests/unittests/test_roi_pool_op.py
python/paddle/fluid/tests/unittests/test_roi_pool_op.py
+15
-5
未找到文件。
python/paddle/compat.py
浏览文件 @
f246ebba
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
# limitations under the License.
# limitations under the License.
import
six
import
six
import
math
__all__
=
[]
__all__
=
[]
...
@@ -197,30 +196,3 @@ def _to_bytes(obj, encoding):
...
@@ -197,30 +196,3 @@ def _to_bytes(obj, encoding):
return
obj
return
obj
else
:
else
:
return
six
.
b
(
obj
)
return
six
.
b
(
obj
)
# math related functions
def
round
(
x
,
d
=
0
):
"""
Compatible round which act the same behaviour in Python3.
Args:
x(float) : The number to round halfway.
Returns:
round result of x
"""
if
six
.
PY3
:
# The official walkaround of round in Python3 is incorrect
# we implement according this answer: https://www.techforgeek.info/round_python.html
if
x
>
0.0
:
p
=
10
**
d
return
float
(
math
.
floor
((
x
*
p
)
+
math
.
copysign
(
0.5
,
x
)))
/
p
elif
x
<
0.0
:
p
=
10
**
d
return
float
(
math
.
ceil
((
x
*
p
)
+
math
.
copysign
(
0.5
,
x
)))
/
p
else
:
return
math
.
copysign
(
0.0
,
x
)
else
:
import
__builtin__
return
__builtin__
.
round
(
x
,
d
)
python/paddle/fluid/tests/unittests/test_compat.py
浏览文件 @
f246ebba
...
@@ -236,18 +236,6 @@ class TestCompatible(unittest.TestCase):
...
@@ -236,18 +236,6 @@ class TestCompatible(unittest.TestCase):
for
i
in
l2
:
for
i
in
l2
:
self
.
assertTrue
(
isinstance
(
i
,
bytes
))
self
.
assertTrue
(
isinstance
(
i
,
bytes
))
def
test_round
(
self
):
self
.
assertEqual
(
3.0
,
cpt
.
round
(
3.4
))
self
.
assertEqual
(
4.0
,
cpt
.
round
(
3.5
))
self
.
assertEqual
(
0.0
,
cpt
.
round
(
0.1
))
self
.
assertEqual
(
0.0
,
cpt
.
round
(
0.0
))
self
.
assertEqual
(
-
0.0
,
cpt
.
round
(
-
0.0
))
self
.
assertEqual
(
-
0.0
,
cpt
.
round
(
-
0.1
))
self
.
assertEqual
(
-
3.0
,
cpt
.
round
(
-
3.4
))
self
.
assertEqual
(
-
4.0
,
cpt
.
round
(
-
3.5
))
self
.
assertEqual
(
5.0
,
cpt
.
round
(
5
))
self
.
assertRaises
(
TypeError
,
cpt
.
round
,
None
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_roi_pool_op.py
浏览文件 @
f246ebba
...
@@ -17,10 +17,20 @@ import unittest
...
@@ -17,10 +17,20 @@ import unittest
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
sys
import
sys
import
paddle.compat
as
cpt
from
op_test
import
OpTest
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
decimal
import
Decimal
,
ROUND_HALF_UP
def
_round
(
x
):
"""In Python3 round function rounds to the nearest even number,
we use this function to make the result always round up when the
remainder is 0.5. See more at:
https://stackoverflow.com/questions/33019698/how-to-properly-round-up-half-float-numbers
"""
return
Decimal
(
x
).
to_integral_value
(
rounding
=
ROUND_HALF_UP
)
class
TestROIPoolOp
(
OpTest
):
class
TestROIPoolOp
(
OpTest
):
...
@@ -67,10 +77,10 @@ class TestROIPoolOp(OpTest):
...
@@ -67,10 +77,10 @@ class TestROIPoolOp(OpTest):
for
i
in
range
(
self
.
rois_num
):
for
i
in
range
(
self
.
rois_num
):
roi
=
self
.
rois
[
i
]
roi
=
self
.
rois
[
i
]
roi_batch_id
=
int
(
roi
[
0
])
roi_batch_id
=
int
(
roi
[
0
])
roi_start_w
=
int
(
cpt
.
round
(
roi
[
1
]
*
self
.
spatial_scale
))
roi_start_w
=
int
(
_
round
(
roi
[
1
]
*
self
.
spatial_scale
))
roi_start_h
=
int
(
cpt
.
round
(
roi
[
2
]
*
self
.
spatial_scale
))
roi_start_h
=
int
(
_
round
(
roi
[
2
]
*
self
.
spatial_scale
))
roi_end_w
=
int
(
cpt
.
round
(
roi
[
3
]
*
self
.
spatial_scale
))
roi_end_w
=
int
(
_
round
(
roi
[
3
]
*
self
.
spatial_scale
))
roi_end_h
=
int
(
cpt
.
round
(
roi
[
4
]
*
self
.
spatial_scale
))
roi_end_h
=
int
(
_
round
(
roi
[
4
]
*
self
.
spatial_scale
))
roi_height
=
int
(
max
(
roi_end_h
-
roi_start_h
+
1
,
1
))
roi_height
=
int
(
max
(
roi_end_h
-
roi_start_h
+
1
,
1
))
roi_width
=
int
(
max
(
roi_end_w
-
roi_start_w
+
1
,
1
))
roi_width
=
int
(
max
(
roi_end_w
-
roi_start_w
+
1
,
1
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录