-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix different results over three backends for ResNet50 and MobileNet #9473
Conversation
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.
Thanks for looking into this. LGTM.
…ack-embeddings-from-layer-outputs * upstream/master: (443 commits) Fix `pool_2d` of Theano for backend compatibility (keras-team#9479) Clean up conv backend tests (keras-team#9478) Refactoring of ConvLSTM2D. Added ConvRNN2D and ConvLSTM2DCell. (keras-team#9094) Fix different results over three backends for ResNet50 and MobileNet (keras-team#9473) Add depthwise conv2d for Theano and CNTK (keras-team#9457) Fix ImageDataGenerator preprocessing_function (keras-team#9273) Add separable conv2d for CNTK (keras-team#9442) Remove word “shuffled” from comments in examples (keras-team#9453) Add random brightness to Image Preprocessing (Code Cleanup) (keras-team#9390) Only print Theano RNN dropout warning when needed. Add train test split to DirectoryIterator (keras-team#6152) Misc: Slight optimisation (keras-team#9445) Force update of Sequences for Windows (keras-team#9436) Move tests for datasets (keras-team#9439) Style fixes (keras-team#9441) Increase test coverages by excluding several lines (keras-team#9428) Fixing minor bug in pretrained_word_embeddings example (keras-team#9438) Optimizer - set_weights : check weights length (keras-team#9435) Add `conv_utils_test` (keras-team#9429) Enable `variable_input_channels` test for `InceptionV3` (keras-team#9425) ...
@taehoonlee, since you already understand the issue (I don't), could you, please, document the difference in behavior of Keras |
@ozabluda, Here is a toy example: import numpy as np
from keras.layers import Conv2D
from keras.models import Sequential
from keras import backend as K
w = [np.arange(3*3*5*2).reshape(3, 3, 5, 2)]
if K.backend() == 'theano':
w = [np.flip(np.flip(w[0], 0), 1)]
model = Sequential()
model.add(Conv2D(2, kernel_size=3, strides=2, input_shape=(6, 6, 5),
padding='SAME', use_bias=False))
model.set_weights(w)
model.predict(np.ones((1, 6, 6, 5))) The results are: $ KERAS_BACKEND=theano python test.py
array([[[[1280., 1300.],
[1770., 1800.],
[1770., 1800.]],
[[1470., 1500.],
[1980., 2025.],
[1980., 2025.]],
[[1470., 1500.],
[1980., 2025.],
[1980., 2025.]]]], dtype=float32)
$ KERAS_BACKEND=cntk python test.py
array([[[[1280., 1300.],
[1770., 1800.],
[1770., 1800.]],
[[1470., 1500.],
[1980., 2025.],
[1980., 2025.]],
[[1470., 1500.],
[1980., 2025.],
[1980., 2025.]]]], dtype=float32)
$ KERAS_BACKEND=tensorflow python test.py
array([[[[1980., 2025.],
[1980., 2025.],
[1170., 1200.]],
[[1980., 2025.],
[1980., 2025.],
[1170., 1200.]],
[[ 870., 900.],
[ 870., 900.],
[ 480., 500.]]]], dtype=float32) The difference comes from the difference in padding behavior when
|
I'm getting same output for 1by1 kernel with different padding, for tensorflow backend:
In the above results, xx5 and xx6 have same shape (xx7 and xx8 also ) even though different padding is used for convolution. |
It is really amazing to me that padding which should be an integer has been left to be interpreted from some strange set of strings (for ease of use?). When ease of use destroys clarity, it is time for some upgrade :-) . |
Hi! Is/Has anybody working/worked on making |
As discussed in #9457, there are the discrepancies in
ResNet50
andMobileNet
. The tests scripts are:The outputs of CNTK and Theano are:
The problem is that TensorFlow differs as follows:
The main problem is from different padding behaviour of
Conv2D(filters, kernel, padding='same', strides=(2, 2))
. With explicitZeroPadding2D
, TensorFlow is able to show small numerical differences.