keras-team/keras · error · ValueError
axis size must be divisible by 2. Received: x.shape={x.shape
Error message
axis size must be divisible by 2. Received: x.shape={x.shape} with axis={axis} What it means
Error "axis size must be divisible by 2. Received: x.shape={x.shape} with axis={axis}" thrown in keras-team/keras.
Source
Thrown at keras/src/backend/tensorflow/nn.py:145
return tf.nn.selu(x)
def gelu(x, approximate=True):
x = convert_to_tensor(x)
return tf.nn.gelu(x, approximate=approximate)
def celu(x, alpha=1.0):
return tf.maximum(x, 0.0) + alpha * tf.math.expm1(
tf.minimum(x, 0.0) / alpha
)
def glu(x, axis=-1):
x = convert_to_tensor(x)
canonicalize_axis(axis, len(x.shape))
if x.shape[axis] % 2 != 0:
raise ValueError(
"axis size must be divisible by 2. "
f"Received: x.shape={x.shape} with axis={axis}"
)
x1, x2 = tf.split(x, num_or_size_splits=2, axis=axis)
return x1 * tf.sigmoid(x2)
def hard_tanh(x):
return tf.clip_by_value(x, clip_value_min=-1.0, clip_value_max=1.0)
def hard_shrink(x, threshold=0.5):
return tf.where(tf.abs(x) > threshold, x, tf.zeros_like(x))
def threshold(x, threshold, default_value):
return tf.where(x > threshold, x, default_value)
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/tensorflow/nn.py:145 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/da83a0665f133a71.
Report an issue: GitHub.