m0_74196153/tf_mobilenetv3_large_100-in1k-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MobileNetV3 Large 100 - Ascend NPU Adaptation

1. Introduction

MobileNetV3-Large is the standard large model variant of the MobileNetV3 series, using 1.0x width multiplier to provide the best classification accuracy in the series. Suitable for scenarios requiring high precision. Trained on ImageNet-1K, input size 224x224.

Original model: timm/tf_mobilenetv3_large_100.in1k

  • Task type: Image Classification
  • Framework: PyTorch / timm
  • Input: RGB image, 224x224
  • Output: 1000-class ImageNet-1K logits and probabilities
  • Parameters: ~5.5M
  • Model size: 21.1 MB

2. Environment

ComponentVersion
NPUAscend910
CANN25.5.2
PyTorch2.9.0
torch_npu2.9.0
timm1.0.27
Python3.11.14
OSLinux (aarch64)

3. Setup

pip install torch torchvision timm Pillow numpy modelscope safetensors
export MODELSCOPE_CACHE=/tmp/modelscope

4. Inference

# CPU inference
python3 inference.py --model_name tf_mobilenetv3_large_100.in1k --device cpu --output_dir ./tf_mobilenetv3_large_100.in1k

# NPU inference
python3 inference.py --model_name tf_mobilenetv3_large_100.in1k --device npu --output_dir ./tf_mobilenetv3_large_100.in1k

5. Inference Results

MetricCPUNPU (Ascend910)
Input size224x224224x224
Avg inference28.72 ms5.76 ms
Top-1 classclass 549class 549
Top-1 prob5.3541%5.2919%

NPU speedup: 5.0x vs CPU.

6. CPU/NPU Accuracy Comparison

Metrics

MetricValue
Max logits diff0.03052139
Mean logits diff0.00427881
Cosine Similarity0.999983
Max prob diff0.062194%
Mean prob diff0.000608%
Relative L2 error0.584360%
Top-1 matchYes
Top-5 overlap5/5

Top-5 predictions:

RankCPU classCPU probNPU classNPU prob
1class 5495.3541%class 5495.2919%
2class 4091.9407%class 4091.9352%
3class 4461.6589%class 4461.6405%
4class 7721.2364%class 7721.2441%
5class 8921.2053%class 8921.1960%

Conclusion

NPU vs CPU error < 1%. All metrics show NPU results match CPU:

  • Cosine Similarity: 0.999983 (near 1.0)
  • Max prob difference: 0.0622%

7. Screenshot

inference

8. Deployment

import torch
import timm
from PIL import Image
from timm.data import create_transform, resolve_data_config

model = timm.create_model('tf_mobilenetv3_large_100.in1k', pretrained=True)
model.eval()

if torch.npu.is_available():
    model = model.npu()

transform = create_transform(**resolve_data_config(model.pretrained_cfg, model=model))
img = Image.open('image.jpg').convert('RGB')
input_tensor = transform(img).unsqueeze(0)

if torch.npu.is_available():
    input_tensor = input_tensor.npu()

with torch.no_grad():
    logits = model(input_tensor)
    probs = torch.nn.functional.softmax(logits, dim=-1)

top5 = torch.topk(probs, k=5)
for i in range(5):
    print(f"class {top5.indices[0][i].item()}: {top5.values[0][i].item()*100:.2f}%")

9. Notes

  1. Model auto-downloads from ModelScope on first run
  2. Verify torch.npu.is_available() before NPU inference
  3. NPU memory is auto-released after inference
  4. For NPU OOM, reduce num_runs in inference.py
  5. This is a TensorFlow-trained MobileNetV3 variant loaded via PyTorch/timm