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/numpy/ops/nn.py:181
* (scipy.special.erf(x / sqrt_2) + 1).astype(x.dtype)
/ np.array(2, x.dtype)
)
def celu(x, alpha=1.0):
x = convert_to_tensor(x)
alpha = np.array(alpha, x.dtype)
return np.maximum(x, np.array(0.0, dtype=x.dtype)) + alpha * np.expm1(
np.minimum(x, np.array(0.0, dtype=x.dtype)) / alpha
)
def glu(x, axis=-1):
x = convert_to_tensor(x)
dtype = x.dtype
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 = np.split(x, 2, axis)
return (x1 * sigmoid(x2)).astype(dtype)
def hard_tanh(x):
x = convert_to_tensor(x)
min_val = np.asarray(-1.0, x.dtype)
max_val = np.asarray(1.0, x.dtype)
return np.array(np.clip(x, min_val, max_val), dtype=x.dtype)
def hard_shrink(x, threshold=0.5):
x = convert_to_tensor(x)
threshold = np.asarray(threshold, x.dtype)
return np.array(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/nn.py:181 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/1d6f9c7ef75a6339.
Report an issue: GitHub.