This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-380] count_include_pad argument for Avg Pooling #11021
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3fdf26
add count_include_pad argument
5b5b702
add cound_include_pad in cudnn pooling and corresponding tests
dec157a
add gluon support for the new option
7935e8e
switch to built-in functions for artificial NaN
db6279d
add doc for gluon
5a07a43
change isAvg/getAvg to is_avg/get_avg
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -675,7 +675,7 @@ def __init__(self, channels, kernel_size, strides=(1, 1, 1), padding=(0, 0, 0), | |
class _Pooling(HybridBlock): | ||
"""Abstract class for different pooling layers.""" | ||
def __init__(self, pool_size, strides, padding, ceil_mode, global_pool, | ||
pool_type, **kwargs): | ||
pool_type, count_include_pad=None, **kwargs): | ||
super(_Pooling, self).__init__(**kwargs) | ||
if strides is None: | ||
strides = pool_size | ||
|
@@ -687,6 +687,8 @@ def __init__(self, pool_size, strides, padding, ceil_mode, global_pool, | |
'kernel': pool_size, 'stride': strides, 'pad': padding, | ||
'global_pool': global_pool, 'pool_type': pool_type, | ||
'pooling_convention': 'full' if ceil_mode else 'valid'} | ||
if count_include_pad is not None: | ||
self._kwargs['count_include_pad'] = count_include_pad | ||
|
||
def _alias(self): | ||
return 'pool' | ||
|
@@ -863,6 +865,8 @@ class AvgPool1D(_Pooling): | |
respectively. padding is applied on 'W' dimension. | ||
ceil_mode : bool, default False | ||
When `True`, will use ceil instead of floor to compute the output shape. | ||
count_include_pad : bool, default True | ||
When 'False', will exclude padding elements when computing the average value. | ||
|
||
|
||
Inputs: | ||
|
@@ -879,13 +883,13 @@ class AvgPool1D(_Pooling): | |
equation. | ||
""" | ||
def __init__(self, pool_size=2, strides=None, padding=0, layout='NCW', | ||
ceil_mode=False, **kwargs): | ||
ceil_mode=False, count_include_pad=True, **kwargs): | ||
assert layout == 'NCW', "Only supports 'NCW' layout for now" | ||
if isinstance(pool_size, numeric_types): | ||
pool_size = (pool_size,) | ||
assert len(pool_size) == 1, "pool_size must be a number or a list of 1 ints" | ||
super(AvgPool1D, self).__init__( | ||
pool_size, strides, padding, ceil_mode, False, 'avg', **kwargs) | ||
pool_size, strides, padding, ceil_mode, False, 'avg', count_include_pad, **kwargs) | ||
|
||
|
||
class AvgPool2D(_Pooling): | ||
|
@@ -907,6 +911,8 @@ class AvgPool2D(_Pooling): | |
dimensions respectively. padding is applied on 'H' and 'W' dimension. | ||
ceil_mode : bool, default False | ||
When True, will use ceil instead of floor to compute the output shape. | ||
count_include_pad : bool, default True | ||
When 'False', will exclude padding elements when computing the average value. | ||
|
||
|
||
Inputs: | ||
|
@@ -926,13 +932,13 @@ class AvgPool2D(_Pooling): | |
equation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here and and for AvgPool3D |
||
""" | ||
def __init__(self, pool_size=(2, 2), strides=None, padding=0, | ||
ceil_mode=False, layout='NCHW', **kwargs): | ||
ceil_mode=False, layout='NCHW', count_include_pad=True, **kwargs): | ||
assert layout == 'NCHW', "Only supports 'NCHW' layout for now" | ||
if isinstance(pool_size, numeric_types): | ||
pool_size = (pool_size,)*2 | ||
assert len(pool_size) == 2, "pool_size must be a number or a list of 2 ints" | ||
super(AvgPool2D, self).__init__( | ||
pool_size, strides, padding, ceil_mode, False, 'avg', **kwargs) | ||
pool_size, strides, padding, ceil_mode, False, 'avg', count_include_pad, **kwargs) | ||
|
||
|
||
class AvgPool3D(_Pooling): | ||
|
@@ -955,6 +961,8 @@ class AvgPool3D(_Pooling): | |
dimension. | ||
ceil_mode : bool, default False | ||
When True, will use ceil instead of floor to compute the output shape. | ||
count_include_pad : bool, default True | ||
When 'False', will exclude padding elements when computing the average value. | ||
|
||
|
||
Inputs: | ||
|
@@ -975,13 +983,13 @@ class AvgPool3D(_Pooling): | |
equation. | ||
""" | ||
def __init__(self, pool_size=(2, 2, 2), strides=None, padding=0, | ||
ceil_mode=False, layout='NCDHW', **kwargs): | ||
ceil_mode=False, layout='NCDHW', count_include_pad=True, **kwargs): | ||
assert layout == 'NCDHW', "Only supports 'NCDHW' layout for now" | ||
if isinstance(pool_size, numeric_types): | ||
pool_size = (pool_size,)*3 | ||
assert len(pool_size) == 3, "pool_size must be a number or a list of 3 ints" | ||
super(AvgPool3D, self).__init__( | ||
pool_size, strides, padding, ceil_mode, False, 'avg', **kwargs) | ||
pool_size, strides, padding, ceil_mode, False, 'avg', count_include_pad, **kwargs) | ||
|
||
|
||
class GlobalMaxPool1D(_Pooling): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add documentation for count_include_pad for gluon blocks