Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
88662130
Commit
88662130
authored
Oct 27, 2017
by
Tianqi Chen
Committed by
GitHub
Oct 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TOPI] Support ceil_mode in pooling (#593)
parent
2f2170f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
topi/python/topi/nn/pooling.py
+12
-1
topi/tests/python/test_topi_pooling.py
+20
-6
No files found.
topi/python/topi/nn/pooling.py
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
))
...
...
topi/tests/python/test_topi_pooling.py
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment