SAVRN
Search Contact SAVRN

Open-weight model · Image segmentation

modnet

by Joshua Xenova/modnet

For more information, check out the official repository and example colab. If you haven't already, you can install the Transformers.js JavaScript library from NPM using: You can then use the model for portrait matting, as follows: Or with the AutoModel and…

Parameters
Context
Weights110.1 MB
Licenseapache-2.0
AccessOpen weights
Monthly Downloads104.3k

Model Card

By Joshua, published under apache-2.0, revision fa2fa546052f.

For more information, check out the official repository and example colab. If you haven't already, you can install the Transformers.js JavaScript library from NPM using: You can then use the model for portrait matting, as follows: Or with the AutoModel and AutoProcessor APIs: Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).

Read Joshua's full model card

MODNet: Trimap-Free Portrait Matting in Real Time

For more information, check out the official repository and example colab.

Usage (Transformers.js)

If you haven't already, you can install the Transformers.js JavaScript library from NPM using:

npm i @huggingface/transformers

You can then use the model for portrait matting, as follows:

import { pipeline } from '@huggingface/transformers';

const segmenter = await pipeline('background-removal', 'Xenova/modnet', { dtype: 'fp32' });
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const output = await segmenter(url);
output[0].save('mask.png');
// You can also use `output[0].toCanvas()` or `await output[0].toBlob()` if you would like to access the output without saving.

Or with the AutoModel and AutoProcessor APIs:

import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';

// Load model and processor
const model = await AutoModel.from_pretrained('Xenova/modnet', { dtype: 'fp32' });
const processor = await AutoProcessor.from_pretrained('Xenova/modnet');

// Load image from URL
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const image = await RawImage.fromURL(url);

// Pre-process image
const { pixel_values } = await processor(image);

// Predict alpha matte
const { output } = await model({ input: pixel_values });

// Save output mask
const mask = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
mask.save('mask.png');
Input image Output mask

Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).

Configuration

Model type
modnet

Identity and Version

Repository
Xenova/modnet
Publisher
Joshua
Task
Image segmentation
Modality
Image
Library
transformers.js
Parameters
Not stated by the source
Languages
Not stated by the source
Revision
fa2fa546052fba4c08921230a26cc69a333fca12
First published
2024-02-05
Last updated
2025-10-26

Files and Weights

12 files, 110.2 MB in total. The weights are 7 files totalling 110.1 MB in onnx.

Weights7 files · 110.1 MB
Configuration3 files · 1.2 KB
Documentation1 file · 2.8 KB
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
onnx/model.onnxWeights25.9 MB 07c308cf0fc7
onnx/model_bnb4.onnxWeights23.1 MB acfa94a3b902
onnx/model_fp16.onnxWeights13.0 MB 25f165da9bfd
onnx/model_q4.onnxWeights23.1 MB 74b7b569f869
onnx/model_q4f16.onnxWeights11.8 MB f582407530e8
onnx/model_quantized.onnxWeights6.6 MB 92e49898c3e0
onnx/model_uint8.onnxWeights6.6 MB 7bad6522b3cd
config.jsonConfiguration83 B
preprocessor_config.jsonConfiguration365 B
quantize_config.jsonConfiguration718 B
README.mdDocumentation2.8 KB
.gitattributesRepository1.5 KB

License and Download

License
apache-2.0
Access
Open weights, no gate
Download size
110.1 MB
Download from Joshua

Released by Joshua through its official repository on Hugging Face. Read the license.

Memory Requirements

PrecisionWeights in memory
As published110.1 MB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About modnet

Can I use modnet commercially?

Yes. modnet is released under Apache License 2.0. The Apache License 2.0 is a permissive open-source license. It permits commercial use, modification and redistribution. It requires keeping the license and copyright notices and any NOTICE file, stating significant changes, and it includes an express patent grant from contributors.

Similar Models

Model · Image segmentation

segformer-b2-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

segformer-b3-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

oneformer_ade20k_swin_large

SHI Labs

OneFormer model trained on the ADE20k dataset (large-sized version, Swin backbone). It was introduced in the paper OneFormer: One Transformer to Rule Universal Image Segmentation by Jain et al. and first released in this repository. OneFormer is the first multi-task universal image segmentation framework. It needs to be trained only once with a single universal architecture, a single model, and on a single dataset, to outperform existing specialized models across semantic, instance, and panoptic segmentation tasks. OneFormer uses a task token to condition the model on the task in focus, making the architecture task-guided for training, and task-dynamic for inference, all with a single…

Open weights mit transformers

Model · Image segmentation

segformer-b1-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

segformer-b0-finetuned-ade-512-512

Joshua

https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512 with ONNX weights to be compatible with Transformers.js. If you haven't already, you can install the Transformers.js JavaScript library from NPM using: Example: Image segmentation with Xenova/segformer-b0-finetuned-ade-512-512. You can visualize the outputs with: Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).

Open weights transformers.js

Model · Image segmentation

DelineateAnything

Mykola Lavreniuk

Delineate Anything v2 extends Delineate Anything into a globally representative, resolution-agnostic foundation model that scales agricultural field boundary detection to a planetary level from any imagery source. Trained on FBIS-73M, a massive 73-million-instance dataset spanning 61 countries with diverse imagery sources ranging from 0.25m to 10m resolution, built through a resolution-specific curation pipeline that solves the parcel-versus-field mismatch, Delineate Anything v2 sets a new state-of-the-art in global zero-shot delineation. It delivers a +103.3% relative gain in [email protected] over Delineate Anything while maintaining extreme efficiency, mapping all of Ukraine (603,000 km²) in 5.4…

Open weights agpl-3.0 ultralytics