R/dataset-oxfordiiitpet.R
oxfordiiitpet_segmentation_dataset.Rd
The Oxford-IIIT Pet Dataset is a segmentation dataset consisting of color images of 37 pet breeds (cats and dogs). Each image is annotated with a pixel-level trimap segmentation mask, identifying pet, background, and outline regions. It is commonly used for evaluating models on object segmentation tasks.
oxfordiiitpet_segmentation_dataset(
root = tempdir(),
train = TRUE,
target_type = "category",
transform = NULL,
target_transform = NULL,
download = FALSE
)
Character. Root directory where the dataset is stored or will be downloaded to. Files are placed under root/oxfordiiitpet
.
Logical. If TRUE, use the training set; otherwise, use the test set. Not applicable to all datasets.
Character. One of "category"
or "binary-category"
(default: "category"
).
Optional. A function that takes an image and returns a transformed version (e.g., normalization, cropping).
Optional. A function that transforms the label.
Logical. If TRUE, downloads the dataset to root/
. If the dataset is already present, download is skipped.
A torch dataset object oxfordiiitpet_dataset
. Each item is a named list:
x
: a H x W x 3 integer array representing an RGB image.
y$masks
: a boolean tensor of shape (3, H, W), representing the segmentation trimap as one-hot masks.
y$label
: an integer representing the class label, depending on the target_type
:
"category"
: an integer in 1–37 indicating the pet breed.
"binary-category"
: 1 for Cat, 2 for Dog.
if (FALSE) { # \dontrun{
# Load the Oxford-IIIT Pet dataset with basic tensor transform
oxfordiiitpet <- oxfordiiitpet_segmentation_dataset(
transform = transform_to_tensor,
download = TRUE
)
# Retrieve the image tensor, segmentation mask and label
first_item <- oxfordiiitpet[1]
first_item$x # RGB image tensor of shape (3, H, W)
first_item$y$masks # (3, H, W) bool tensor: pet, background, outline
first_item$y$label # Integer label (1–37 or 1–2 depending on target_type)
oxfordiiitpet$classes[first_item$y$label] # Class name of the label
# Visualize
overlay <- draw_segmentation_masks(first_item)
tensor_image_browse(overlay)
} # }