{"record":{"id":"2dd89cdb3602ad62","repo":"tracel-ai/burn","slug":"more-than-3-channels-not-supported-channels","errorCode":null,"errorMessage":"More than 3 channels not supported ({channels})","messagePattern":"More than 3 channels not supported \\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-vision/src/utils/save.rs","lineNumber":158,"sourceCode":"                let mut pixel = [0 as f32; 3];\n                match opts.color_opts {\n                    ColorDisplayOpts::Rgb => match channels {\n                        1 => {\n                            pixel[0] = channel_vals[0];\n                            pixel[1] = 0.0;\n                            pixel[2] = 0.0;\n                        }\n                        2 => {\n                            pixel[0] = channel_vals[0];\n                            pixel[1] = channel_vals[1];\n                            pixel[2] = 0.0;\n                        }\n                        3 => {\n                            pixel[0] = channel_vals[0];\n                            pixel[1] = channel_vals[1];\n                            pixel[2] = channel_vals[2];\n                        }\n                        _ => unimplemented!(\"More than 3 channels not supported ({channels})\"),\n                    },\n                    ColorDisplayOpts::Monochrome { min, max } => {\n                        let val: f32 = channel_vals.iter().sum();\n                        pixel[0] = min[0] * (1.0 - val) + max[0] * val;\n                        pixel[1] = min[1] * (1.0 - val) + max[1] * val;\n                        pixel[2] = min[2] * (1.0 - val) + max[2] * val;\n                    }\n                }\n\n                let pixel = [\n                    (pixel[0] * 255.0) as u8,\n                    (pixel[1] * 255.0) as u8,\n                    (pixel[2] * 255.0) as u8,\n                ];\n                img.put_pixel(x, y, Rgb(pixel));\n            }\n        }\n    }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-vision/src/utils/save.rs#L140-L176","documentation":"save_tensor_as_image can only map tensor channels to RGB pixels for 1-, 2-, or 3-channel images (1 = monochrome/scalar mapping, 3 = direct RGB). Any channel count greater than 3 hits the catch-all arm and aborts with unimplemented!, since the image buffer only has 3 pixel components to fill.","triggerScenarios":"Calling `save_tensor_as_image` on a tensor with C > 3 in its channel dimension, e.g. [H, W, 4] RGBA tensors, [B, H, W, C] batches with C > 3, or feature-map tensors with many channels, saved with ColorDisplayOpts::Rgb.","commonSituations":"Trying to visualize intermediate conv feature maps (16/64/512 channels) as images; saving RGBA (4-channel) tensors; forgetting to slice/select channels before saving debug visualizations.","solutions":["Slice the tensor to at most 3 channels before saving, e.g. `tensor.slice(s![.., .., 0..3])` or select the 3 channels you want as RGB.","Reduce multi-channel data yourself (mean/max over channels) to a 1-channel tensor and save with ColorDisplayOpts::Monochrome.","Save each channel as a separate monochrome image if all channels are needed."],"exampleFix":"// before\nsave_tensor_as_image(&feature_map, \"out.png\", ColorDisplayOpts::Rgb)?; // 64 channels: panics\n// after\nlet rgb = feature_map.clone().slice(2..2, 0..3); // keep first 3 channels\nsave_tensor_as_image(&rgb, \"out.png\", ColorDisplayOpts::Rgb)?;","handlingStrategy":"validation","validationCode":"let channels = tensor.dims()[tensor.dims().len() - 1];\nif channels > 3 {\n    tensor = tensor.slice(2..2, 0..3); // or reduce channels before saving\n}\nsave_tensor_as_image(&tensor, \"out.png\", opts)?;","typeGuard":"fn is_saveable(channels: usize) -> bool {\n    matches!(channels, 1..=3)\n}","tryCatchPattern":null,"preventionTips":["Check the last (channel) dimension of the tensor is 1-3 before saving.","For feature maps, aggregate channels (mean/max) or slice 0..3 before visualizing.","Never pass raw conv feature maps with C > 3 to save_tensor_as_image."],"tags":["rust","burn","image-saving","unimplemented"],"backgroundTag":"unsupported-channel-count","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}