OpenGVLab/internimage_s_1k_224
模型介绍
文件和版本
Pull Requests
讨论
分析

InternImage 模型卡

简介

InternImage 是由上海人工智能实验室、清华大学及其他机构的研究人员研发的前沿视觉基础模型。与基于 Transformer 的模型不同,InternImage 采用 DCNv3 作为核心算子。该方案为模型提供了目标检测、分割等下游任务所需的动态且高效感受野,同时支持自适应空间聚合。

性能

  • 在图像分类任务中,InternImage 仅使用公开可用数据,便在 ImageNet 基准数据集上取得了 90.1% 的 Top-1 准确率,表现亮眼。除 Google 和微软两个使用额外数据集训练的未公开模型外,InternImage 是目前唯一达到 90.0% 以上 Top-1 准确率的开源模型,同时也是全球规模最大的模型。
  • 在 COCO 目标检测基准数据集上,InternImage 以 65.5 的 mAP 领先全球所有其他模型,也是目前全球唯一 mAP 突破 65 的模型。
  • 此外,InternImage 还在其他 16 个重要视觉基准数据集上取得了全球最佳性能,覆盖分类、检测、分割等多种任务,成为多个领域中的顶尖模型。

已发布模型

开源视觉预训练模型

Hugging Face 名称模型名称预训练分辨率参数量
internimage_l_22k_384InternImage-LIN-22K384x384223M
internimage_xl_22k_384InternImage-XLIN-22K384x384335M
internimage_h_jointto22k_384InternImage-HJoint 427M -> IN-22K384x3841.08B
internimage_g_jointto22k_384InternImage-GJoint 427M -> IN-22K384x3843B

ImageNet-1K 图像分类

Hugging Face 名称模型名称预训练分辨率acc@1参数量FLOPs
internimage_t_1k_224InternImage-TIN-1K224x22483.530M5G
internimage_s_1k_224InternImage-SIN-1K224x22484.250M8G
internimage_b_1k_224InternImage-BIN-1K224x22484.997M16G
internimage_l_22kto1k_384InternImage-LIN-22K384x38487.7223M108G
internimage_xl_22kto1k_384InternImage-XLIN-22K384x38488.0335M163G
internimage_h_22kto1k_640InternImage-HJoint 427M -> IN-22K640x64089.61.08B1478G
internimage_g_22kto1k_512InternImage-GJoint 427M -> IN-22K512x51290.13B2700G

DCNv3 CUDA 内核安装

如果未安装 DCNv3 的 CUDA 版本,InternImage 将自动回退至 PyTorch 实现。但是,CUDA 实现可以显著降低 GPU 显存占用,并提升推理效率。

安装教程:

  1. 打开终端并运行:

    git clone https://github.com/OpenGVLab/InternImage.git
    cd InternImage/classification/ops_dcnv3
  2. 确保有可用于编译的 GPU,然后运行:

    sh make.sh

这将编译 DCNv3 的 CUDA 版本。安装完成后,InternImage 将自动利用经过优化的 CUDA 实现,以获得更好的性能。

与 Transformers 配合使用

以下是 InternImage 在 Transformers 框架中的两个使用示例:

示例 1:将 InternImage 用作图像骨干网络

import torch
from PIL import Image
from transformers import AutoModel, CLIPImageProcessor

# Replace 'model_name' with the appropriate model identifier
model_name = "OpenGVLab/internimage_t_1k_224"  # example model

# Prepare the image
image_path = 'img.png'
image_processor = CLIPImageProcessor.from_pretrained(model_name)
image = Image.open(image_path)
image = image_processor(images=image, return_tensors='pt').pixel_values
print('image shape:', image.shape)

# Load the model as a backbone
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
# 'hidden_states' contains the outputs from the 4 stages of the InternImage backbone
hidden_states = model(image).hidden_states

示例 2:使用 InternImage 进行图像分类

import torch
from PIL import Image
from transformers import AutoModelForImageClassification, CLIPImageProcessor

# Replace 'model_name' with the appropriate model identifier
model_name = "OpenGVLab/internimage_t_1k_224"  # example model

# Prepare the image
image_path = 'img.png'
image_processor = CLIPImageProcessor.from_pretrained(model_name)
image = Image.open(image_path)
image = image_processor(images=image, return_tensors='pt').pixel_values
print('image shape:', image.shape)

# Load the model as an image classifier
model = AutoModelForImageClassification.from_pretrained(model_name, trust_remote_code=True)
logits = model(image).logits
label = torch.argmax(logits, dim=1)
print("Predicted label:", label.item())

引用

若本研究对您的工作有所帮助,敬请引用以下 BibTeX 条目。

@inproceedings{wang2023internimage,
  title={Internimage: Exploring large-scale vision foundation models with deformable convolutions},
  author={Wang, Wenhai and Dai, Jifeng and Chen, Zhe and Huang, Zhenhang and Li, Zhiqi and Zhu, Xizhou and Hu, Xiaowei and Lu, Tong and Lu, Lewei and Li, Hongsheng and others},
  booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
  pages={14408--14419},
  year={2023}
}