ViDT: An Efficient and Effective Fully Transformer-based Object Detector

Related tags

Deep Learningvidt
Overview

ViDT: An Efficient and Effective Fully Transformer-based Object Detector

by Hwanjun Song1, Deqing Sun2, Sanghyuk Chun1, Varun Jampani2, Dongyoon Han1,
Byeongho Heo1, Wonjae Kim1, and Ming-Hsuan Yang2,3

1 NAVER AI Lab, 2 Google Research, 3 University California Merced

ViDT: Vision and Detection Transformers

Highlight

ViDT is an end-to-end fully transformer-based object detector, which directly produces predictions without using convolutional layers. Our main contributions are summarized as follows:

  • ViDT introduces a modified attention mechanism, named Reconfigured Attention Module (RAM), that facilitates any ViT variant to handling the appened [DET] and [PATCH] tokens for a standalone object detection. Thus, we can modify the lastest Swin Transformer backbone with RAM to be an object detector and obtain high scalability using its local attetention mechanism with linear complexity.

  • ViDT adopts a lightweight encoder-free neck architecture to reduce the computational overhead while still enabling the additional optimization techniques on the neck module. As a result, ViDT obtains better performance than neck-free counterparts.

  • We introdcue a new concept of token matching for knowledge distillation, which brings additional performance gains from a large model to a small model without compromising detection efficiency.

Architectural Advantages. First, ViDT enables to combine Swin Transformer and the sequent-to-sequence paradigm for detection. Second, ViDT can use the multi-scale features and additional techniques without a significant computation overhead. Therefore, as a fully transformer-based object detector, ViDT facilitates better integration of vision and detection transformers.

Component Summary. There are four components: (1) RAM to extend Swin Transformer as a standalone object detector, (2) the neck decoder to exploit multi-scale features with two additional techniques, auxiliary decoding loss and iterative box refinement, (3) knowledge distillation to benefit from a large model, and (4) decoding layer drop to further accelerate inference speed.

Evaluation

Index: [A. ViT Backbone], [B. Main Results], [C. Complete Analysis]

|--- A. ViT Backbone used for ViDT
|--- B. Main Results in the ViDT Paper
     |--- B.1. ViDT for 50 and 150 Epochs
     |--- B.2. Distillation with Token Matching
|--- C. Complete Component Analysis

A. ViT Backbone used for ViDT

Backbone and Size Training Data Epochs Resulution Params ImageNet Acc. Checkpoint
Swin-nano ImageNet-1K 300 224 6M 74.9% Github
Swin-tiny ImageNet-1K 300 224 28M 81.2% Github
Swin-small ImageNet-1K 300 224 50M 83.2% Github
Swin-base ImageNet-22K 90 224 88M 86.3% Github

B. Main Results in the ViDT Paper

In main experiments, auxiliary decoding loss and iterative box refinement were used as the auxiliary techniques on the neck structure.
The efficiacy of distillation with token mathcing and decoding layer drop are verified independently in Compelete Component Analysis.
All the models were re-trained with the final version of source codes. Thus, the value may be very slightly different from those in the paper.

B.1. VIDT for 50 and 150 epochs
Backbone Epochs AP AP50 AP75 AP_S AP_M AP_L Params FPS Checkpoint / Log
Swin-nano 50 (150) 40.4 (42.6) 59.9 (62.2) 43.0 (45.7) 23.1 (24.9) 42.8 (45.4) 55.9 (59.1) 16M 20.0 Github / Log
(Github / Log)
Swin-tiny 50 (150) 44.9 (47.2) 64.7 (66.7) 48.3 (51.4) 27.5 (28.4) 47.9 (50.2) 61.9 (64.7) 38M 17.2 Github / Log
(Github / Log)
Swin-small 50 (150) 47.4 (48.8) 67.7 (68.8) 51.2 (53.0) 30.4 (30.7) 50.7 (52.0) 64.6 (65.9) 60M 12.1 Github / Log
(Github / Log)
Swin-base 50 (150) 49.4 (50.4) 69.6 (70.4) 53.4 (54.8) 31.6 (34.1) 52.4 (54.2) 66.8 (67.4) 0.1B 9.0 Github / Log
(Github / Log)
B.2. Distillation with Token Matching (Coefficient 4.0)

