tracel-ai/burn · error
Unrecognized image color type
Error message
Unrecognized image color type
What it means
Exhaustiveness guard in `segmentation_mask_to_vec_usize`: only L8, L16, Rgb8, and Rgb16 image color types are converted; any other `image::ColorType` (e.g. RGBA, palette, or alpha-bearing formats) reaching the loader triggers the panic. The failing input is an image file whose color type the image folder dataset does not support for segmentation masks.
Solutions
- Pre-convert mask images to 8-bit grayscale or RGB (no alpha) before placing them in the dataset folder.
- Re-save PNG masks as palette-free `L` or `RGB` mode (e.g. with ImageMagick or PIL) to drop RGBA/palette color types.
- Extend the match to handle additional ColorTypes such as Rgba8/A8 if masks legitimately use alpha channels.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/burn-dataset/src/vision/image_folder.rs:261 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/4c56b8eefc0703be.
Report an issue: GitHub.
Appendix: source
Thrown at crates/burn-dataset/src/vision/image_folder.rs:261
// Image as Vec<PixelDepth>
// if rgb8 or rgb16, keep only the first channel assuming all channels are the same
match image.color() {
ColorType::L8 => image.into_luma8().iter().map(|&x| x as usize).collect(),
ColorType::L16 => image.into_luma16().iter().map(|&x| x as usize).collect(),
ColorType::Rgb8 => image
.into_rgb8()
.iter()
.step_by(3)
.map(|&x| x as usize)
.collect(),
ColorType::Rgb16 => image
.into_rgb16()
.iter()
.step_by(3)
.map(|&x| x as usize)
.collect(),
_ => panic!("Unrecognized image color type"),
}
}
/// Parse the image annotation to the corresponding type.
fn parse_image_annotation(
annotation: &AnnotationRaw,
classes: &HashMap<String, usize>,
) -> Annotation {
// TODO: add support for other annotations
// - [ ] Object bounding boxes
// - [x] Segmentation mask
// For now, only image classification labels and segmentation are supported.
// Map class string to label id
match annotation {
AnnotationRaw::Label(name) => Annotation::Label(*classes.get(name).unwrap()),
AnnotationRaw::MultiLabel(names) => Annotation::MultiLabel(
namesView on GitHub (pinned to d16f7ba2ed)