# CSPNet (CSPResNet, CSPDarkNet, DarkNet)

**Category:** CNN · **Code:**
[`timm/models/cspnet.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/cspnet.py) ·
**Architectures:** 23 · **Pretrained weights:** 15 (15 with ImageNet-1k results)

Cross Stage Partial Networks split the features of each stage into two parts, one passing through the stage blocks and
one merged back at the end of the stage. This module holds CSPResNet, CSPResNeXt, CSPDarkNet, DarkNet and the `timm`
`cs3*` variants.

## Papers

* [CSPNet: A New Backbone that can Enhance Learning Capability of CNN](https://arxiv.org/abs/1911.11929)
* [YOLOv3: An Incremental Improvement](https://arxiv.org/abs/1804.02767)

## Usage

See the [Quickstart](../quickstart) for loading pretrained weights, image preprocessing and fine-tuning, and [Feature
Extraction](../feature_extraction) for using the models as backbones.

```py
>>> import timm
>>> model = timm.create_model('cspdarknet53.ra_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `CspNet` |
|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 2, 4, 8, 16, 32) |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✗ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✗ |
| [Any input size, no changes needed](../model_api#input-size) | ✓ |
| [`set_input_size()`](../model_api#input-size) | – |
| [`dynamic_img_size=True`](../model_api#input-size) | – |
| [`set_grad_checkpointing()`](../model_api#training-hooks) | ✗ |
| [Layer-wise LR decay (`group_matcher()`)](../model_api#training-hooks) | ✓ |
| [`reset_classifier()`](../model_api#classifier) | ✓ |

✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input
size). Checked by running each feature on a randomly initialized model (`CspNet` with `cs3darknet_focus_s` at 256),
other architectures of the same class are expected to behave the same. See the [Model API](../model_api) page for
details.

## Architectures

| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---:|---:|---:|---:|
| `cs3darknet_focus_l` | 21.15 | 4.66 | 256 | 1 |
| `cs3darknet_focus_m` | 9.30 | 1.98 | 256 | 1 |
| `cs3darknet_focus_s` | 3.27 | 0.69 | 256 | 1 |
| `cs3darknet_focus_x` | 35.02 | 8.03 | 256 | 0 |
| `cs3darknet_l` | 21.16 | 4.86 | 256 | 1 |
| `cs3darknet_m` | 9.31 | 2.08 | 256 | 1 |
| `cs3darknet_s` | 3.28 | 0.72 | 256 | 0 |
| `cs3darknet_x` | 35.05 | 8.38 | 256 | 1 |
| `cs3edgenet_x` | 47.82 | 11.53 | 256 | 1 |
| `cs3se_edgenet_x` | 50.72 | 11.53 | 256 | 1 |
| `cs3sedarknet_l` | 21.91 | 4.86 | 256 | 1 |
| `cs3sedarknet_x` | 35.40 | 8.38 | 256 | 1 |
| `cs3sedarknet_xdw` | 21.60 | 5.97 | 256 | 0 |
| `cspdarknet53` | 27.64 | 6.57 | 256 | 1 |
| `cspresnet50` | 21.62 | 4.54 | 256 | 1 |
| `cspresnet50d` | 21.64 | 4.86 | 256 | 0 |
| `cspresnet50w` | 28.12 | 5.04 | 256 | 0 |
| `cspresnext50` | 20.57 | 4.05 | 256 | 1 |
| `darknet17` | 14.30 | 3.26 | 256 | 0 |
| `darknet21` | 20.86 | 3.93 | 256 | 0 |
| `darknet53` | 41.61 | 9.31 | 256 | 1 |
| `darknetaa53` | 36.02 | 7.97 | 256 | 1 |
| `sedarknet21` | 20.95 | 3.93 | 256 | 0 |

GMACs and parameter counts are for the default input size and classifier of each architecture, from the [benchmark
results](https://github.com/huggingface/pytorch-image-models/tree/main/results).

## Pretrained weights

Top-1 is ImageNet-1k validation accuracy from
[`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv) at
the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the
size of the pretrained classifier, none for weights without one.

Weights are grouped by source: the paper or origin given in the pretrained config, else a Hub organization other than
`timm`, else the first part of the pretrained tag (`architecture.tag`). Sources with a single weight are listed under
other.

### `c2ns` tags

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `cs3darknet_focus_l.c2ns_in1k` | 256 (test 288) | 80.894 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_focus_l.c2ns_in1k) |
| `cs3darknet_focus_m.c2ns_in1k` | 256 (test 288) | 77.286 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_focus_m.c2ns_in1k) |
| `cs3darknet_l.c2ns_in1k` | 256 (test 288) | 80.882 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_l.c2ns_in1k) |
| `cs3darknet_m.c2ns_in1k` | 256 (test 288) | 77.636 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_m.c2ns_in1k) |
| `cs3darknet_x.c2ns_in1k` | 256 (test 288) | 82.234 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_x.c2ns_in1k) |
| `cs3se_edgenet_x.c2ns_in1k` | 256 (test 320) | 83.550 | 320 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3se_edgenet_x.c2ns_in1k) |
| `cs3sedarknet_l.c2ns_in1k` | 256 (test 288) | 81.770 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3sedarknet_l.c2ns_in1k) |
| `cs3sedarknet_x.c2ns_in1k` | 256 (test 288) | 82.654 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3sedarknet_x.c2ns_in1k) |
| `darknet53.c2ns_in1k` | 256 (test 288) | 80.542 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/darknet53.c2ns_in1k) |
| `darknetaa53.c2ns_in1k` | 256 (test 288) | 80.528 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/darknetaa53.c2ns_in1k) |

### `ra` tags

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `cspdarknet53.ra_in1k` | 256 | 80.078 | 256 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cspdarknet53.ra_in1k) |
| `cspresnet50.ra_in1k` | 256 | 79.578 | 256 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cspresnet50.ra_in1k) |
| `cspresnext50.ra_in1k` | 256 | 80.548 | 256 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cspresnext50.ra_in1k) |

### Other

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `cs3darknet_focus_s.ra4_e3600_r256_in1k` | 256 (test 320) | 73.158 | 320 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3darknet_focus_s.ra4_e3600_r256_in1k) |
| `cs3edgenet_x.c2_in1k` | 256 (test 288) | 82.734 | 288 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/cs3edgenet_x.c2_in1k) |

