Additional Operators for Image Models

Implements additional operators for computer vision models, including operators necessary for image segmentation and object detection deep learning models.


torchvisionlib

Lifecycle:experimental R-CMD-check CRANstatus Discord

The goal of torchvisionlib is to provide access to C++ operations implemented in torchvision. It provides plain R acesss to some of those C++ operations but, most importantly it provides full support for JIT operators defined in torchvision, allowing us to load ‘scripted’ object detection and image segmentation models.

Installation

torchvisionlib can be installed from CRAN with:

install.packages("torchvisionlib")

You can also install the development version of torchvisionlib from GitHub with:

# install.packages("devtools")
devtools::install_github("mlverse/torchvisionlib")

Example

Suppose that we want to load an image detection model implemented in torchvision. First, in Python, we can save JIT script and then save this model:

import torch
import torchvision

model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_320_fpn(pretrained=True)
model.eval()

jit_model = torch.jit.script(model)
torch.jit.save(jit_model, "fasterrcnn_mobilenet_v3_large_320_fpn.pt")

We can then load this model in R. Simply loading torchvisionlib will register all JIT operators, and we can use torch::jit_load().

library(torchvisionlib)
model <- torch::jit_load("fasterrcnn_mobilenet_v3_large_320_fpn.pt")
model
#> An `nn_module` containing 19,386,354 parameters.
#> 
#> ── Modules ─────────────────────────────────────────────────────────────────────
#> • transform: <script_module> #0 parameters
#> • backbone: <script_module> #4,414,944 parameters
#> • rpn: <script_module> #609,355 parameters
#> • roi_heads: <script_module> #14,362,055 parameters

You can then use this model to make preditions or even fine tuning.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("torchvisionlib")

0.8.0 by Tomasz Kalinowski, 6 months ago


https://github.com/mlverse/torchvisionlib


Report a bug at https://github.com/mlverse/torchvisionlib/issues


Browse source code at https://github.com/cran/torchvisionlib


Authors: Daniel Falbel [aut] , Tomasz Kalinowski [ctb, cre] , RStudio [cph]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports Rcpp, torch, rlang, glue, withr

Suggests testthat

Linking to Rcpp, torch


Suggested by torchvision.


See at CRAN