{"record":{"id":"61bedbd5b5af5093","repo":"huggingface/candle","slug":"either-scales-or-sizes-should-be-present","errorCode":null,"errorMessage":"Either scales or sizes should be present","messagePattern":"Either scales or sizes should be present","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":2337,"sourceCode":"                let output_dims = match (scales, sizes) {\n                    (Some(_), Some(_)) => {\n                        bail!(\"Scales and sizes cannot both be set for Resize operation\")\n                    }\n                    (Some(scales_tensor), None) => {\n                        let scale_values = scales_tensor.to_vec1::<f32>()?;\n                        input\n                            .dims()\n                            .iter()\n                            .enumerate()\n                            .map(|(i, &d)| (d as f32 * scale_values[i]) as usize)\n                            .collect::<Vec<_>>()\n                    }\n                    (None, Some(sizes_tensor)) => sizes_tensor\n                        .to_vec1::<i64>()?\n                        .iter()\n                        .map(|&d| d as usize)\n                        .collect::<Vec<_>>(),\n                    (None, None) => bail!(\"Either scales or sizes should be present\"),\n                };\n\n                let coordinate_transformation_mode =\n                    get_attr_opt::<str>(node, \"coordinate_transformation_mode\")?\n                        .unwrap_or(\"half_pixel\");\n                // Interpolation mode: nearest, linear, or cubic.\n                let mode = get_attr_opt::<str>(node, \"mode\")?.unwrap_or(\"nearest\");\n                // How to determine the \"nearest\" pixel in nearest interpolation mode.\n                let nearest_mode =\n                    get_attr_opt::<str>(node, \"nearest_mode\")?.unwrap_or(\"round_prefer_floor\");\n\n                if mode != \"nearest\" {\n                    bail!(\"Unsupported resize mode: {}\", mode);\n                }\n\n                if nearest_mode != \"floor\" {\n                    bail!(\"Unsupported nearest_mode for resize: {}\", nearest_mode);\n                }","sourceCodeStart":2319,"sourceCodeEnd":2355,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L2319-L2355","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (Resize node inputs: [X, roi, None, None])\n// after: provide scales as initializer\n// scales = Constant tensor [1.0, 1.0, 2.0, 2.0] wired to input index 2","handlingStrategy":"validation","validationCode":"// onnx-rust style pre-check\nlet scales = node_input(&node, 2);\nlet sizes = node_input(&node, 3);\nif scales.is_none() && sizes.is_none() {\n    return Err(\"Resize node must define scales or sizes\");\n}","typeGuard":"fn has_resize_target(node: &Node) -> bool {\n    node.input.len() >= 3 && (node.input[2].is_some() || node.input.get(3).map_or(false, |s| s.is_some()))\n}","tryCatchPattern":"match model.eval(inputs) {\n    Err(e) if e.to_string().contains(\"Either scales or sizes\") => eprintln!(\"Resize node lacks scales/sizes; fix export\"),\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Inspect Resize nodes with netron before deployment","Re-export with a current exporter version","Keep scales or sizes as graph initializers"],"tags":["onnx","resize","missing-input"],"backgroundTag":"missing-required-operator-input","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}