Files
enginex-bi_series-vc-cnn/README.md
2025-08-15 10:51:29 +08:00

65 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# image-classification-transformers
## 天数智芯 天垓100 视觉分类
transformers框架支持多种图像分类模型现对天垓100加速卡进行transformers框架的适配并且带入到信创算力测试框架中。将视觉分类模型放在天数卡天垓100上运行且测试性能与CPU(4c)运行结果对比注意该测试框架下的模型需适配transformers库。
使用 Hugging Face 的transformers库加载预训练模型支持同时使用 CPU 和 GPU 进行图像分类推理。
## 视觉分类模型测试服务原理
使用Hugging Face transformers库中的工具类AutoImageProcessor 和AutoModelForImageClassification
AutoImageProcessor用于自动加载与预训练模型配套的图像处理器。与预训练模型绑定通过from_pretrained(model_path)加载时,会自动读取模型训练时使用的预处理配置(如尺寸、归一化参数等),负责图像预处理(如尺寸调整、归一化等)。
AutoModelForImageClassification是一个 “自动模型类”,会根据预训练模型的类型(如 ViT、ResNet 等自动加载对应的网络结构。AutoModelForImageClassification.from_pretrained(model_path)从model_path加载预训练的图像分类模型必须接收AutoImageProcessor处理后的张量作为输入。
AutoModelForImageClassification执行图像分类的核心计算输入预处理后的张量输出分类结果如类别概率
## 如何使用 视觉分类 模型测试框架
代码实现了一个接收图像并返回概率最高的类别作为最终分类结果的视觉分类 HTTP 服务,并基于 zibo.harbor.iluvatar.com.cn:30000/saas/bi100-3.2.1-x86-ubuntu20.04-py3.10-poc-llm-infer:v1.2.2 基础镜像,将该 HTTP 服务重新打包成 docker 镜像,通过 k8s 集群sut容器去请求这个 HTTP 服务。
该框架 已测试适配的 视觉分类 模型类型有:
1、卷积神经网络CNNResNet
2、Transformer 类ViTVision Transformer、Swin Transformer、DeiTData-efficient Image Transformers、BEiTBERT Pre-training of Image Transformers
3、 轻量级模型MobileNet 系列
4、其他特殊设计ConvNeXt
## 视觉分类 模型测试服务请求示例
```python
import requests
# 服务地址(根据实际部署修改)
BASE_URL = "http://localhost:80"
PREDICT_ENDPOINT = "/v1/private/s782b4996"
# 本地图片路径(替换为你的图片路径)
IMAGE_PATH = "test_image.jpg"
# 读取图片文件并发送请求
with open(IMAGE_PATH, "rb") as f:
files = {"image": f} # 键名必须为 "image",与服务端接收字段一致
response = requests.post(f"{BASE_URL}{PREDICT_ENDPOINT}", files=files)
# 打印响应结果
print("预测接口响应状态码:", response.status_code)
print("预测结果:")
print(response.json())
```
## 天垓100视觉分类模型适配情况
| 模型地址 | 类型 | 适配状态 | 天垓100准确率 | 天垓100吞吐量张/秒) | cpu准确率 | cpu吞吐量4C张/秒) | Submit Id |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| https://www.modelscope.cn/models/apple/mobilevit-x-small | MobileViT | 成功 | 22.6667% | 31.6415 | 22.6667% | 2.6574 | 249973 |
| https://www.modelscope.cn/models/facebook/convnextv2-tiny-22k-384 | ConvNeXt V2ConvNeXt 模型的改进版本) | 成功 | 29.3333% | 25.1330 | 29.3333% | 0.7301 | 249985 |
| https://www.modelscope.cn/models/google/vit-base-patch16-224 | ViTVision Transformer | 成功 | 29.3333% | 40.0226 | 29.3333% | 1.1306 | 249992 |
| https://www.modelscope.cn/models/microsoft/beit-base-patch16-224-pt22k-ft22k | BEiTBERT Pre-training of Image Transformers | 成功 | 34.0000% | 23.7485 | 34.0000% | 0.9773 | 249537 |
| https://www.modelscope.cn/models/microsoft/swinv2-tiny-patch4-window16-256 | Swin Transformer V2基于Swin Transformer | 成功 | 29.3333% | 13.8379 | 29.3333% | 1.0331 | 249557 |
| https://www.modelscope.cn/models/timm/mobilenetv3_small_100.lamb_in1k | MobileNetV3Google 提出的 MobileNet 系列第三代) | 失败 | | | | | 250057 |
| https://www.modelscope.cn/models/timm/resnet50.a1_in1k | ResNetResidual Network | 失败 | | | | | 250004 |
| https://www.modelscope.cn/models/facebook/deit-small-patch16-224 | DeiTData-efficient Image Transformer由 Facebook AI 提出 | 成功 | 29.3333% | 40.5675 | 29.3333% | 3.2749 | 250034 |
| https://www.modelscope.cn/models/microsoft/dit-base-finetuned-rvlcdip | DiT(Document Image Transformer) | 成功 | 0.0000% | 35.5122 | 0.0000% | 1.0823 | 250035 |
| https://www.modelscope.cn/models/microsoft/cvt-13 | CvT(Convolutional Vision Transformer) | 成功 | 29.3333% | 27.1214 | 29.3333% | 1.7240 | 250039 |
| https://www.modelscope.cn/models/google/efficientnet-b7 | EfficientNet 架构基于卷积神经网络CNN | 成功 | 28.6667% | 10.0449 | 28.6667% | 0.1541 | 250042 |
| https://www.modelscope.cn/models/microsoft/resnet-18 | ResNetResidual Network | 成功 | 22.6667% | 43.5976 | 22.6667% | 7.3915 | 250047 |