oxfordiiitpet_segmentation_dataset | R Documentation |
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
)
root |
Character. Root directory where the dataset is stored or will be downloaded to. Files are placed under |
train |
Logical. If TRUE, use the training set; otherwise, use the test set. Not applicable to all datasets. |
target_type |
Character. One of |
transform |
Optional. A function that takes an image and returns a transformed version (e.g., normalization, cropping). |
target_transform |
Optional. A function that transforms the label. |
download |
Logical. If TRUE, downloads the dataset to |
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.
## Not run:
# 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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.