项目介绍:tf_mobilenetv3_large_075.in1k
tf_mobilenetv3_large_075.in1k项目是一个关于图像分类的模型,属于MobileNet-v3家族。该模型在Tensorflow上通过ImageNet-1k数据集进行训练,并由Ross Wightman移植至PyTorch。
模型细节
tf_mobilenetv3_large_075.in1k是为图像分类而设计的,其主要特点如下:
- 模型类型: 图像分类 / 特征提取骨架
- 模型参数:
- 参数数量:4.0百万
- GMACs(十亿次乘加运算):0.2
- 激活数量:4.0百万
- 图像尺寸:224 x 224
- 论文: 搜索MobileNetV3: 论文链接
- 数据集: ImageNet-1k
- 原始实现: GitHub链接
模型使用
图像分类
要在Python中使用该模型来进行图像分类,首先从一个URL加载图像并应用模型,然后进行预测,代码如下:
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('tf_mobilenetv3_large_075.in1k', pretrained=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))
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
特征图提取
除了进行分类,该模型还可以用于特征图的提取,以下是相应的代码示例:
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(
'tf_mobilenetv3_large_075.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))
for o in output:
print(o.shape)
图像嵌入
如果只是需要图像嵌入,不需要分类器,可以通过以下代码实现:
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(
'tf_mobilenetv3_large_075.in1k',
pretrained=True,
num_classes=0,
)
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 = model.forward_features(transforms(img).unsqueeze(0))
output = model.forward_head(output, pre_logits=True)
模型比较
需要深入了解该模型的性能和与其他模型的对比,可以访问timm的模型结果页面。
引用
在研究工作中引用此项目的相关论文和资源:
@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}
}
@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}}
}
通过以上信息,使用者可以快速了解tf_mobilenetv3_large_075.in1k项目的特性及其在图像分类任务中的应用。