Commit fe6cdd2e authored by zhe chen's avatar zhe chen
Browse files

Update huggingface model


Update huggingface model


Update README.md


Update README.md


Update README.md


Update huggingface model


Update huggingface model
parent 3bd2e7b9
{
"crop_size": 384,
"do_center_crop": true,
"do_normalize": true,
"do_resize": true,
"feature_extractor_type": "CLIPFeatureExtractor",
"image_mean": [
0.485,
0.456,
0.406
],
"image_std": [
0.229,
0.224,
0.225
],
"resample": 3,
"size": 384
}
---
license: mit
pipeline_tag: image-classification
library_name: transformers
tags:
- internimage
- custom_code
datasets:
- ILSVRC/imagenet-1k
---
# InternImage Model Card
## Introduction
InternImage is an advanced vision foundation model developed by researchers from Shanghai AI Laboratory, Tsinghua University, and other institutions. Unlike models based on Transformers, InternImage employs DCNv3 as its core operator. This approach equips the model with dynamic and effective receptive fields required for downstream tasks like object detection and segmentation, while enabling adaptive spatial aggregation.
<div style="text-align: center;"> <img src="https://github.com/OpenGVLab/InternImage/raw/master/docs/figs/arch.png" style="width:60%;" /> </div>
## Performance
- InternImage achieved an impressive Top-1 accuracy of 90.1% on the ImageNet benchmark dataset using only publicly available data for image classification. Apart from two undisclosed models trained with additional datasets by Google and Microsoft, InternImage is the only open-source model that achieves a Top-1 accuracy of over 90.0%, and it is also the largest model in scale worldwide.
- InternImage outperformed all other models worldwide on the COCO object detection benchmark dataset with a remarkable mAP of 65.5, making it the only model that surpasses 65 mAP in the world.
- InternImage also demonstrated world's best performance on 16 other important visual benchmark datasets, covering a wide range of tasks such as classification, detection, and segmentation, making it the top-performing model across multiple domains.
## Released Models
### Open‑Source Visual Pretrained Models
| huggingface name | model name | pretrain | resolution | #param |
| :-------------------------------------------------------------------------------------------: | :------------: | :------------------: | :--------: | :----: |
| [internimage_l_22k_384](https://huggingface.co/OpenGVLab/internimage_l_22k_384) | InternImage-L | IN-22K | 384x384 | 223M |
| [internimage_xl_22k_384](https://huggingface.co/OpenGVLab/internimage_xl_22k_384) | InternImage-XL | IN-22K | 384x384 | 335M |
| [internimage_h_jointto22k_384](https://huggingface.co/OpenGVLab/internimage_h_jointto22k_384) | InternImage-H | Joint 427M -> IN-22K | 384x384 | 1.08B |
| [internimage_g_jointto22k_384](https://huggingface.co/OpenGVLab/internimage_g_jointto22k_384) | InternImage-G | Joint 427M -> IN-22K | 384x384 | 3B |
### ImageNet-1K Image Classification
| huggingface name | model name | pretrain | resolution | acc@1 | #param | FLOPs |
| :---------------------------------------------------------------------------------------: | :------------: | :------------------: | :--------: | :---: | :----: | :---: |
| [internimage_t_1k_224](https://huggingface.co/OpenGVLab/internimage_t_1k_224) | InternImage-T | IN-1K | 224x224 | 83.5 | 30M | 5G |
| [internimage_s_1k_224](https://huggingface.co/OpenGVLab/internimage_s_1k_224) | InternImage-S | IN-1K | 224x224 | 84.2 | 50M | 8G |
| [internimage_b_1k_224](https://huggingface.co/OpenGVLab/internimage_b_1k_224) | InternImage-B | IN-1K | 224x224 | 84.9 | 97M | 16G |
| [internimage_l_22kto1k_384](https://huggingface.co/OpenGVLab/internimage_l_22kto1k_384) | InternImage-L | IN-22K | 384x384 | 87.7 | 223M | 108G |
| [internimage_xl_22kto1k_384](https://huggingface.co/OpenGVLab/internimage_xl_22kto1k_384) | InternImage-XL | IN-22K | 384x384 | 88.0 | 335M | 163G |
| [internimage_h_22kto1k_640](https://huggingface.co/OpenGVLab/internimage_h_22kto1k_640) | InternImage-H | Joint 427M -> IN-22K | 640x640 | 89.6 | 1.08B | 1478G |
| [internimage_g_22kto1k_512](https://huggingface.co/OpenGVLab/internimage_g_22kto1k_512) | InternImage-G | Joint 427M -> IN-22K | 512x512 | 90.1 | 3B | 2700G |
## DCNv3 CUDA Kernel Installation
If you do not install the CUDA version of DCNv3, InternImage will automatically fall back to a PyTorch implementation. However, the CUDA implementation can significantly reduce GPU memory usage and improve inference efficiency.
**Installation Tutorial:**
1. Open your terminal and run:
```bash
git clone https://github.com/OpenGVLab/InternImage.git
cd InternImage/classification/ops_dcnv3
```
2. Make sure you have an available GPU for compilation, then run:
```bash
sh make.sh
```
This will compile the CUDA version of DCNv3. Once installed, InternImage will automatically leverage the optimized CUDA implementation for better performance.
## Usage with Transformers
Below are two usage examples for InternImage with the Transformers framework:
### Example 1: Using InternImage as an Image Backbone
```python
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
```
### Example 2: Using InternImage for Image Classification
```python
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())
```
## Citation
If this work is helpful for your research, please consider citing the following BibTeX entry.
```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}
}
```
{
"_name_or_path": "OpenGVLab/internimage_xl_22k_384",
"act_layer": "GELU",
"architectures": [
"InternImageModel"
],
"auto_map": {
"AutoConfig": "configuration_internimage.InternImageConfig",
"AutoModel": "modeling_internimage.InternImageModel",
"AutoModelForImageClassification": "modeling_internimage.InternImageModelForImageClassification"
},
"center_feature_scale": false,
"channels": 192,
"cls_scale": 1.5,
"core_op": "DCNv3",
"depths": [
5,
5,
24,
5
],
"drop_path_rate": 0.0,
"drop_path_type": "linear",
"drop_rate": 0.0,
"dw_kernel_size": null,
"groups": [
12,
24,
48,
96
],
"layer_scale": 1e-05,
"level2_post_norm": false,
"level2_post_norm_block_ids": null,
"mlp_ratio": 4.0,
"model_type": "internimage",
"norm_layer": "LN",
"num_classes": 21841,
"offset_scale": 2.0,
"post_norm": true,
"remove_center": false,
"res_post_norm": false,
"torch_dtype": "float32",
"transformers_version": "4.37.2",
"use_clip_projector": false,
"with_cp": false
}
# --------------------------------------------------------
# InternImage
# Copyright (c) 2025 OpenGVLab
# Licensed under The MIT License [see LICENSE for details]
# --------------------------------------------------------
from transformers import PretrainedConfig
class InternImageConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`~InternImageModel`].
It is used to instantiate an internimage model according to the specified arguments, defining the model
architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of
the internimage [OpenGVLab/internimage](https://huggingface.co/OpenGVLab/internimage) architecture.
Configuration objects inherit from [`PretrainedConfig`] and can be used
to control the model outputs. Read the documentation from [`PretrainedConfig`]
for more information.
Args:
core_op (`str`, *optional*, defaults to `"DCNv3"`):
Core operation used in the InternImageModel.
depths (`tuple`, *optional*, defaults to `(4, 4, 18, 4)`):
Tuple specifying the depth of layers in the InternImageModel.
groups (`tuple`, *optional*, defaults to `(4, 8, 16, 32)`):
Tuple specifying the group of layers in the InternImageModel.
channels (`int`, *optional*, defaults to `64`):
Number of channels in the InternImageModel.
dw_kernel_size (`int`, *optional*, defaults to `None`):
Kernel size for depthwise convolutions.
layer_scale (`float`, *optional*, defaults to `None`):
Scale of the layers in the model.
offset_scale (`float`, *optional*, defaults to `1.0`):
Offset scale in the model.
mlp_ratio (`float`, *optional*, defaults to `4.0`):
Ratio of mlp layers in the InternImageModel.
post_norm (`bool`, *optional*, defaults to `False`):
Whether to use post normalization in the model.
level2_post_norm (`bool`, *optional*, defaults to `False`):
Whether to use level 2 post normalization.
level2_post_norm_block_ids (`list`, *optional*, defaults to `None`):
Specific block IDs for level 2 post normalization.
center_feature_scale (`bool`, *optional*, defaults to `False`):
Whether to apply center feature scaling.
use_clip_projector (`bool`, *optional*, defaults to `False`):
Whether to use CLIP projector.
remove_center (`bool`, *optional*, defaults to `False`):
Whether to remove center pixels in some operations.
num_classes (`int`, *optional*, defaults to `1000`):
Number of classes for the model output.
drop_rate (`float`, *optional*, defaults to `0.0`):
Dropout rate in the model.
drop_path_rate (`float`, *optional*, defaults to `0.0`):
Dropout path rate in the model.
drop_path_type (`str`, *optional*, defaults to `"linear"`):
Type of dropout path used in the model.
act_layer (`str`, *optional*, defaults to `"GELU"`):
Activation function used in the model.
norm_layer (`str`, *optional*, defaults to `"LN"`):
Normalization layer used in the model.
cls_scale (`float`, *optional*, defaults to `1.5`):
Scale of the classification layer in the model.
with_cp (`bool`, *optional*, defaults to `False`):
Whether to use checkpointing in the model.
"""
model_type = 'internimage'
def __init__(
self,
core_op='DCNv3',
depths=(4, 4, 18, 4),
groups=(4, 8, 16, 32),
channels=64,
dw_kernel_size=None,
layer_scale=None,
offset_scale=1.0,
mlp_ratio=4.0,
post_norm=False,
res_post_norm=False,
level2_post_norm=False,
level2_post_norm_block_ids=None,
center_feature_scale=False,
use_clip_projector=False,
remove_center=False,
num_classes=1000,
drop_rate=0.0,
drop_path_rate=0.0,
drop_path_type='linear',
act_layer='GELU',
norm_layer='LN',
cls_scale=1.5,
with_cp=False,
**kwargs,
):
super().__init__(**kwargs)
# Model configuration parameters
self.core_op = core_op
self.depths = depths
self.groups = groups
self.channels = channels
self.dw_kernel_size = dw_kernel_size
self.layer_scale = layer_scale
self.offset_scale = offset_scale
self.mlp_ratio = mlp_ratio
self.post_norm = post_norm
self.res_post_norm = res_post_norm
self.level2_post_norm = level2_post_norm
self.level2_post_norm_block_ids = level2_post_norm_block_ids
self.center_feature_scale = center_feature_scale
self.use_clip_projector = use_clip_projector
self.remove_center = remove_center
self.num_classes = num_classes
self.drop_rate = drop_rate
self.drop_path_rate = drop_path_rate
self.drop_path_type = drop_path_type
self.act_layer = act_layer
self.norm_layer = norm_layer
self.cls_scale = cls_scale
self.with_cp = with_cp
{
"crop_size": 384,
"do_center_crop": true,
"do_normalize": true,
"do_resize": true,
"feature_extractor_type": "CLIPFeatureExtractor",
"image_mean": [
0.485,
0.456,
0.406
],
"image_std": [
0.229,
0.224,
0.225
],
"resample": 3,
"size": 384
}
---
license: mit
pipeline_tag: image-classification
library_name: transformers
tags:
- internimage
- custom_code
datasets:
- ILSVRC/imagenet-1k
---
# InternImage Model Card
## Introduction
InternImage is an advanced vision foundation model developed by researchers from Shanghai AI Laboratory, Tsinghua University, and other institutions. Unlike models based on Transformers, InternImage employs DCNv3 as its core operator. This approach equips the model with dynamic and effective receptive fields required for downstream tasks like object detection and segmentation, while enabling adaptive spatial aggregation.
<div style="text-align: center;"> <img src="https://github.com/OpenGVLab/InternImage/raw/master/docs/figs/arch.png" style="width:60%;" /> </div>
## Performance
- InternImage achieved an impressive Top-1 accuracy of 90.1% on the ImageNet benchmark dataset using only publicly available data for image classification. Apart from two undisclosed models trained with additional datasets by Google and Microsoft, InternImage is the only open-source model that achieves a Top-1 accuracy of over 90.0%, and it is also the largest model in scale worldwide.
- InternImage outperformed all other models worldwide on the COCO object detection benchmark dataset with a remarkable mAP of 65.5, making it the only model that surpasses 65 mAP in the world.
- InternImage also demonstrated world's best performance on 16 other important visual benchmark datasets, covering a wide range of tasks such as classification, detection, and segmentation, making it the top-performing model across multiple domains.
## Released Models
### Open‑Source Visual Pretrained Models
| huggingface name | model name | pretrain | resolution | #param |
| :-------------------------------------------------------------------------------------------: | :------------: | :------------------: | :--------: | :----: |
| [internimage_l_22k_384](https://huggingface.co/OpenGVLab/internimage_l_22k_384) | InternImage-L | IN-22K | 384x384 | 223M |
| [internimage_xl_22k_384](https://huggingface.co/OpenGVLab/internimage_xl_22k_384) | InternImage-XL | IN-22K | 384x384 | 335M |
| [internimage_h_jointto22k_384](https://huggingface.co/OpenGVLab/internimage_h_jointto22k_384) | InternImage-H | Joint 427M -> IN-22K | 384x384 | 1.08B |
| [internimage_g_jointto22k_384](https://huggingface.co/OpenGVLab/internimage_g_jointto22k_384) | InternImage-G | Joint 427M -> IN-22K | 384x384 | 3B |
### ImageNet-1K Image Classification
| huggingface name | model name | pretrain | resolution | acc@1 | #param | FLOPs |
| :---------------------------------------------------------------------------------------: | :------------: | :------------------: | :--------: | :---: | :----: | :---: |
| [internimage_t_1k_224](https://huggingface.co/OpenGVLab/internimage_t_1k_224) | InternImage-T | IN-1K | 224x224 | 83.5 | 30M | 5G |
| [internimage_s_1k_224](https://huggingface.co/OpenGVLab/internimage_s_1k_224) | InternImage-S | IN-1K | 224x224 | 84.2 | 50M | 8G |
| [internimage_b_1k_224](https://huggingface.co/OpenGVLab/internimage_b_1k_224) | InternImage-B | IN-1K | 224x224 | 84.9 | 97M | 16G |
| [internimage_l_22kto1k_384](https://huggingface.co/OpenGVLab/internimage_l_22kto1k_384) | InternImage-L | IN-22K | 384x384 | 87.7 | 223M | 108G |
| [internimage_xl_22kto1k_384](https://huggingface.co/OpenGVLab/internimage_xl_22kto1k_384) | InternImage-XL | IN-22K | 384x384 | 88.0 | 335M | 163G |
| [internimage_h_22kto1k_640](https://huggingface.co/OpenGVLab/internimage_h_22kto1k_640) | InternImage-H | Joint 427M -> IN-22K | 640x640 | 89.6 | 1.08B | 1478G |
| [internimage_g_22kto1k_512](https://huggingface.co/OpenGVLab/internimage_g_22kto1k_512) | InternImage-G | Joint 427M -> IN-22K | 512x512 | 90.1 | 3B | 2700G |
## DCNv3 CUDA Kernel Installation
If you do not install the CUDA version of DCNv3, InternImage will automatically fall back to a PyTorch implementation. However, the CUDA implementation can significantly reduce GPU memory usage and improve inference efficiency.
**Installation Tutorial:**
1. Open your terminal and run:
```bash
git clone https://github.com/OpenGVLab/InternImage.git
cd InternImage/classification/ops_dcnv3
```
2. Make sure you have an available GPU for compilation, then run:
```bash
sh make.sh
```
This will compile the CUDA version of DCNv3. Once installed, InternImage will automatically leverage the optimized CUDA implementation for better performance.
## Usage with Transformers
Below are two usage examples for InternImage with the Transformers framework:
### Example 1: Using InternImage as an Image Backbone
```python
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
```
### Example 2: Using InternImage for Image Classification
```python
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())
```
## Citation
If this work is helpful for your research, please consider citing the following BibTeX entry.
```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}
}
```
This diff is collapsed.
{
"crop_size": 224,
"do_center_crop": true,
"do_normalize": true,
"do_resize": true,
"feature_extractor_type": "CLIPFeatureExtractor",
"image_mean": [
0.485,
0.456,
0.406
],
"image_std": [
0.229,
0.224,
0.225
],
"resample": 3,
"size": 224
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment