tracel-ai / burn

Burn is a new comprehensive dynamic Deep Learning Framework built using Rust with extreme flexibility, compute efficiency and portability as its primary goals.
https://burn.dev
Apache License 2.0
8.73k stars 430 forks source link

Implement SegmentationMask in image_folder.rs (dataset::vision) #2361

Open anthonytorlucci opened 1 week ago

anthonytorlucci commented 1 week ago

No open issues related to SegmentationMask.

Feature description

Complete the implementation of SegmentationMask in image_folder.rs.

Feature motivation

I'm currently working on a semantic segmentation example (simply UNet) and feel that implementing this feature will be a better solution than writing a new custom dataset.

(Optional) Suggest a Solution

It appears to have been started or bookmarked for future work.

/// Annotation type for different tasks.
#[derive(Debug, Clone, PartialEq)]
pub enum Annotation {
    /// Image-level label.
    Label(usize),
    /// Multiple image-level labels.
    MultiLabel(Vec<usize>),
    /// Object bounding boxes.
    BoundingBoxes(Vec<BoundingBox>),
    /// Segmentation mask.
    SegmentationMask(SegmentationMask),
}

Needed to complete:

/// Raw annotation types.
#[derive(Deserialize, Serialize, Debug, Clone)]
enum AnnotationRaw {
    Label(String),
    MultiLabel(Vec<String>),
    // TODO: bounding boxes and segmentation mask
}
/// 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
    // - [ ] Segmentation mask
    // For now, only image classification labels are supported.

    // Map class string to label id
    match annotation {
        AnnotationRaw::Label(name) => Annotation::Label(*classes.get(name).unwrap()),
        AnnotationRaw::MultiLabel(names) => Annotation::MultiLabel(
            names
                .iter()
                .map(|name| *classes.get(name).unwrap())
                .collect(),
        ),
    }
}

Need to test Mapper and Loader. Additional code may be needed as well.

csking101 commented 6 hours ago

Hi, I am new to open source, could you suggest how to proceed further?

anthonytorlucci commented 2 hours ago

@csking101 , I've just about completed the task and plan to submit a pull request in the next few days. To learn more about open source contributing, you could watch this ticket and follow the pull request (once requested). I'm sure the maintainers will have comments; then watch how the iterative process continues and ultimately leads to either good code being added to the project or a failure to meet expectations. Either way, it will be a learning experience. Thank you for joining the conversation and stay tuned!

csking101 commented 1 hour ago

@anthonytorlucci , thanks for the reply! I will be following how this issue and subsequent PR pans out. Thanks!