keras-team/keras · error · ValueError
Invalid data_format: {data_format}
Error message
Invalid data_format: {data_format} What it means
UpSampling3D._resize_volumes raises when data_format matches neither 'channels_first' nor 'channels_last' after the if/elif chain. Like the 2D case, the public constructor normally validates earlier, so this fires on direct/internal calls with non-standard strings ('NCDHW', typos, None).
Source
Thrown at keras/src/layers/reshaping/up_sampling3d.py:134
height_factor: Positive integer.
width_factor: Positive integer.
data_format: One of `"channels_first"`, `"channels_last"`.
Returns:
Resized tensor.
"""
if data_format == "channels_first":
output = ops.repeat(x, depth_factor, axis=2)
output = ops.repeat(output, height_factor, axis=3)
output = ops.repeat(output, width_factor, axis=4)
return output
elif data_format == "channels_last":
output = ops.repeat(x, depth_factor, axis=1)
output = ops.repeat(output, height_factor, axis=2)
output = ops.repeat(output, width_factor, axis=3)
return output
else:
raise ValueError(f"Invalid data_format: {data_format}")
View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass exactly 'channels_first' or 'channels_last'
- Route custom code through keras.backend.standardize_data_format() before calling the helper, or use the public UpSampling3D layer API
- Set data_format once via keras.config.image_data_format and omit per-layer arguments
Example fix
# before out = up3d._resize_volumes(x, 2, 2, 2, data_format='NCDHW') # after out = up3d._resize_volumes(x, 2, 2, 2, data_format='channels_first')
Defensive patterns
Strategy: validation
Validate before calling
def valid_data_format(df):
return df in {'channels_last', 'channels_first'}
assert valid_data_format(df), f'bad data_format: {df}' Type guard
def is_keras_data_format(v) -> bool:
return v in ('channels_last', 'channels_first') Prevention
- Map PyTorch NCDHW/NDHWC to channels_first/channels_last at the boundary
- Prefer the public UpSampling3D layer over internal helpers
- Run standardize_data_format on any user-supplied format string in custom layers
When it happens
Trigger: Invoking _resize_volumes directly (custom subclass, monkey-patch, or copied helper code) with data_format='NCDHW', 'none', or an unset variable; a wrapper that passes the raw user string down unchecked.
Common situations: Porting PyTorch-style format names (NCDHW/NDHWC) into Keras layer code; custom 3D upsampling wrappers that accept arbitrary strings and forward them unchecked.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid `data_format` argument: {data_format}
- Unknown data_format: {data_format}
- `data_format` should be `"channels_last"` (channel after row
- Unknown activation function '{activation}' cannot be seriali
- Could not interpret activation function identifier: {identif
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/38d1ad697be3d16f.
Report an issue: GitHub.