All the models are trained for 50 epochs with distillation.

Teacher ViDT (Swin-base) trained for 50 epochs
Student ViDT (Swin-nano) ViDT (Swin-tiny) ViDT (Swin-Small)
Coefficient = 0.0 40.4 44.9 47.4
Coefficient = 4.0 41.8 (Github / Log) 46.6 (Github / Log) 49.2 (Github / Log)

C. Complete Component Analysis

We combined the four proposed components (even with distillation with token matching and decoding layer drop) to achieve high accuracy and speed for object detection. For distillation, ViDT (Swin-base) trained for 50 epochs was used for all models.

Component Swin-nano Swin-tiny Swin-small
# RAM Neck Distil Drop AP Params FPS AP Params FPS AP Params FPS
(1) ✔️ 28.7 7M 36.5 36.3 29M 28.6 41.6 52M 16.8
(2) ✔️ ✔️ 40.4 16M 20.0 44.9 38M 17.2 47.4 60M 12.1
(3) ✔️ ✔️ ✔️ 41.8 16M 20.0 46.6 38M 17.2 49.2 60M 12.1
(4) ✔️ ✔️ ✔️ ✔️ 41.6 13M 23.0 46.4 35M 19.5 49.1 58M 13.0

Requirements

This codebase has been developed with the setting used in Deformable DETR:
Linux, CUDA>=9.2, GCC>=5.4, Python>=3.7, PyTorch>=1.5.1, and torchvision>=0.6.1.

We recommend you to use Anaconda to create a conda environment:

conda create -n deformable_detr python=3.7 pip
conda activate deformable_detr
conda install pytorch=1.5.1 torchvision=0.6.1 cudatoolkit=9.2 -c pytorch

Compiling CUDA operators for deformable attention

cd ./ops
sh ./make.sh
# unit test (should see all checking is True)
python test.py

Other requirements

pip install -r requirements.txt

Training

We used the below commands to train ViDT models with a single node having 8 NVIDIA V100 GPUs.

Run this command to train the ViDT (Swin-nano) model in the paper :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_nano \
       --epochs 50 \
       --lr 1e-4 \
       --min-lr 1e-7 \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --output_dir /path/for/output
Run this command to train the ViDT (Swin-tiny) model in the paper :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_tiny \
       --epochs 50 \
       --lr 1e-4 \
       --min-lr 1e-7 \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --output_dir /path/for/output
Run this command to train the ViDT (Swin-small) model in the paper :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_small \
       --epochs 50 \
       --lr 1e-4 \
       --min-lr 1e-7 \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --output_dir /path/for/output
Run this command to train the ViDT (Swin-base) model in the paper :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_base_win7_22k \
       --epochs 50 \
       --lr 1e-4 \
       --min-lr 1e-7 \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --output_dir /path/for/output

When a large pre-trained ViDT model is available, distillation with token matching can be applied for training a smaller ViDT model.

Run this command when training ViDT (Swin-nano) using a large ViDT (Swin-base) via Knowledge Distillation :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_nano \
       --epochs 50 \
       --lr 1e-4 \
       --min-lr 1e-7 \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --distil_model vidt_base \
       --distil_path /path/to/vidt_base (or url) \
       --coco_path /path/to/coco \
       --output_dir /path/for/output

Evaluation

Run this command to evaluate the ViDT (Swin-nano) model on COCO :

python -m torch.distributed.launch \
       --nproc_per_node=8 \ 
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_nano \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --resume /path/to/vidt_nano \
       --pre_trained none \
       --eval True
Run this command to evaluate the ViDT (Swin-tiny) model on COCO :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_tiny \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --resume /path/to/vidt_tiny\
       --pre_trained none \
       --eval True
