Skip to content

Segmentation Dataset alignment against draw_segmentation_mask() #176

@cregouby

Description

@cregouby

Current Situation

Current and future segmentation datasets

  • coco_segmentation_dataset
  • oxfordiiitpet_segmentation_dataset
  • ...
    have default segmentation annotations file content that are not ready for draw_segmentation_mask() function.

In order to ease usage of draw_segmentation_mask, we currently apply a specific hidden target_transform within each dataset function :

masks <- lapply(seq_len(nrow(anns)), function(i) {
seg <- anns$segmentation[[i]]
if (is.list(seg) && length(seg) > 0) {
mask <- coco_polygon_to_mask(seg, height = H, width = W)
if (inherits(mask, "torch_tensor") && mask$ndim == 2) return(mask)
}
NULL
})
masks <- Filter(function(m) inherits(m, "torch_tensor") && m$ndim == 2, masks)
if (length(masks) > 0) {
masks_tensor <- torch::torch_stack(masks)
} else {
masks_tensor <- torch::torch_zeros(c(0, H, W), dtype = torch::torch_bool())
}

masks <- png::readPNG(mask_path) * 255
masks <- torch_tensor(masks)
mask1 <- (masks==1)
mask2 <- (masks==2)
mask3 <- (masks==3)
masks <- torch_stack(list(mask1, mask2, mask3))$to(dtype = torch_bool())

Design driver

  • try to adhere to (py) torchvision guidelines "Torchvision datasets preserve the data structure and types as it was intended by the datasets authors. So by default, the output structure may not always be compatible with the models or the transforms."
  • clean and easy-to-understand workflow for the end-user to load the dataset and draw a segmented image and to infer with a asegmentation model and draw the result.
  • not having to perform hidden complex target-transformation of raw annotation into the image_with_segmentation_mask data format

Expected situation

  • add two target transform functions :

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions