huggingface/candle · error
Either scales or sizes should be present
Error message
Either scales or sizes should be present
What it means
The ONNX Resize operator requires either a `scales` input (float multipliers per dimension) or a `sizes` input (target dimensions). The candle-onnx evaluator found neither, so it cannot compute the output shape of the resize and aborts with this message. This mirrors the ONNX spec constraint that one of the two optional inputs must be present.
Source
Thrown at candle-onnx/src/eval.rs:2337
let output_dims = match (scales, sizes) {
(Some(_), Some(_)) => {
bail!("Scales and sizes cannot both be set for Resize operation")
}
(Some(scales_tensor), None) => {
let scale_values = scales_tensor.to_vec1::<f32>()?;
input
.dims()
.iter()
.enumerate()
.map(|(i, &d)| (d as f32 * scale_values[i]) as usize)
.collect::<Vec<_>>()
}
(None, Some(sizes_tensor)) => sizes_tensor
.to_vec1::<i64>()?
.iter()
.map(|&d| d as usize)
.collect::<Vec<_>>(),
(None, None) => bail!("Either scales or sizes should be present"),
};
let coordinate_transformation_mode =
get_attr_opt::<str>(node, "coordinate_transformation_mode")?
.unwrap_or("half_pixel");
// Interpolation mode: nearest, linear, or cubic.
let mode = get_attr_opt::<str>(node, "mode")?.unwrap_or("nearest");
// How to determine the "nearest" pixel in nearest interpolation mode.
let nearest_mode =
get_attr_opt::<str>(node, "nearest_mode")?.unwrap_or("round_prefer_floor");
if mode != "nearest" {
bail!("Unsupported resize mode: {}", mode);
}
if nearest_mode != "floor" {
bail!("Unsupported nearest_mode for resize: {}", nearest_mode);
}View on GitHub (pinned to d5fee525bf)
Solutions
- Re-export the model ensuring the Resize node has either `scales` or `sizes` wired as an input or initializer
- Inspect the ONNX graph (netron or onnx.helper) and patch the Resize node to supply a scales/sizes tensor
- Bump the opset/exporter version so resize attributes are serialized correctly
Example fix
// before (Resize node inputs: [X, roi, None, None]) // after: provide scales as initializer // scales = Constant tensor [1.0, 1.0, 2.0, 2.0] wired to input index 2
Defensive patterns
Strategy: validation
Validate before calling
// onnx-rust style pre-check
let scales = node_input(&node, 2);
let sizes = node_input(&node, 3);
if scales.is_none() && sizes.is_none() {
return Err("Resize node must define scales or sizes");
} Type guard
fn has_resize_target(node: &Node) -> bool {
node.input.len() >= 3 && (node.input[2].is_some() || node.input.get(3).map_or(false, |s| s.is_some()))
} Try / catch
match model.eval(inputs) {
Err(e) if e.to_string().contains("Either scales or sizes") => eprintln!("Resize node lacks scales/sizes; fix export"),
Err(e) => return Err(e),
Ok(v) => Ok(v),
} Prevention
- Inspect Resize nodes with netron before deployment
- Re-export with a current exporter version
- Keep scales or sizes as graph initializers
When it happens
Trigger: Evaluating a model whose Resize node has both the `scales` input (input 2) and the `sizes` input (input 3) set to None/missing, e.g. a model exported without resize scale information or with both inputs pruned.
Common situations: Exporting models from PyTorch/TensorFlow where the resize was traced with dynamic parameters and the exporter dropped both optional inputs; hand-edited ONNX graphs; older exporters that emitted empty initializer references for Resize.
Related errors
- Unsupported resize mode: {}
- Unsupported nearest_mode for resize: {}
- Unsupported coordinate_transformation_mode for resize: {}
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR was an invalid data_type number
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/61bedbd5b5af5093.
Report an issue: GitHub.