keras-team/keras · error · ValueError
ImageNet weights can only be loaded with NASNetLarge or…
Error message
ImageNet weights can only be loaded with NASNetLarge or NASNetMobile
What it means
NASNet weight-loading branch in keras/src/applications/nasnet.py: pretrained ImageNet checkpoints are only published for NASNetLarge (331px) and NASNetMobile (224px) configurations. A custom NASNet variant (different penultimate_filters/default_size) reaches the weight-loading code without a matching checkpoint, so ImageNet weights cannot be provided for it.
Solutions
- Use the stock NASNetLarge or NASNetMobile entry points when requesting weights="imagenet"
- Use weights=None for custom NASNet architectures and train from scratch
- Check that penultimate_filters and default_size match a configuration with published weights
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at keras/src/applications/nasnet.py:304 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/af4b1221f7fbe0f4.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/applications/nasnet.py:304
model.load_weights(weights_path)
elif default_size == 331: # large version
if include_top:
weights_path = file_utils.get_file(
"nasnet_large.h5",
NASNET_LARGE_WEIGHT_PATH,
cache_subdir="models",
file_hash="11577c9a518f0070763c2b964a382f17",
)
else:
weights_path = file_utils.get_file(
"nasnet_large_no_top.h5",
NASNET_LARGE_WEIGHT_PATH_NO_TOP,
cache_subdir="models",
file_hash="d81d89dc07e6e56530c4e77faddd61b5",
)
model.load_weights(weights_path)
else:
raise ValueError(
"ImageNet weights can only be loaded with NASNetLarge"
" or NASNetMobile"
)
elif weights is not None:
model.load_weights(weights)
return model
@keras_export(
[
"keras.applications.nasnet.NASNetMobile",
"keras.applications.NASNetMobile",
]
)
def NASNetMobile(
input_shape=None,
include_top=True,View on GitHub (pinned to 7a34a03db6)