# GhostNet

**类别：** Efficient/Mobile · **代码：** [`timm/models/ghostnet.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/ghostnet.py) · **架构：** 10 · **预训练权重：** 5（其中 5 个包含 ImageNet-1k 结果）

GhostNet 使用廉价操作（Ghost 模块）生成部分特征图。GhostNetV2 引入了 DFC 注意力机制以处理长距离依赖关系，GhostNetV3 则在训练过程中采用了重参数化和知识蒸馏技术。

## 论文

* [GhostNet：通过廉价操作获取更多特征](https://arxiv.org/abs/1911.11907)
* [GhostNetV2：通过长程注意力增强廉价操作](https://arxiv.org/abs/2211.12905)
* [GhostNetV3：探索紧凑型模型的训练策略](https://arxiv.org/abs/2404.11202)

## 用法

请参阅[快速入门](../quickstart)了解如何加载预训练权重、进行图像预处理和微调，以及参阅[特征提取](../feature_extraction)了解如何将这些模型用作骨干网络。

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

## 模型 API 支持

| 功能 | `GhostNet` |
|---|---|
| [`features_only=True` 特征图](../model_api#intermediate-features) | ✓（步长 2、4、8、16、32） |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✓ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✓ |
| [任意输入尺寸，无需更改](../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) | ✓ |
| [逐层学习率衰减（`group_matcher()`）](../model_api#training-hooks) | ✓ |
| [`reset_classifier()`](../model_api#classifier) | ✓ |

✓ 支持，✓ (square) 仅支持方形尺寸，✗ 不支持，– 无需支持（模型本身已接受任意输入尺寸）。通过在每个功能上运行随机初始化的模型（`GhostNet` 使用 `ghostnet_050`，尺寸为 224）进行验证，预期同一类的其他架构表现相同。详情请参阅 [Model API](../model_api) 页面。

## 架构

| 架构 | 参数（M） | GMAC | 输入大小 | 预训练权重 |
|---|---:|---:|---:|---:|
| `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 和参数量对应于每种架构的默认输入大小和分类器，数据来自[基准测试结果](https://github.com/huggingface/pytorch-image-models/tree/main/results)。

## 预训练权重

Top-1 是在所列评估规模下，来自 [`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv) 的 ImageNet-1k 验证准确率，- 表示该权重没有 ImageNet-1k 结果（例如预训练权重或图文权重）。Classes 是预训练分类器的大小，对于没有分类器的权重则为无。

| 权重 | 输入大小 | Top-1（%） | 评估大小 | 类 | 许可证 | 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) |

