FasterViT

NVlabs长期未更新

FasterViT 是 NVIDIA 提出的高效视觉主干网络,通过分层注意力机制在 ImageNet 分类、COCO 检测和 ADE20K 分割上兼顾精度与推理速度。

[ICLR 2024] Official PyTorch implementation of FasterViT: Fast Vision Transformers with Hierarchical Attention

v1.0.0发布于 2025-07-22 21:59 UTC928star72fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
pip install fastervit
pip install -r requirements.txt
硬件要求按 README 说明

README 未说明具体显存要求;吞吐数据基于 GPU 测得,并建议用最新 NVIDIA TensorRT 获得优化算子收益,未提及 CPU 运行或非 NVIDIA GPU 支持

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

NVIDIA 官方 FasterViT 视觉 Transformer 实现,用分层注意力兼顾精度与吞吐

FasterViT 是 NVIDIA 提出的高效视觉主干网络,通过分层注意力机制在 ImageNet 分类、COCO 检测和 ADE20K 分割上兼顾精度与推理速度。

核心能力

  • 提出分层注意力 HAT,用跨窗口 carrier token 捕捉长程信息
  • 提供 ImageNet-1K/21K 预训练权重,一行代码加载模型
  • 支持任意分辨率 any-res 模型,可迁移到检测分割等任务
  • 附带 ONNX 与 CoreML 导出脚本,支持动态 batch 推理
  • 含 DINO 检测与 MOTRv2 跟踪的下游任务代码

容易踩的坑

