keras-team/keras · error · ValueError
For NASNet-A models, the `penultimate_filters` must be a…
Error message
For NASNet-A models, the `penultimate_filters` must be a multiple of 24 * (`filter_multiplier` ** 2). Current value: {penultimate_filters} What it means
NASNet family constraint in keras/src/applications/nasnet.py: the architecture's penultimate filter count must satisfy the divisibility relation penultimate_filters % (24 * filter_multiplier**2) == 0 for the reduction splits to tile evenly. A custom penultimate_filters value that violates this (e.g. for NASNetMobile: multiple of 24*4=96) makes block construction impossible, so the builder rejects it.
Solutions
- Use penultimate_filters=4096 with filter_multiplier=24 (NASNetLarge) or 1056 with 8 (NASNetMobile)
- Choose a penultimate_filters value divisible by 24 * filter_multiplier**2
- Keep default architecture parameters instead of customizing filter counts
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/applications/nasnet.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/02f26b579b76483e.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/applications/nasnet.py:181
"However your settings specify the default "
'data format "channels_first" (channels, width, height).'
' You should set `image_data_format="channels_last"` '
"in your Keras config located at ~/.keras/keras.json. "
"The model being returned right now will expect inputs "
'to follow the "channels_last" data format.',
stacklevel=2,
)
if input_tensor is None:
img_input = layers.Input(shape=input_shape)
else:
if not backend.is_keras_tensor(input_tensor):
img_input = layers.Input(tensor=input_tensor, shape=input_shape)
else:
img_input = input_tensor
if penultimate_filters % (24 * (filter_multiplier**2)) != 0:
raise ValueError(
"For NASNet-A models, the `penultimate_filters` must be a multiple "
"of 24 * (`filter_multiplier` ** 2). "
f"Current value: {penultimate_filters}"
)
channel_dim = 1 if backend.image_data_format() == "channels_first" else -1
filters = penultimate_filters // 24
x = layers.Conv2D(
stem_block_filters,
(3, 3),
strides=(2, 2),
padding="valid",
use_bias=False,
name="stem_conv1",
kernel_initializer="he_normal",
)(img_input)
View on GitHub (pinned to 7a34a03db6)