Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 1D convolution layers under Theano backend (#2938)
This issue is due to an unexpected loss of dimensionality when composing the backend tensor operations "reshape" and "squeeze" when there are dimensions of length 1. For example, using a Theano backend the following fails with a complaint about dimension mismatch: UpSampling1D(2)(MaxPooling1D(2)(Reshape((2,1))(Input(shape=(2,))))) The issue arises due to the conflict of two behaviors specific to the Theano backend: - Reshape uses Theano's reshape function. Theano's reshape automatically makes dimensions with length 1 "broadcastable" - MaxPooling1D's implementation class _Pooling1D has a call method which uses a dummy dimension which it has to remove. The manner in which this dummy method is removed it to call "squeeze(x, axis)" from the backend. The squeeze implementation tells Theano to make the dummy dimension broadcastable, and then calls Theano's "squeeze", which removes ALL the broadcastable dimensions; not just the dummy dimension, but also the length 1 dimension flagged as broadcastable by reshape. This causes the problem observed above. This behavior is distinct from the behavior of the TensorFlow backend, which removes only the requested dimension. This PR addresses this issue in two ways: First, it introduces a test which checks the composition of "reshape" and "squeeze" to make sure we get the same result using both Theano and TensorFlow backends. Second, it changes the implementation of squeeze(x,axis) so that the Theano backend should behave similarly to the TensorFlow backend. With this change the introduced test passes and the above example works.
- Loading branch information