Run this command to evaluate the ViDT (Swin-small) model on COCO :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_small \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --resume /path/to/vidt_small \
       --pre_trained none \
       --eval True
Run this command to evaluate the ViDT (Swin-base) model on COCO :

python -m torch.distributed.launch \
       --nproc_per_node=8 \
       --nnodes=1 \
       --use_env main.py \
       --method vidt \
       --backbone_name swin_base_win7_22k \
       --batch_size 2 \
       --num_workers 2 \
       --aux_loss True \
       --with_box_refine True \
       --coco_path /path/to/coco \
       --resume /path/to/vidt_base \
       --pre_trained none \
       --eval True

Citation

Please consider citation if our paper is useful in your research.

@article{song2021vidt,
  title={ViDT: An Efficient and Effective Fully Transformer-based Object Detector},
  author={Song, Hwanjun and Sun, Deqing and Chun, Sanghyuk and Jampani, Varun and Han, Dongyoon and Heo, Byeongho and Kim, Wonjae and Yang, Ming-Hsuan},
  journal={arXiv preprint arXiv:2110.03921},
  year={2021}
}

License

Copyright 2021-present NAVER Corp.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Inference Time of Deformable Detr with Swin-base

    Inference Time of Deformable Detr with Swin-base

    Hi, From the results you provided in openreview, the inference time of deformable detr with swin-base is 4.8 FPS. However, from my testing, it is 8.1 FPS. I am using Tesla V100 GPU with batch size=1.

    Screen Shot 2021-12-03 at 4 27 18 PM

    opened by ilovecv 5
  • Simple notebook file(.ipynb) for whom wants to train/test ViDT on Colab

    Simple notebook file(.ipynb) for whom wants to train/test ViDT on Colab

    As I first seen your paper, I'm currently trying train/test of ViDT on single machine, single gpu (especially Colab Pro).

    Since there seems to be no any other materials (or .ipynb file) of tutorial for this simple testing with COCO dataset,

    I would like to share my .ipynb file for whom interested in this model, and testing with Colab environment.

    .ipynb file on this repo

    If it bothers, please let me know, then I'll delete this colab repo.

    Thanks in advance.

    opened by EherSenaw 1
  • Error while running make.sh

    Error while running make.sh

    I am getting the following error message while running make.sh in ops directory.

    I am exactly following the installation steps provided in the README file

    `Traceback (most recent call last): File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1423, in _run_ninja_build check=True) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/subprocess.py", line 512, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "setup.py", line 70, in cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension}, File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/setuptools/init.py", line 153, in setup return distutils.core.setup(**attrs) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/core.py", line 148, in setup dist.run_commands() File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/dist.py", line 966, in run_commands self.run_command(cmd) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/command/build.py", line 135, in run self.run_command(cmd_name) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 79, in run _build_ext.run(self) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/command/build_ext.py", line 340, in run self.build_extensions() File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 603, in build_extensions build_ext.build_extensions(self) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/command/build_ext.py", line 449, in build_extensions self._build_extensions_serial() File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/command/build_ext.py", line 474, in _build_extensions_serial self.build_extension(ext) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 202, in build_extension _build_ext.build_extension(self, ext) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/distutils/command/build_ext.py", line 534, in build_extension depends=ext.depends) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 437, in unix_wrap_ninja_compile with_cuda=with_cuda) File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1163, in _write_ninja_file_and_compile_objects error_prefix='Error compiling objects for extension') File "/home/aditya_rastogi/anaconda3/envs/ddetr/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1436, in _run_ninja_build raise RuntimeError(message) RuntimeError: Error compiling objects for extension`

    opened by IISCAditayTripathi 0
  • Question about feature map

    Question about feature map

    Hello,

    I have a question about the feature map that is extracted by the Swin backbone. Assuming an input with size (224,224), the original Swin model produces 4 feature maps, with shapes (C, 56, 56), (2C, 28, 28), (4C, 14, 14) and (8C, 7, 7).

    Your version, however, produces 4 feature maps (2C, 28, 28), (4C, 14, 14), (8C, 7, 7) and (256, 4, 4).

    Can you please explain why you are not also using the 1st feature map?

    opened by ManiadisG 0
  • Long training Time

    Long training Time

    I am trying to train swin_nano with 4 V100 GPUs. It's almost 20hrs but have not completed one epoch yet. I have followed the setup instructions stated in this repo. My setup is as foliows: Package Version


    certifi 2022.6.15
    charset-normalizer 2.1.0
    cycler 0.11.0
    einops 0.4.1
    fonttools 4.33.3
    idna 3.3
    kiwisolver 1.4.3
    matplotlib 3.5.2
    MultiScaleDeformableAttention 1.0
    numpy 1.21.6
    onnx 1.10.0
    onnxruntime 1.4.0
    opencv-python 4.1.1.26
    packaging 21.3
    Pillow 9.2.0
    pip 19.0.3
    protobuf 3.20.1
    pycocotools 2.0.4
    pyparsing 3.0.9
    python-dateutil 2.8.2
    requests 2.28.1
    scipy 1.7.3
    setuptools 40.8.0
    six 1.16.0
    timm 0.5.4
    torch 1.8.0+cu111 torchaudio 0.8.0
    torchvision 0.9.0+cu111 typing-extensions 4.3.0
    urllib3 1.26.9

    With the same setup DeformableDETR takes 1hr and 30 mins to complete one epoch on COCO 2017 dataset. Could anyone identify the problem?

    opened by Alam4545 0
  • What if we only do detection and classification task with vidt+

    What if we only do detection and classification task with vidt+

    As mention in title,I have some dataset that already transform to coco format with bounding box and class label but with no segmentation mask,which part of your code should be modified? Simply with --mask=False still not working..

    opened by quyanqiu 0
  • #BUG

    #BUG

    when i run the main.py, the error comes

    ViDT training and evaluation script: error: unrecognized arguments: true

    in main.py, my code is

    args = parser.parse_args(['--method', 'vidt', '--backbone_name', 'swin_nano', '--epochs', '50', '--lr', '1e-4', '--min-lr', '1e-7', '--batch_size', '2', '--num_workers', '2', '--aux_loss', 'true', '--with_box_refine', 'true', '--det_token_num', '100', '--epff', ' true', '--token_label', 'true', '--iou_aware', 'true', '--with_vector', 'true', '--masks', 'true', '--coco_path', '/r/code/coco', '--output_dir', './output',])

    opened by ross-Hr 1
Releases(v0.1-vidt-plus-optimized)
Owner
NAVER AI
Official account of NAVER AI, Korea No.1 Industrial AI Research Group
NAVER AI
implement of SwiftNet:Real-time Video Object Segmentation

SwiftNet The official PyTorch implementation of SwiftNet:Real-time Video Object Segmentation, which has been accepted by CVPR2021. Requirements Python

haochen wang 64 Dec 14, 2022
Sentiment analysis translations of the Bhagavad Gita

Sentiment and Semantic Analysis of Bhagavad Gita Translations It is well known that translations of songs and poems not only breaks rhythm and rhyming

Machine learning and Bayesian inference @ UNSW Sydney 3 Aug 01, 2022
NeurIPS 2021 paper 'Representation Learning on Spatial Networks' code

Representation Learning on Spatial Networks This repository is the official implementation of Representation Learning on Spatial Networks. Training Ex

13 Dec 29, 2022
A PyTorch Implementation of "SINE: Scalable Incomplete Network Embedding" (ICDM 2018).

Scalable Incomplete Network Embedding ⠀⠀ A PyTorch implementation of Scalable Incomplete Network Embedding (ICDM 2018). Abstract Attributed network em

Benedek Rozemberczki 69 Sep 22, 2022
Arch-Net: Model Distillation for Architecture Agnostic Model Deployment

Arch-Net: Model Distillation for Architecture Agnostic Model Deployment The official implementation of Arch-Net: Model Distillation for Architecture A

MEGVII Research 22 Jan 05, 2023
Official implementation of the ICML2021 paper "Elastic Graph Neural Networks"

ElasticGNN This repository includes the official implementation of ElasticGNN in the paper "Elastic Graph Neural Networks" [ICML 2021]. Xiaorui Liu, W

liuxiaorui 34 Dec 04, 2022
graph-theoretic framework for robust pairwise data association

CLIPPER: A Graph-Theoretic Framework for Robust Data Association Data association is a fundamental problem in robotics and autonomy. CLIPPER provides

MIT Aerospace Controls Laboratory 118 Dec 28, 2022
BERT model training impelmentation using 1024 A100 GPUs for MLPerf Training v1.1

Pre-trained checkpoint and bert config json file Location of checkpoint and bert config json file This MLCommons members Google Drive location contain

SAIT (Samsung Advanced Institute of Technology) 12 Apr 27, 2022
[SIGMETRICS 2022] One Proxy Device Is Enough for Hardware-Aware Neural Architecture Search

One Proxy Device Is Enough for Hardware-Aware Neural Architecture Search paper | website One Proxy Device Is Enough for Hardware-Aware Neural Architec

10 Dec 16, 2022
Pytorch implementation of DeePSiM

Pytorch implementation of DeePSiM

1 Nov 05, 2021
2021 Artificial Intelligence Diabetes Datathon

A.I.D.D. 2021 2021 Artificial Intelligence Diabetes Datathon A.I.D.D. 2021은 ‘2021 인공지능 학습용 데이터 구축사업’을 통해 만들어진 학습용 데이터를 활용하여 당뇨병을 효과적으로 예측할 수 있는가에 대한 A

2 Dec 27, 2021
Crowd-sourced Annotation of Human Motion.

Motion Annotation Tool Live: https://motion-annotation.humanoids.kit.edu Paper: The KIT Motion-Language Dataset Installation Start by installing all P

Matthias Plappert 4 May 25, 2020
Temporal Knowledge Graph Reasoning Triggered by Memories

MTDM Temporal Knowledge Graph Reasoning Triggered by Memories To alleviate the time dependence, we propose a memory-triggered decision-making (MTDM) n

4 Sep 25, 2022
Baseline for the Spoofing-aware Speaker Verification Challenge 2022

Introduction This repository contains several materials that supplements the Spoofing-Aware Speaker Verification (SASV) Challenge 2022 including: calc

40 Dec 28, 2022
Unified tracking framework with a single appearance model

Paper: Do different tracking tasks require different appearance model? [ArXiv] (comming soon) [Project Page] (comming soon) UniTrack is a simple and U

ZhongdaoWang 300 Dec 24, 2022
Dataset Condensation with Contrastive Signals

Dataset Condensation with Contrastive Signals This repository is the official implementation of Dataset Condensation with Contrastive Signals (DCC). T

3 May 19, 2022
Hummingbird compiles trained ML models into tensor computation for faster inference.

Hummingbird Introduction Hummingbird is a library for compiling trained traditional ML models into tensor computations. Hummingbird allows users to se

Microsoft 3.1k Dec 30, 2022
Code for the ICCV 2021 Workshop paper: A Unified Efficient Pyramid Transformer for Semantic Segmentation.

Unified-EPT Code for the ICCV 2021 Workshop paper: A Unified Efficient Pyramid Transformer for Semantic Segmentation. Installation Linux, CUDA=10.0,

29 Aug 23, 2022
某学校选课系统GIF验证码数据集 + Baseline模型 + 上下游相关工具

elective-dataset-2021spring 某学校2021春季选课系统GIF验证码数据集(29338张) + 准确率98.4%的Baseline模型 + 上下游相关工具。 数据集采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。 Baseline模型和上下游相关工具采用

xmcp 27 Sep 17, 2021
MMDetection3D is an open source object detection toolbox based on PyTorch

MMDetection3D is an open source object detection toolbox based on PyTorch, towards the next-generation platform for general 3D detection. It is a part of the OpenMMLab project developed by MMLab.

OpenMMLab 3.2k Jan 05, 2023