Model card for cspnext_s.rsb_a1_in1k
A CSPNeXt image classification model. Pretrained on ImageNet-1k by OpenMMLab (RTMDet) and converted to timm format.
Name disambiguation: This is the CSPNeXt backbone of RTMDet (OpenMMLab), as implemented in MMDetection. A separate paper, CSPNeXt: A new efficient token hybrid backbone (Chen et al., EAAI 2024, doi:10.1016/j.engappai.2024.107886), uses the same name for a different architecture. These weights do not implement that paper; please cite RTMDet (below) for this model.
Model Details
- Model Type: Image classification / feature backbone
- Model Stats:
- Params (M): 4.89
- GMACs: 0.66
- Activations (M): 2.76
- Image size: 224 x 224
- Papers:
- RTMDet: An Empirical Study of Designing Real-Time Object Detectors: https://arxiv.org/abs/2212.07784
- Original:
- https://github.com/open-mmlab/mmdetection/tree/main/configs/rtmdet/classification
- https://download.openmmlab.com/mmdetection/v3.0/rtmdet/cspnext_rsb_pretrain/cspnext-s_imagenet_600e-ea671761.pth
- Dataset: ImageNet-1k
Model Usage
Image Classification
from urllib.request import urlopen
from PIL import Image
import timm
import torch
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model('hf_hub:munehiro-k/cspnext_s.rsb_a1_in1k', pretrained=True)
model = model.eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
Feature Map Extraction
from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'hf_hub:munehiro-k/cspnext_s.rsb_a1_in1k',
pretrained=True,
features_only=True,
)
model = model.eval()
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
for o in output:
# print shape of each feature map in output
# e.g.:
# torch.Size([1, 32, 112, 112])
# torch.Size([1, 64, 56, 56])
# torch.Size([1, 128, 28, 28])
# torch.Size([1, 256, 14, 14])
# torch.Size([1, 512, 7, 7])
print(o.shape)
Image Embeddings
from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'hf_hub:munehiro-k/cspnext_s.rsb_a1_in1k',
pretrained=True,
num_classes=0, # remove classifier nn.Linear
)
model = model.eval()
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
# or equivalently (without needing to set num_classes=0)
output = model.forward_features(transforms(img).unsqueeze(0))
# output is unpooled, a (1, 512, 7, 7) shaped tensor
output = model.forward_head(output, pre_logits=True)
# output is a (1, num_features) shaped tensor
Model Comparison
ImageNet-1k validation accuracy at 224x224 as reported by OpenMMLab (source); not re-evaluated for this conversion. Params and GMACs are measured on the timm model. The evaluation transform of the source is: resize shorter edge to 236 (bicubic), center crop 224 (crop_pct=0.949).
| model |
params (M) |
GMACs |
top-1 (%) |
top-5 (%) |
| cspnext_tiny.rsb_a1_in1k |
2.73 |
0.34 |
69.44 |
89.45 |
| cspnext_s.rsb_a1_in1k |
4.89 |
0.66 |
74.41 |
92.23 |
| cspnext_m.rsb_a1_in1k |
13.05 |
1.92 |
79.27 |
94.79 |
| cspnext_l.rsb_a1_in1k |
27.16 |
4.18 |
81.30 |
95.62 |
| cspnext_x.rsb_a1_in1k |
48.85 |
7.73 |
82.10 |
95.69 |
Provenance and License
- Weights were converted to timm format from the OpenMMLab checkpoint listed under Original above
(key renaming only, no change to the tensor values). The model definition is a plain PyTorch
re-implementation adapted from MMDetection / MMPretrain.
- SHA-256 of the original checkpoint (
cspnext-s_imagenet_600e-ea671761.pth): ea671761304695cf6141962dd6e00aada667da5c4044f01ae328cd33a296bbc5
- The OpenMMLab checkpoints were trained on ImageNet-1k with the MMPretrain
rsb-a1 configs
(configs/rtmdet/classification/cspnext-*_8xb256-rsb-a1-600e_in1k.py; 600 epochs, Lamb optimizer).
- License: the MMDetection repository is released under Apache-2.0 (LICENSE,
Copyright 2018-2023 OpenMMLab) and its RTMDet classification README makes no separate license statement for the
checkpoints. They are therefore treated as Apache-2.0 here. This has not been confirmed with OpenMMLab: the same
question (open-mmlab/mmdetection#11484, opened 2024-02-20) had no reply from the
maintainers as of 2026-10-04. The training data, ImageNet-1k, is subject to its own terms of access.
Citation
@misc{lyu2022rtmdet,
title={RTMDet: An Empirical Study of Designing Real-Time Object Detectors},
author={Chengqi Lyu and Wenwei Zhang and Haian Huang and Yue Zhou and Yudong Wang and Yanyi Liu and Shilong Zhang and Kai Chen},
year={2022},
eprint={2212.07784},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}