Skip to content

Commit

Permalink
Fix pool_2d of Theano for backend compatibility (keras-team#9479)
Browse files Browse the repository at this point in the history
* Fix `pool_2d` of Theano for backend compatibility

* Add a test
  • Loading branch information
taehoonlee authored and fchollet committed Feb 26, 2018
1 parent 5e79743 commit 07c77c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 1 addition & 5 deletions keras/backend/theano_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,14 +2171,10 @@ def pool2d(x, pool_size, strides=(1, 1), padding='valid',
pad=pad,
mode='max')
elif pool_mode == 'avg':
if padding == 'same':
th_avg_pool_mode = 'average_inc_pad'
elif padding == 'valid':
th_avg_pool_mode = 'average_exc_pad'
pool_out = pool.pool_2d(x, ws=pool_size, stride=strides,
ignore_border=True,
pad=pad,
mode=th_avg_pool_mode)
mode='average_exc_pad')
else:
raise ValueError('Invalid pooling mode:', pool_mode)
if padding == 'same':
Expand Down
5 changes: 5 additions & 0 deletions tests/keras/backend/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,11 @@ def test_pool2d(self):
BACKENDS, cntk_dynamicity=True,
pool_size=(2, 3), strides=(1, 1), padding='valid')

check_single_tensor_operation('pool2d', (2, 7, 7, 5),
BACKENDS, cntk_dynamicity=True,
pool_size=(3, 3), strides=(1, 1),
padding='same', pool_mode='avg')

def test_pool3d(self):
check_single_tensor_operation('pool3d', (5, 10, 12, 5, 3),
BACKENDS, cntk_dynamicity=True,
Expand Down

0 comments on commit 07c77c6

Please sign in to comment.