Mask tracking
Step-by-step tutorial on how to integrate custom video object segmentation neural network into Supervisely platform on the example of XMem.
Introduction
Implementation details
Overall structure
import supervisely as sly
import torch
import numpy as np
class MyModel(sly.nn.inference.MaskTracking):
def load_on_device(
self,
model_dir: str,
device: Literal["cpu", "cuda", "cuda:0", "cuda:1", "cuda:2", "cuda:3"] = "cpu",
):
# initialize model, load weights, load model on device
pass
def predict(
self,
frames: List[np.ndarray],
input_mask: np.ndarray,
) -> List[np.ndarray]:
# a simple code example
# disable gradient calculation
torch.set_grad_enabled(False)
results = []
# pass input mask to your model, run it on given list of frames (frame-by-frame)
for frame in frames:
prediction = self.model(input_mask, frame)
# save predictions to a list
results.append(prediction)
# update progress bar on each iteration
self.video_interface._notify(task="mask tracking")
return resultsXMem video object segmentation model
Getting started
Step-by-step implementation
Debug in Supervisely platform

Release your code as a Supervisely App
Repository structure
App configuration
App release
Last updated