预训练权重需联网从 HuggingFace 下载,并用 model_path 指定下载目录;已装旧版需升级到 fastervit>=0.9.8 才能用预训练权重;CoreML 导出需单独安装 coremltools==5.2.0,且许可证为 NVIDIA 非商业源码许可

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.0.0
  1. v1.0.0最新正式版2025-07-22 · 2025-07-22 21:59 UTC

    这个版本没有写更新说明。

  2. v0.9.82023-09-01 · 2023-09-01 18:50 UTC

    这个版本没有写更新说明。

  3. v0.9.72023-08-28 · 2023-08-28 16:20 UTC
    查看更新说明

    Fixes minor issues

  4. v0.9.62023-08-21 · 2023-08-21 16:07 UTC

    这个版本没有写更新说明。

  5. v0.9.52023-08-12 · 2023-08-12 07:39 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    FasterViT: Fast Vision Transformers with Hierarchical Attention

    Official PyTorch implementation of FasterViT: Fast Vision Transformers with Hierarchical Attention.

    Star on GitHub

    Ali Hatamizadeh, Greg Heinrich, Hongxu (Danny) Yin, Andrew Tao, Jose M. Alvarez, Jan Kautz, Pavlo Molchanov.

    For business inquiries, please visit our website and submit the form: NVIDIA Research Licensing


    FasterViT achieves a new SOTA Pareto-front in terms of Top-1 accuracy and throughput without extra training data !

    We introduce a new self-attention mechanism, denoted as Hierarchical Attention (HAT), that captures both short and long-range information by learning cross-window carrier tokens.

    teaser

    Note: Please use the latest NVIDIA TensorRT release to enjoy the benefits of optimized FasterViT ops.

    💥 News 💥

    • [03.25.2025] We have updated the download links for each model. All models are accecible via HuggingFace.
    • [04.02.2024] 🔥 Updated manuscript now available on arXiv !
    • [01.24.2024] 🔥🔥🔥 Object Tracking with MOTRv2 + FasterViT is now open-sourced (link) !
    • [01.17.2024] 🔥🔥🔥 FasterViT paper has been accepted to ICLR 2024 !
    • [10.14.2023] 🔥🔥 We have added the FasterViT object detection repository with DINO !
    • [08.24.2023] 🔥 FasterViT Keras models with pre-trained weights published in keras_cv_attention_models !
    • [08.20.2023] 🔥🔥 We have added ImageNet-21K SOTA pre-trained models for various resolutions !
    • [07.20.2023] We have created official NVIDIA FasterViT HuggingFace page.
    • [07.06.2023] FasterViT checkpoints are now also accecible in HuggingFace!
    • [07.04.2023] ImageNet pretrained FasterViT models can now be imported with 1 line of code. Please install the latest FasterViT pip package to use this functionality (also supports Any-resolution FasterViT models).
    • [06.30.2023] We have further improved the TensorRT throughput of FasterViT models by 10-15% on average across different models. Please use the latest NVIDIA TensorRT release to use these throughput performance gains.
    • [06.29.2023] Any-resolution FasterViT model can now be intitialized from pre-trained ImageNet resolution (224 x 244) models.
    • [06.18.2023] We have released the FasterViT pip package !
    • [06.17.2023] Any-resolution FasterViT model is now available ! the model can be used for variety of applications such as detection and segmentation or high-resolution fine-tuning with arbitrary input image resolutions.
    • [06.09.2023] 🔥🔥 We have released source code and ImageNet-1K FasterViT-models !

    Quick Start

    Object Detection

    Please see FasterViT object detection repository with DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection for more details.

    Classification

    We can import pre-trained FasterViT models with 1 line of code. Firstly, FasterViT can be simply installed:

    pip install fastervit
    

    Note: Please upgrate the package to fastervit>=0.9.8 if you have already installed the package to use the pretrained weights.

    A pretrained FasterViT model with default hyper-parameters can be created as in:

    >>> from fastervit import create_model
    
    # Define fastervit-0 model with 224 x 224 resolution
    
    >>> model = create_model('faster_vit_0_224', 
                              pretrained=True,
                              model_path="/tmp/faster_vit_0.pth.tar")
    

    model_path is used to set the directory to download the model.

    We can also simply test the model by passing a dummy input image. The output is the logits:

    >>> import torch
    
    >>> image = torch.rand(1, 3, 224, 224)
    >>> output = model(image) # torch.Size([1, 1000])
    

    We can also use the any-resolution FasterViT model to accommodate arbitrary image resolutions. In the following, we define an any-resolution FasterViT-0 model with input resolution of 576 x 960, window sizes of 12 and 6 in 3rd and 4th stages, carrier token size of 2 and embedding dimension of 64:

    >>> from fastervit import create_model
    
    # Define any-resolution FasterViT-0 model with 576 x 960 resolution
    >>> model = create_model('faster_vit_0_any_res', 
                              resolution=[576, 960],
                              window_size=[7, 7, 12, 6],
                              ct_size=2,
                              dim=64,
                              pretrained=True)
    

    Note that the above model is intiliazed from the original ImageNet pre-trained FasterViT with original resolution of 224 x 224. As a result, missing keys and mis-matches could be expected since we are addign new layers (e.g. addition of new carrier tokens, etc.)

    We can test the model by passing a dummy input image. The output is the logits:

    >>> import torch
    
    >>> image = torch.rand(1, 3, 576, 960)
    >>> output = model(image) # torch.Size([1, 1000])
    

    Catalog

    • ImageNet-1K training code
    • ImageNet-1K pre-trained models
    • Any-resolution FasterViT
    • FasterViT pip-package release
    • Add capablity to initialize any-resolution FasterViT from ImageNet-pretrained weights.
    • ImageNet-21K pre-trained models
    • Detection code + models

    Results + Pretrained Models

    ImageNet-1K

    FasterViT ImageNet-1K Pretrained Models

    ImageNet-21K

    FasterViT ImageNet-21K Pretrained Models (ImageNet-1K Fine-tuned)

    Raw pre-trained ImageNet-21K model weights for FasterViT-4 is also available for download in this link.

    Robustness (ImageNet-A - ImageNet-R - ImageNet-V2)

    All models use crop_pct=0.875. Results are obtained by running inference on ImageNet-1K pretrained models without finetuning.

    A, R and V2 denote ImageNet-A, ImageNet-R and ImageNet-V2 respectively.

    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
    

    Training

    Please see TRAINING.md for detailed training instructions of all models.

    Evaluation

    The FasterViT models can be evaluated on ImageNet-1K validation set using the following:

    python validate.py \
    --model <model-name>
    --checkpoint <checkpoint-path>
    --data_dir <imagenet-path>
    --batch-size <batch-size-per-gpu
    

    Here --model is the FasterViT variant (e.g. faster_vit_0_224_1k), --checkpoint is the path to pretrained model weights, --data_dir is the path to ImageNet-1K validation set and --batch-size is the number of batch size. We also provide a sample script here.

    ONNX Conversion

    We provide ONNX conversion script to enable dynamic batch size inference. For instance, to generate ONNX model for faster_vit_0_any_res with resolution 576 x 960 and ONNX opset number 17, the following can be used.

    python onnx_convert --model-name faster_vit_0_any_res --simplify --resolution-h 576 --resolution-w 960 --onnx-opset 17
    
    

    CoreML Conversion

    To generate FasterViT CoreML models, please install coremltools==5.2.0 and use our provided script.

    It is recommended to benchmark the performance by using Xcode14 or newer releases.

    Star History

    Star History Chart

    Third-party Extentions

    We always welcome third-party extentions/implementations and usage for other purposes. The following represent third-party contributions by other users.

    NameLinkContributorFramework
    keras_cv_attention_modelsLink@leondgarseKeras

    If you would like your work to be listed in this repository, please raise an issue and provide us with detailed information.

    Citation

    Please consider citing FasterViT if this repository is useful for your work.

    @article{hatamizadeh2023fastervit,
      title={FasterViT: Fast Vision Transformers with Hierarchical Attention},
      author={Hatamizadeh, Ali and Heinrich, Greg and Yin, Hongxu and Tao, Andrew and Alvarez, Jose M and Kautz, Jan and Molchanov, Pavlo},
      journal={arXiv preprint arXiv:2306.06189},
      year={2023}
    }
    

    Licenses

    Copyright © 2025, NVIDIA Corporation. All rights reserved.

    This work is made available under the NVIDIA Source Code License-NC. Click here to view a copy of this license.

    For license information regarding the timm repository, please refer to its repository.

    For license information regarding the ImageNet dataset, please see the ImageNet official website.

    Acknowledgement

    This repository is built on top of the timm repository. We thank Ross Wrightman for creating and maintaining this high-quality library.