Constructs an FCN (Fully Convolutional Network) model for semantic image segmentation, based on a ResNet backbone as described in Fully Convolutional Networks for Semantic Segmentation.
model_fcn_resnet50(
pretrained = FALSE,
progress = TRUE,
num_classes = 21,
aux_loss = NULL,
pretrained_backbone = TRUE,
...
)
model_fcn_resnet101(
pretrained = FALSE,
progress = TRUE,
num_classes = 21,
aux_loss = NULL,
pretrained_backbone = TRUE,
...
)
(bool): If TRUE, returns a model pre-trained on ImageNet.
(bool): If TRUE, displays a progress bar of the download to stderr.
Number of output classes. Default: 21.
If TRUE, includes the auxiliary classifier. If NULL, defaults to TRUE when pretrained = TRUE
.
If TRUE, uses a backbone pre-trained on ImageNet.
Additional arguments passed to the backbone implementation.
An nn_module
representing the FCN model.
The 21 output classes follow the PASCAL VOC convention:
background
, aeroplane
, bicycle
, bird
, boat
,
bottle
, bus
, car
, cat
, chair
,
cow
, dining table
, dog
, horse
, motorbike
,
person
, potted plant
, sheep
, sofa
, train
,
tv/monitor
.
Pretrained weights require num_classes = 21
.
Other semantic_segmentation_model:
model_deeplabv3
if (FALSE) { # \dontrun{
library(magrittr)
norm_mean <- c(0.485, 0.456, 0.406) # ImageNet normalization constants, see
# https://pytorch.org/vision/stable/models.html
norm_std <- c(0.229, 0.224, 0.225)
img_url <- "https://en.wikipedia.org/wiki/Special:FilePath/Felis_catus-cat_on_snow.jpg"
img <- base_loader(img_url)
input <- img %>%
transform_to_tensor() %>%
transform_resize(c(520, 520)) %>%
transform_normalize(norm_mean, norm_std)
batch <- input$unsqueeze(1)
model <- model_fcn_resnet50(pretrained = TRUE)
model$eval()
output <- model(batch)
# visualize the result
# `draw_segmentation_masks()` turns the torch_float output into a boolean mask internaly:
segmented <- draw_segmentation_masks(input, output$out$squeeze(1))
tensor_image_display(segmented)
model <- model_fcn_resnet101(pretrained = TRUE)
model$eval()
output <- model(batch)
# visualize the result
segmented <- draw_segmentation_masks(input, output$out$squeeze(1))
tensor_image_display(segmented)
} # }