Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
88662130
Commit
88662130
authored
7 years ago
by
Tianqi Chen
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[TOPI] Support ceil_mode in pooling (#593)
parent
2f2170f4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
topi/python/topi/nn/pooling.py
+12
-1
12 additions, 1 deletion
topi/python/topi/nn/pooling.py
topi/tests/python/test_topi_pooling.py
+20
-6
20 additions, 6 deletions
topi/tests/python/test_topi_pooling.py
with
32 additions
and
7 deletions
topi/python/topi/nn/pooling.py
+
12
−
1
View file @
88662130
...
...
@@ -44,7 +44,7 @@ def global_pool(data, pool_type):
raise
ValueError
(
"
Pool type should be
'
avg
'
or
'
max
'
.
"
)
def
pool
(
data
,
kernel
,
stride
,
padding
,
pool_type
):
def
pool
(
data
,
kernel
,
stride
,
padding
,
pool_type
,
ceil_mode
=
False
):
"""
Perform pooling on the data
Parameters
...
...
@@ -64,6 +64,9 @@ def pool(data, kernel, stride, padding, pool_type):
pool_type : str
Pool type,
'
max
'
or
'
avg
'
ceil_mode : bool
Whether to use ceil when caculate output size.
Returns
-------
output : tvm.Tensor
...
...
@@ -77,10 +80,18 @@ def pool(data, kernel, stride, padding, pool_type):
pad_top
,
pad_left
,
pad_down
,
pad_right
=
get_pad_tuple
(
padding
,
(
kernel_height
,
kernel_width
))
pad_before
=
[
0
,
0
,
pad_top
,
pad_left
]
pad_after
=
[
0
,
0
,
pad_down
,
pad_right
]
if
ceil_mode
:
# Additional padding to ensure we do ceil instead of floor when divide stride.
pad_down
+=
stride_height
-
1
pad_right
+=
stride_width
-
1
out_height
=
util
.
simplify
((
height
-
kernel_height
+
pad_top
+
pad_down
)
//
stride_height
+
1
)
out_width
=
util
.
simplify
((
width
-
kernel_width
+
pad_left
+
pad_right
)
//
stride_width
+
1
)
dheight
=
tvm
.
reduce_axis
((
0
,
kernel_height
))
dwidth
=
tvm
.
reduce_axis
((
0
,
kernel_width
))
...
...
This diff is collapsed.
Click to expand it.
topi/tests/python/test_topi_pooling.py
+
20
−
6
View file @
88662130
...
...
@@ -2,18 +2,30 @@
import
numpy
as
np
import
tvm
import
topi
import
math
from
topi.util
import
get_const_tuple
def
verify_pool
(
n
,
ic
,
ih
,
kh
,
sh
,
padding
,
pool_type
):
def
verify_pool
(
n
,
ic
,
ih
,
kh
,
sh
,
padding
,
pool_type
,
ceil_mode
):
iw
=
ih
kw
=
kh
sw
=
sh
ph
,
pw
=
padding
A
=
tvm
.
placeholder
((
n
,
ic
,
ih
,
iw
),
name
=
'
A
'
)
B
=
topi
.
nn
.
pool
(
A
,
kernel
=
[
kh
,
kw
],
stride
=
[
sh
,
sw
],
padding
=
padding
,
pool_type
=
pool_type
)
B
=
topi
.
nn
.
pool
(
A
,
kernel
=
[
kh
,
kw
],
stride
=
[
sh
,
sw
],
padding
=
padding
,
pool_type
=
pool_type
,
ceil_mode
=
ceil_mode
)
B
=
topi
.
nn
.
relu
(
B
)
dtype
=
A
.
dtype
bshape
=
get_const_tuple
(
B
.
shape
)
ashape
=
get_const_tuple
(
A
.
shape
)
if
ceil_mode
:
assert
bshape
[
2
]
==
int
(
math
.
ceil
(
float
(
ashape
[
2
]
-
kh
+
ph
*
2
)
/
sh
)
+
1
)
assert
bshape
[
3
]
==
int
(
math
.
ceil
(
float
(
ashape
[
3
]
-
kw
+
pw
*
2
)
/
sw
)
+
1
)
else
:
assert
bshape
[
2
]
==
int
(
math
.
floor
(
float
(
ashape
[
2
]
-
kh
+
ph
*
2
)
/
sh
)
+
1
)
assert
bshape
[
3
]
==
int
(
math
.
floor
(
float
(
ashape
[
3
]
-
kw
+
pw
*
2
)
/
sw
)
+
1
)
a_np
=
np
.
random
.
uniform
(
size
=
(
n
,
ic
,
ih
,
iw
)).
astype
(
dtype
)
pad_np
=
np
.
zeros
(
shape
=
(
n
,
ic
,
ih
+
2
*
ph
,
iw
+
2
*
pw
)).
astype
(
dtype
)
no_zero
=
(
range
(
n
),
range
(
ic
),
(
range
(
ph
,
ih
+
ph
)),
(
range
(
pw
,
iw
+
pw
)))
...
...
@@ -49,10 +61,12 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type):
check_device
(
device
)
def
test_pool
():
verify_pool
(
1
,
256
,
32
,
2
,
2
,
[
0
,
0
],
'
avg
'
)
verify_pool
(
1
,
256
,
31
,
3
,
3
,
[
1
,
1
],
'
avg
'
)
verify_pool
(
1
,
256
,
32
,
2
,
2
,
[
0
,
0
],
'
max
'
)
verify_pool
(
1
,
256
,
31
,
3
,
3
,
[
1
,
1
],
'
max
'
)
verify_pool
(
1
,
256
,
32
,
2
,
2
,
[
0
,
0
],
'
avg
'
,
False
)
verify_pool
(
1
,
256
,
31
,
3
,
3
,
[
1
,
2
],
'
avg
'
,
False
)
verify_pool
(
1
,
256
,
32
,
2
,
2
,
[
0
,
0
],
'
max
'
,
False
)
verify_pool
(
1
,
256
,
31
,
3
,
3
,
[
2
,
1
],
'
max
'
,
False
)
verify_pool
(
1
,
256
,
31
,
3
,
3
,
[
2
,
1
],
'
max
'
,
True
)
def
verify_global_pool
(
n
,
c
,
h
,
w
,
pool_type
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment