# GhostNet

**Category:** Efficient/Mobile · **Code:**
[`timm/models/ghostnet.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/ghostnet.py) ·
**Architectures:** 10 · **Pretrained weights:** 5 (5 with ImageNet-1k results)

GhostNet generates part of its feature maps with cheap operations (Ghost modules). GhostNetV2 adds DFC attention for
long-range dependencies, GhostNetV3 uses re-parameterization and knowledge distillation in training.

## Papers

* [GhostNet: More Features from Cheap Operations](https://arxiv.org/abs/1911.11907)
* [GhostNetV2: Enhance Cheap Operation with Long-Range Attention](https://arxiv.org/abs/2211.12905)
* [GhostNetV3: Exploring the Training Strategies for Compact Models](https://arxiv.org/abs/2404.11202)

## 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('ghostnetv2_160.in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `GhostNet` |
|---|---|
| [`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 (`GhostNet` with `ghostnet_050` at 224), 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 |
|---|---:|---:|---:|---:|
| `ghostnet_050` | 2.59 | 0.05 | 224 | 0 |
| `ghostnet_100` | 5.18 | 0.15 | 224 | 1 |
| `ghostnet_130` | 7.36 | 0.24 | 224 | 0 |
| `ghostnetv2_100` | 6.16 | 0.18 | 224 | 1 |
| `ghostnetv2_130` | 8.96 | 0.28 | 224 | 1 |
| `ghostnetv2_160` | 12.39 | 0.42 | 224 | 1 |
| `ghostnetv3_050` | 2.85 | 0.05 | 224 | 0 |
| `ghostnetv3_100` | 6.15 | 0.17 | 224 | 1 |
| `ghostnetv3_130` | 8.95 | 0.28 | 224 | 0 |
| `ghostnetv3_160` | 12.38 | 0.41 | 224 | 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.

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `ghostnet_100.in1k` | 224 | 73.958 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/ghostnet_100.in1k) |
| `ghostnetv2_100.in1k` | 224 | 75.186 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/ghostnetv2_100.in1k) |
| `ghostnetv2_130.in1k` | 224 | 76.746 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/ghostnetv2_130.in1k) |
| `ghostnetv2_160.in1k` | 224 | 77.836 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/ghostnetv2_160.in1k) |
| `ghostnetv3_100.in1k` | 224 | 76.936 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/ghostnetv3_100.in1k) |

