% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dataset-coco.R
\name{coco_segmentation_dataset}
\alias{coco_segmentation_dataset}
\title{COCO Segmentation Dataset}
\usage{
coco_segmentation_dataset(
  root = tempdir(),
  train = TRUE,
  year = c("2017", "2014"),
  download = FALSE,
  transform = NULL,
  target_transform = NULL
)
}
\arguments{
\item{root}{Root directory where the dataset is stored or will be downloaded to.}

\item{train}{Logical. If TRUE, loads the training split; otherwise, loads the validation split.}

\item{year}{Character. Dataset version year. One of \code{"2014"} or \code{"2017"}.}

\item{download}{Logical. If TRUE, downloads the dataset if it's not already present in the \code{root} directory.}

\item{transform}{Optional transform function applied to the image.}

\item{target_transform}{Optional transform function applied to the target.
Use \code{target_transform_coco_masks} to convert polygon annotations to binary masks.}
}
\value{
An object of class \code{coco_segmentation_dataset}. Each item is a list:
\itemize{
\item \code{x}: a \verb{(C, H, W)} array representing the image.
\item \code{y$labels}: an integer \code{torch_tensor} with the class label for each object.
\item \code{y$iscrowd}: a boolean \code{torch_tensor}, where \code{TRUE} marks the object as part of a crowd.
\item \code{y$segmentation}: a list of segmentation polygons for each object.
\item \code{y$masks}: a \verb{(N, H, W)} boolean \code{torch_tensor} containing binary segmentation masks (when using target_transform_coco_masks).
}

The returned object has S3 class \code{"image_with_segmentation_mask"}
to enable automatic dispatch by visualization functions such as \code{draw_segmentation_masks()}.

For object detection tasks without segmentation, use \code{\link{coco_detection_dataset}} instead.
}
\description{
Loads the MS COCO dataset for instance segmentation tasks.
}
\details{
The returned image \code{x} is in CHW format (channels, height, width), matching the torch convention.
The dataset \code{y} offers instance segmentation annotations including labels,
crowd indicators, and segmentation masks from the official COCO annotations.

Files are downloaded to a \code{coco} subdirectory in the torch cache directory for better organization.
}
\examples{
\dontrun{
# Load dataset for instance segmentation
ds <- coco_segmentation_dataset(
  train = FALSE,
  year = "2017",
  download = TRUE,
  target_transform = target_transform_coco_masks
)

item <- ds[1]

# Visualize segmentation masks
masked <- draw_segmentation_masks(item)
tensor_image_browse(masked)
}
}
\seealso{
\code{\link{coco_detection_dataset}} for object detection tasks

Other segmentation_dataset: 
\code{\link{oxfordiiitpet_segmentation_dataset}()},
\code{\link{pascal_voc_datasets}},
\code{\link{rf100_peixos_segmentation_dataset}()}
}
\concept{segmentation_dataset}
