keras-team/keras · error · ValueError
Invalid value for argument `method`. Expected of one
Error message
Invalid value for argument `method`. Expected of one {SCALE_AND_TRANSLATE_METHODS}. Received: method={method} What it means
Argument validation at the top of `scale_and_translate` (NumPy backend): the resampling `method` is checked against the SCALE_AND_TRANSLATE_METHODS set ('linear', 'bilinear', 'trilinear', 'cubic', 'bicubic', 'tricubic', 'lanczos3', 'lanczos5'). Any other string — wrong casing, a typo, or a method supported only by `resize` — fails the membership test and is rejected with the allowed set listed.
Solutions
- Pass one of the supported method strings exactly as printed (e.g. 'bilinear', 'lanczos3')
- Map resize-style names to their equivalents here ('bicubic' not 'cubic' if 'cubic' is rejected by your version's set)
- Validate against the printed set and fall back to 'bilinear' for unknown user-supplied methods
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/image.py:1189 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/42b9343405592f1c.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/ops/image.py:1189
if need_squeeze:
transformed_images = np.squeeze(transformed_images, axis=0)
transformed_images = transformed_images.astype(input_dtype)
return transformed_images
def scale_and_translate(
images,
output_shape,
scale,
translation,
spatial_dims,
method,
antialias=True,
):
if method not in SCALE_AND_TRANSLATE_METHODS:
raise ValueError(
"Invalid value for argument `method`. Expected of one "
f"{SCALE_AND_TRANSLATE_METHODS}. Received: method={method}"
)
if method in ("linear", "bilinear", "trilinear", "triangle"):
method = "linear"
elif method in ("cubic", "bicubic", "tricubic"):
method = "cubic"
images = convert_to_tensor(images)
scale = convert_to_tensor(scale)
translation = convert_to_tensor(translation)
kernel = _kernels[method]
dtype = backend.result_type(scale.dtype, translation.dtype)
scale = scale.astype(dtype)
translation = translation.astype(dtype)
return _scale_and_translate(
images,
output_shape,View on GitHub (pinned to 7a34a03db6)