Skip to content

Commit

Permalink
Update tensorflow_backend.py
Browse files Browse the repository at this point in the history
From line 1907 - 1918: when call tf.reshape(x, shape), (*before*)shape=(-1) will raise ValueError: Shape must be rank 1 but is rank 0 ...
I think (-1) in python refers to the Rank-0 shape, though [-1] or (-1,) refers to the Rank-1 shape instead.

It was also strange that it only raised error when 'image_data_format' was set to 'channels_first', not 'channels_last'.
  • Loading branch information
StevenPZChan committed Oct 4, 2018
1 parent 1931e21 commit e3a2f7d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions keras/backend/tensorflow_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,17 +1905,17 @@ def batch_normalization(x, mean, var, beta, gamma, axis=-1, epsilon=1e-3):
# The mean / var / beta / gamma may be processed by broadcast
# so it may have extra axes with 1, it is not needed and should be removed
if ndim(mean) > 1:
mean = tf.reshape(mean, (-1))
mean = tf.reshape(mean, [-1])
if ndim(var) > 1:
var = tf.reshape(var, (-1))
var = tf.reshape(var, [-1])
if beta is None:
beta = zeros_like(mean)
elif ndim(beta) > 1:
beta = tf.reshape(beta, (-1))
beta = tf.reshape(beta, [-1])
if gamma is None:
gamma = ones_like(mean)
elif ndim(gamma) > 1:
gamma = tf.reshape(gamma, (-1))
gamma = tf.reshape(gamma, [-1])
y, _, _ = tf.nn.fused_batch_norm(
x,
gamma,
Expand Down

0 comments on commit e3a2f7d

Please sign in to comment.