forked from pfnet-research/chainer-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implementated average poolin 2d.
The supported args cannot be tuple right now. This is WIP. Will extend it to support tuple arguments. Addresses: issue pfnet-research#160
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# coding: utf-8 | ||
|
||
import chainer | ||
import chainer.functions as F | ||
|
||
|
||
class AvgPool(chainer.Chain): | ||
|
||
def __init__(self): | ||
super(AvgPool, self).__init__() | ||
|
||
def forward(self, x): | ||
y1 = F.average_pooling_2d(x, 1, stride=2) | ||
return y1 | ||
|
||
|
||
class AvgPoolPad(chainer.Chain): | ||
|
||
def __init__(self): | ||
super(AvgPoolPad, self).__init__() | ||
|
||
def forward(self, x): | ||
y1 = F.average_pooling_2d(x, 3, stride=1, pad=2) | ||
return y1 | ||
|
||
|
||
class AvgPoolNoStride(chainer.Chain): | ||
|
||
def __init__(self): | ||
super(AvgPoolNoStride, self).__init__() | ||
|
||
def forward(self, x): | ||
y1 = F.average_pooling_2d(x, 3) | ||
return y1 | ||
|
||
|
||
# ====================================== | ||
|
||
import testtools | ||
import numpy as np | ||
|
||
|
||
def main(): | ||
np.random.seed(123) | ||
x = np.random.rand(2, 20, 15, 17).astype(np.float32) | ||
|
||
testtools.generate_testcase(AvgPool(), [x], subname='default') | ||
testtools.generate_testcase(AvgPoolPad(), [x], subname='withpad') | ||
testtools.generate_testcase(AvgPoolNoStride(), [x], subname='withoutstride') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |