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

MobileNetV3 Small 100 - Ascend NPU Adaptation

1. Introduction

MobileNetV3-Small is the small variant of the MobileNetV3 series, using 1.0x width multiplier to balance between lightness and accuracy. Suitable for mobile devices and edge computing. Trained on ImageNet-1K, input size 224x224.

Original model: timm/tf_mobilenetv3_small_100.in1k

  • Task type: Image Classification
  • Framework: PyTorch / timm
  • Input: RGB image, 224x224
  • Output: 1000-class ImageNet-1K logits and probabilities
  • Parameters: ~2.5M
  • Model size: 9.8 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_small_100.in1k --device cpu --output_dir ./tf_mobilenetv3_small_100.in1k

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

5. Inference Results

MetricCPUNPU (Ascend910)
Input size224x224224x224
Avg inference11.31 ms4.72 ms
Top-1 classclass 549class 549
Top-1 prob9.9340%9.9385%

NPU speedup: 2.4x vs CPU.

6. CPU/NPU Accuracy Comparison

Metrics

MetricValue
Max logits diff0.03542328
Mean logits diff0.00618965
Cosine Similarity0.999976
Max prob diff0.080875%
Mean prob diff0.000768%
Relative L2 error0.736410%
Top-1 matchYes
Top-5 overlap5/5

Top-5 predictions:

RankCPU classCPU probNPU classNPU prob
1class 5499.9340%class 5499.9385%
2class 4193.4130%class 4193.3843%
3class 6102.7593%class 6102.6784%
4class 8441.6866%class 8441.6531%
5class 7691.4895%class 7691.4814%

Conclusion

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

  • Cosine Similarity: 0.999976 (near 1.0)
  • Max prob difference: 0.0809%

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_small_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