From 3634ca6bfc1d1d4597f1303d5d6be852da24c890 Mon Sep 17 00:00:00 2001 From: Somshubra Majumdar Date: Mon, 27 Feb 2017 23:00:52 -0600 Subject: [PATCH] Add assertions to prevent using wrong dim ordering/backends when using depth_to_space backend methods --- keras_contrib/backend/tensorflow_backend.py | 2 ++ keras_contrib/backend/theano_backend.py | 2 ++ pytest.ini | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/keras_contrib/backend/tensorflow_backend.py b/keras_contrib/backend/tensorflow_backend.py index 73bd8e8..259fefe 100644 --- a/keras_contrib/backend/tensorflow_backend.py +++ b/keras_contrib/backend/tensorflow_backend.py @@ -103,6 +103,8 @@ def extract_image_patches(X, ksizes, ssizes, border_mode="same", dim_ordering="t def depth_to_space(input, scale): ''' Uses phase shift algorithm to convert channels/depth for spatial resolution ''' + assert K.image_dim_ordering() == 'tf', 'depth_to_scale backend function can only be used with "tf" dim ' \ + 'ordering when using tensorflow backend' return tf.depth_to_space(input, scale) diff --git a/keras_contrib/backend/theano_backend.py b/keras_contrib/backend/theano_backend.py index 06e1fcb..963bc90 100644 --- a/keras_contrib/backend/theano_backend.py +++ b/keras_contrib/backend/theano_backend.py @@ -121,6 +121,8 @@ def extract_image_patches(X, ksizes, strides, border_mode="valid", dim_ordering= def depth_to_space(input, scale): ''' Uses phase shift algorithm to convert channels/depth for spatial resolution ''' + assert K.image_dim_ordering() == 'th', 'depth_to_scale backend function can only be used with "th" dim ' \ + 'ordering when using theano backend' b, k, row, col = input.shape output_shape = (b, input._keras_shape[1] // (scale ** 2), row * scale, col * scale) diff --git a/pytest.ini b/pytest.ini index 079ed86..44ae0ee 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,10 +1,10 @@ # Configuration of py.test [pytest] addopts=-v - -n 2 + #-n 2 --durations=10 - --cov-report term-missing - --cov=keras + #--cov-report term-missing + #--cov=keras # Do not run tests in the build folder norecursedirs= build