You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co./docs/hub/model-cards#model-card-metadata)

MobileNetV2

MobileNetV2 是在分辨率 224x224 的 ImageNet-1k 数据集上预训练的图像分类模型。https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet

我们开发了一个 AMD Ryzen AI (https://ryzenai.docs.amd.com/en/latest/) 支持的修改版本 - https://huggingface.co./models?search=mobilenet_v2

详情可参照 https://huggingface.co./amd/mobilenet_v2_1.0_224

安装

按照 https://ryzenai.docs.amd.com/en/latest/inst.html 为 Ryzen AI 准备环境。

运行以下脚本安装pre-requisites包


pip install -r requirements.txt

推理

推理一张图片


import sys
import onnxruntime
import torch
import torchvision.transforms as transforms 
from PIL import Image

image_path = sys.argv[1]
onnx_model = sys.argv[2]

normalize = transforms.Normalize(
  mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
img_transformer = transforms.Compose([
                transforms.Resize(256),
                transforms.CenterCrop(224),
                transforms.ToTensor(),  
                normalize])
img_tensor = img_transformer(Image.open(image_path)).unsqueeze(0)
img_tensor = torch.permute(img_tensor, (0, 2, 3, 1))
so = onnxruntime.SessionOptions()
ort_session = onnxruntime.InferenceSession(
        onnx_model, so, 
        providers=['CPUExecutionProvider'], 
        provider_options=None)
input = img_tensor.numpy()
ort_input = {ort_session.get_inputs()[0].name: input}

output = ort_session.run(None, ort_input)
top5_probabilities, top5_class_indices = torch.topk(torch.nn.functional.softmax(torch.tensor(output[0])), k=5)

vaip_config.json 来自于Ryzen AI 安装包 https://ryzenai.docs.amd.com/en/latest/inst.html, voe-4.0-win_amd64 of ryzen-ai-sw-1.0.zip.

使用 eval_onnx.py 推理 ImageNet validation dataset (50,000 Images).

测试量化模型CPU


python eval_onnx.py  --onnx_model=./mobilenetv2_int8.onnx --data_dir=./{DATA_PATH}

测试量化模型IPU


python eval_onnx.py  --onnx_model=./mobilenetv2_int8.onnx --data_dir=./{DATA_PATH} --ipu --provider_config Path\To\vaip_config.json

Metric	Accuracy on IPU
top1& top5 accuracy	75.62% / 92.52%

DATA_PATH: ImageNet validation目录

引用


@article{MobileNet v2,
  author       = {Mark Sandler and
                  Andrew G. Howard and
                  Menglong Zhu and
                  Andrey Zhmoginov and
                  Liang{-}Chieh Chen},
  title        = {MobileNetV2: Inverted Residuals and Linear Bottlenecks},
  year         = {2018},
  url          = {http://arxiv.org/abs/1801.04381},
}
Downloads last month
5
Safetensors
Model size
8.99B params
Tensor type
BF16
·
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.

Space using DQLiu/rrferrglgf-NLP 1