nvidia/MambaVision-L3-512-21K

Model

Model Overview

56

12 commits

1 linked in READMEs

updated Mar 29, 2025

See the code

README

MambaVision: A Hybrid Mamba-Transformer Vision Backbone.

Project page

Model Overview

We have developed the first hybrid model for computer vision which leverages the strengths of Mamba and Transformers. Specifically, our core contribution includes redesigning the Mamba formulation to enhance its capability for efficient modeling of visual features. In addition, we conducted a comprehensive ablation study on the feasibility of integrating Vision Transformers (ViT) with Mamba. Our results demonstrate that equipping the Mamba architecture with several self-attention blocks at the final layers greatly improves the modeling capacity to capture long-range spatial dependencies. Based on our findings, we introduce a family of MambaVision models with a hierarchical architecture to meet various design criteria.

Model Performance

MambaVision-L3-512-21K is pretrained on ImageNet-21K dataset and finetuned on ImageNet-1K at 512 x 512 resolution.

NameAcc@1(%)Acc@5(%)#Params(M)FLOPs(G)Resolution
MambaVision-L3-512-21K88.198.6739.6489.1512x512

In addition, the MambaVision models demonstrate a strong performance by achieving a new SOTA Pareto-front in terms of Top-1 accuracy and throughput.

Model Usage

It is highly recommended to install the requirements for MambaVision by running the following:

pip install mambavision

For each model, we offer two variants for image classification and feature extraction that can be imported with 1 line of code.

Image Classification

In the following example, we demonstrate how MambaVision can be used for image classification.

Given the following image from COCO dataset val set as an input:

The following snippet can be used for image classification:

from transformers import AutoModelForImageClassification
from PIL import Image
from timm.data.transforms_factory import create_transform
import requests

model = AutoModelForImageClassification.from_pretrained("nvidia/MambaVision-L3-512-21K", trust_remote_code=True)

# eval mode for inference
model.cuda().eval()

# prepare image for the model
url = 'http://images.cocodataset.org/val2017/000000020247.jpg'
image = Image.open(requests.get(url, stream=True).raw)
input_resolution = (3, 512, 512)  # MambaVision supports any input resolutions

transform = create_transform(input_size=input_resolution,
                             is_training=False,
                             mean=model.config.mean,
                             std=model.config.std,
                             crop_mode=model.config.crop_mode,
                             crop_pct=model.config.crop_pct)

inputs = transform(image).unsqueeze(0).cuda()
# model inference
outputs = model(inputs)
logits = outputs['logits'] 
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])

The predicted label is brown bear, bruin, Ursus arctos.

Feature Extraction

MambaVision can also be used as a generic feature extractor.

Specifically, we can extract the outputs of each stage of model (4 stages) as well as the final averaged-pool features that are flattened.

The following snippet can be used for feature extraction:

from transformers import AutoModel
from PIL import Image
from timm.data.transforms_factory import create_transform
import requests

model = AutoModel.from_pretrained("nvidia/MambaVision-L3-512-21K", trust_remote_code=True)

# eval mode for inference
model.cuda().eval()

# prepare image for the model
url = 'http://images.cocodataset.org/val2017/000000020247.jpg'
image = Image.open(requests.get(url, stream=True).raw)
input_resolution = (3, 512, 512)  # MambaVision supports any input resolutions

transform = create_transform(input_size=input_resolution,
                             is_training=False,
                             mean=model.config.mean,
                             std=model.config.std,
                             crop_mode=model.config.crop_mode,
                             crop_pct=model.config.crop_pct)
inputs = transform(image).unsqueeze(0).cuda()
# model inference
out_avg_pool, features = model(inputs)
print("Size of the averaged pool features:", out_avg_pool.size())  # torch.Size([1, 1568])
print("Number of stages in extracted features:", len(features)) # 4 stages
print("Size of extracted features in stage 1:", features[0].size()) # torch.Size([1, 196, 128, 128])
print("Size of extracted features in stage 4:", features[3].size()) # torch.Size([1, 1568, 16, 16])

License:

NVIDIA Source Code License-NC

Results + Pretrained Models

ImageNet-21K

NameAcc@1(%)Acc@5(%)#Params(M)FLOPs(G)ResolutionHFDownload
MambaVision-B-21K84.997.597.715.0224x224linkmodel
MambaVision-L-21K86.197.9227.934.9224x224linkmodel
MambaVision-L2-512-21K87.398.4241.5196.3512x512linkmodel
MambaVision-L3-256-21K87.398.3739.6122.3256x256linkmodel
MambaVision-L3-512-21K88.198.6739.6489.1512x512linkmodel

ImageNet-1K

NameAcc@1(%)Acc@5(%)Throughput(Img/Sec)Resolution#Params(M)FLOPs(G)HFDownload
MambaVision-T82.396.26298224x22431.84.4linkmodel
MambaVision-T282.796.35990224x22435.15.1linkmodel
MambaVision-S83.396.54700224x22450.17.5linkmodel
MambaVision-B84.296.93670224x22497.715.0linkmodel
MambaVision-L85.097.12190224x224227.934.9linkmodel
MambaVision-L285.397.21021224x224241.537.5linkmodel

Installation

We provide a docker file. In addition, assuming that a recent PyTorch package is installed, the dependencies can be installed by running:

pip install -r requirements.txt
custom_code
image-classification
mambavision
safetensors
transformers

