mobilenetv3_small_100.lamb_in1k 项目介绍
项目概述
mobilenetv3_small_100.lamb_in1k 是一个基于 MobileNet-v3 架构的图像分类模型。该模型在 ImageNet-1k 数据集上进行了训练,使用了 timm
库中的特定训练方法。这个模型旨在提供高效且准确的图像分类功能,特别适合在资源受限的环境中使用。
模型特点
该模型具有以下几个显著特点:
-
轻量级设计:模型参数量仅为 2.5 百万,计算量为 0.1 GMACs,非常适合在移动设备或嵌入式系统中部署。
-
高效性能:尽管模型较小,但在 ImageNet-1k 数据集上仍能达到不错的分类效果。
-
灵活应用:除了图像分类,该模型还可以用于特征提取和图像嵌入等任务。
-
优化训练策略:采用了类似于 "ResNet Strikes Back" 的 LAMB 优化器配方,但训练时间延长了 50%,并使用了 EMA 权重平均。
使用方法
这个模型可以通过 timm
库轻松调用和使用。主要有三种使用方式:
-
图像分类:可以直接对输入图像进行分类,输出前五个最可能的类别及其概率。
-
特征图提取:通过设置
features_only=True
,模型可以输出不同层级的特征图,方便进行进一步的分析或处理。 -
图像嵌入:通过移除最后的分类层,模型可以输出图像的嵌入向量,这对于图像检索或迁移学习非常有用。
应用场景
mobilenetv3_small_100.lamb_in1k 模型适用于多种场景,包括但不限于:
- 移动设备上的实时图像分类
- 嵌入式系统中的视觉识别
- 大规模图像数据库的特征提取
- 计算资源有限的边缘计算设备
模型优势
- 轻量化:相比其他大型模型,该模型参数少,计算量小,更易部署。
- versatility:支持多种使用方式,适应不同的应用需求。
- 预训练可用:可直接使用在 ImageNet-1k 上预训练的权重,节省训练时间。
- 易于使用:通过
timm
库,只需几行代码即可完成模型加载和使用。
总结
mobilenetv3_small_100.lamb_in1k 是一个轻量级但功能强大的图像分类模型。它在保持高效性的同时,提供了良好的分类性能。无论是for研究目的还是实际应用,这个模型都是一个值得考虑的选择。通过 timm
库的支持,开发者可以方便地将其整合到各种计算机视觉项目中。
Model card for mobilenetv3_small_100.lamb_in1k
A MobileNet-v3 image classification model. Trained on ImageNet-1k in timm
using recipe template described below.
Recipe details:
- A LAMB optimizer recipe that is similar to ResNet Strikes Back
A2
but 50% longer with EMA weight averaging, no CutMix - RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
- Step (exponential decay w/ staircase) LR schedule with warmup
Model Details
- Model Type: Image classification / feature backbone
- Model Stats:
- Params (M): 2.5
- GMACs: 0.1
- Activations (M): 1.4
- Image size: 224 x 224
- Papers:
- Searching for MobileNetV3: https://arxiv.org/abs/1905.02244
- Dataset: ImageNet-1k
- Original: https://github.com/huggingface/pytorch-image-models
Model Usage
Image Classification
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('mobilenetv3_small_100.lamb_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(
'mobilenetv3_small_100.lamb_in1k',
pretrained=True,
features_only=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
for o in output:
# print shape of each feature map in output
# e.g.:
# torch.Size([1, 16, 112, 112])
# torch.Size([1, 16, 56, 56])
# torch.Size([1, 24, 28, 28])
# torch.Size([1, 48, 14, 14])
# torch.Size([1, 576, 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(
'mobilenetv3_small_100.lamb_in1k',
pretrained=True,
num_classes=0, # remove classifier nn.Linear
)
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)) # 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, 576, 7, 7) shaped tensor
output = model.forward_head(output, pre_logits=True)
# output is a (1, num_features) shaped tensor
Model Comparison
Explore the dataset and runtime metrics of this model in timm model results.
Citation
@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}}
}
@inproceedings{howard2019searching,
title={Searching for mobilenetv3},
author={Howard, Andrew and Sandler, Mark and Chu, Grace and Chen, Liang-Chieh and Chen, Bo and Tan, Mingxing and Wang, Weijun and Zhu, Yukun and Pang, Ruoming and Vasudevan, Vijay and others},
booktitle={Proceedings of the IEEE/CVF international conference on computer vision},
pages={1314--1324},
year={2019}
}