keras-team/keras · error · ValueError
The `weights` argument should be either `None` (random…
Error message
The `weights` argument should be either `None` (random initialization), 'imagenet' (pre-training on ImageNet), or the path to the weights file to be loaded.
What it means
Guard in the Xception application constructor: the `weights` argument is validated against the set {'imagenet', None} and checked for existence as a file path. A value that is neither — typically a misspelled identifier or a path that does not exist — fails file_utils.exists and falls through to this error.
Solutions
- Pass weights=None for random initialization.
- Pass weights='imagenet' for ImageNet pre-training.
- Pass a valid path to an Xception weights file; verify the path exists with os.path.exists before calling.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/applications/xception.py:96 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/ca3028a71c5fb15a.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/applications/xception.py:96
last convolutional block, and thus
the output of the model will be a 2D tensor.
- `max` means that global max pooling will
be applied.
classes: optional number of classes to classify images
into, only to be specified if `include_top` is `True`, and
if no `weights` argument is specified. Defaults to `1000`.
classifier_activation: A `str` or callable. The activation function to
use on the "top" layer. Ignored unless `include_top=True`. Set
`classifier_activation=None` to return the logits of the "top"
layer. When loading pretrained weights, `classifier_activation` can
only be `None` or `"softmax"`.
name: The name of the model (string).
Returns:
A model instance.
"""
if not (weights in {"imagenet", None} or file_utils.exists(weights)):
raise ValueError(
"The `weights` argument should be either "
"`None` (random initialization), 'imagenet' "
"(pre-training on ImageNet), "
"or the path to the weights file to be loaded."
)
if weights == "imagenet" and include_top and classes != 1000:
raise ValueError(
"If using `weights='imagenet'` with `include_top=True`, "
"`classes` should be 1000. "
f"Received classes={classes}"
)
# Determine proper input shape
input_shape = imagenet_utils.obtain_input_shape(
input_shape,
default_size=299,
min_size=71,View on GitHub (pinned to 7a34a03db6)