nvidia/MambaVision-L3-512-21K

Model

Model Overview

56

12 commits

1 linked in READMEs

updated Mar 29, 2025

See the code

README

MambaVision: A Hybrid Mamba-Transformer Vision Backbone.

Project page

Model Overview

We have developed the first hybrid model for computer vision which leverages the strengths of Mamba and Transformers. Specifically, our core contribution includes redesigning the Mamba formulation to enhance its capability for efficient modeling of visual features. In addition, we conducted a comprehensive ablation study on the feasibility of integrating Vision Transformers (ViT) with Mamba. Our results demonstrate that equipping the Mamba architecture with several self-attention blocks at the final layers greatly improves the modeling capacity to capture long-range spatial dependencies. Based on our findings, we introduce a family of MambaVision models with a hierarchical architecture to meet various design criteria.

Model Performance

MambaVision-L3-512-21K is pretrained on ImageNet-21K dataset and finetuned on ImageNet-1K at 512 x 512 resolution.

NameAcc@1(%)Acc@5(%)#Params(M)FLOPs(G)Resolution
MambaVision-L3-512-21K88.198.6739.6489.1512x512

In addition, the MambaVision models demonstrate a strong performance by achieving a new SOTA Pareto-front in terms of Top-1 accuracy and throughput.

Model Usage

It is highly recommended to install the requirements for MambaVision by running the following:

pip install mambavision

For each model, we offer two variants for image classification and feature extraction that can be imported with 1 line of code.

Image Classification

In the following example, we demonstrate how MambaVision can be used for image classification.

Given the following image from COCO dataset val set as an input:

The following snippet can be used for image classification:

from transformers import AutoModelForImageClassification
from PIL import Image
from timm.data.transforms_factory import create_transform
import requests

model = AutoModelForImageClassification.from_pretrained("nvidia/MambaVision-L3-512-21K", trust_remote_code=True)

# eval mode for inference
model.cuda().eval()

# prepare image for the model
url = 'http://images.cocodataset.org/val2017/000000020247.jpg'
image = Image.open(requests.get(url, stream=True).raw)
input_resolution = (3, 512, 512)  # MambaVision supports any input resolutions

transform = create_transform(input_size=input_resolution,
                             is_training=False,
                             mean=model.config.mean,
                             std=model.config.std,
                             crop_mode=model.config.crop_mode,
                             crop_pct=model.config.crop_pct)

inputs = transform(image).unsqueeze(0).cuda()
# model inference
outputs = model(inputs)
logits = outputs['logits'] 
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])

The predicted label is brown bear, bruin, Ursus arctos.

Feature Extraction

MambaVision can also be used as a generic feature extractor.

Specifically, we can extract the outputs of each stage of model (4 stages) as well as the final averaged-pool features that are flattened.

The following snippet can be used for feature extraction:

from transformers import AutoModel
from PIL import Image
from timm.data.transforms_factory import create_transform
import requests

model = AutoModel.from_pretrained("nvidia/MambaVision-L3-512-21K", trust_remote_code=True)

# eval mode for inference
model.cuda().eval()

# prepare image for the model
url = 'http://images.cocodataset.org/val2017/000000020247.jpg'
image = Image.open(requests.get(url, stream=True).raw)
input_resolution = (3, 512, 512)  # MambaVision supports any input resolutions

transform = create_transform(input_size=input_resolution,
                             is_training=False,
                             mean=model.config.mean,
                             std=model.config.std,
                             crop_mode=model.config.crop_mode,
                             crop_pct=model.config.crop_pct)
inputs = transform(image).unsqueeze(0).cuda()
# model inference
out_avg_pool, features = model(inputs)
print("Size of the averaged pool features:", out_avg_pool.size())  # torch.Size([1, 1568])
print("Number of stages in extracted features:", len(features)) # 4 stages
print("Size of extracted features in stage 1:", features[0].size()) # torch.Size([1, 196, 128, 128])
print("Size of extracted features in stage 4:", features[3].size()) # torch.Size([1, 1568, 16, 16])

License:

NVIDIA Source Code License-NC

Results + Pretrained Models

ImageNet-21K

NameAcc@1(%)Acc@5(%)#Params(M)FLOPs(G)ResolutionHFDownload
MambaVision-B-21K84.997.597.715.0224x224linkmodel
MambaVision-L-21K86.197.9227.934.9224x224linkmodel
MambaVision-L2-512-21K87.398.4241.5196.3512x512linkmodel
MambaVision-L3-256-21K87.398.3739.6122.3256x256linkmodel
MambaVision-L3-512-21K88.198.6739.6489.1512x512linkmodel

ImageNet-1K

NameAcc@1(%)Acc@5(%)Throughput(Img/Sec)Resolution#Params(M)FLOPs(G)HFDownload
MambaVision-T82.396.26298224x22431.84.4linkmodel
MambaVision-T282.796.35990224x22435.15.1linkmodel
MambaVision-S83.396.54700224x22450.17.5linkmodel
MambaVision-B84.296.93670224x22497.715.0linkmodel
MambaVision-L85.097.12190224x224227.934.9linkmodel
MambaVision-L285.397.21021224x224241.537.5linkmodel

Installation

We provide a docker file. In addition, assuming that a recent PyTorch package is installed, the dependencies can be installed by running:

pip install -r requirements.txt
custom_code
image-classification
mambavision
safetensors
transformers