% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/models-mask_rcnn.R
\name{model_maskrcnn}
\alias{model_maskrcnn}
\alias{model_maskrcnn_resnet50_fpn}
\alias{model_maskrcnn_resnet50_fpn_v2}
\title{Mask R-CNN Models}
\usage{
model_maskrcnn_resnet50_fpn(
  pretrained = FALSE,
  progress = TRUE,
  num_classes = 90,
  score_thresh = 0.05,
  nms_thresh = 0.5,
  detections_per_img = 100,
  ...
)

model_maskrcnn_resnet50_fpn_v2(
  pretrained = FALSE,
  progress = TRUE,
  num_classes = 90,
  score_thresh = 0.05,
  nms_thresh = 0.5,
  detections_per_img = 100,
  ...
)
}
\arguments{
\item{pretrained}{Logical. If TRUE, loads pretrained weights from local file.}

\item{progress}{Logical. Show progress bar during download (unused).}

\item{num_classes}{Number of output classes excluding background (default: 90 for COCO).}

\item{score_thresh}{Numeric. Minimum score threshold for detections (default: 0.05).}

\item{nms_thresh}{Numeric. Non-Maximum Suppression (NMS) IoU threshold for removing overlapping boxes (default: 0.5).}

\item{detections_per_img}{Integer. Maximum number of detections per image (default: 100).}

\item{...}{Other arguments (unused).}
}
\value{
A \code{maskrcnn_model} nn_module.
}
\description{
Construct Mask R-CNN model variants for instance segmentation task.
Mask R-CNN extends Faster R-CNN by adding a mask prediction branch that
outputs segmentation masks for each detected object.
}
\section{Functions}{
\itemize{
\item \code{model_maskrcnn_resnet50_fpn()}: Mask R-CNN with ResNet-50 FPN

\item \code{model_maskrcnn_resnet50_fpn_v2()}: Mask R-CNN with ResNet-50 FPN V2

}}
\section{Task}{

Instance segmentation over images with bounding boxes, class labels, and segmentation masks.
}

\section{Input Format}{

Input images should be \code{torch_tensor}s of shape
\verb{(batch_size, 3, H, W)} where \code{H} and \code{W} are typically around 800.
}

\section{Output Format}{

Returns a list with:
\itemize{
\item \code{features}: Feature maps from the backbone
\item \code{detections}: List containing:
\itemize{
\item \code{boxes}: Bounding boxes (N, 4)
\item \code{labels}: Class labels (N)
\item \code{scores}: Confidence scores (N)
\item \code{masks}: Segmentation masks (N, 28, 28)
}
}
}

\section{Available Models}{

\itemize{
\item \code{model_maskrcnn_resnet50_fpn()}
\item \code{model_maskrcnn_resnet50_fpn_v2()}
}
}

\examples{
\dontrun{
library(magrittr)
# ImageNet normalization constants, see https://pytorch.org/vision/stable/models.html
norm_mean <- c(0.485, 0.456, 0.406)
norm_std  <- c(0.229, 0.224, 0.225)

# Load an image
url <- paste0("https://upload.wikimedia.org/wikipedia/commons/thumb/",
              "e/ea/Morsan_Normande_vache.jpg/120px-Morsan_Normande_vache.jpg")
img <- base_loader(url)

input <- img \%>\%
  transform_to_tensor() \%>\%
  transform_resize(c(800, 800)) \%>\%
  transform_normalize(norm_mean, norm_std)
batch <- input$unsqueeze(1)

# Mask R-CNN ResNet-50 FPN
model <- model_maskrcnn_resnet50_fpn(pretrained = TRUE, , detections_per_img = 5)
model$eval()

torch::with_no_grad({pred <- model(batch)$detections[[1]]})

# Visualize boxes
labels <- coco_classes(as.integer(pred$labels))
boxed <- draw_bounding_boxes(image, pred$boxes, labels = labels)
tensor_image_browse(boxed)
}

}
\seealso{
Other object_detection_model: 
\code{\link{model_convnext_detection}},
\code{\link{model_facenet}},
\code{\link{model_fasterrcnn}}
}
\concept{object_detection_model}
