diff --git a/tensorflow/python/ops/special_math_ops.py b/tensorflow/python/ops/special_math_ops.py index 7ad841c18a4..2f350c114fd 100644 --- a/tensorflow/python/ops/special_math_ops.py +++ b/tensorflow/python/ops/special_math_ops.py @@ -533,7 +533,8 @@ def _reshape_if_necessary(tensor, new_shape): new_shape = tuple(-1 if x is None else x for x in new_shape) cur_shape = tuple(x.value for x in tensor.get_shape().dims) if (len(new_shape) == len(cur_shape) and - all(d0 == d1 or d1 == -1 for d0, d1 in zip(cur_shape, new_shape))): + all(not isinstance(d1, ops.Tensor) and (d0 == d1 or d1 == -1) + for d0, d1 in zip(cur_shape, new_shape))): return tensor else: return array_ops.reshape(tensor, new_shape)