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

MobileNetV3 Small Minimal 100 - Ascend NPU Adaptation

1. Introduction

MobileNetV3-Small-Minimal is the lightest variant of the MobileNetV3 series, using Minimal design to further simplify the network structure while providing image classification capability with minimal computation. Trained on ImageNet-1K, input size 224x224.

Original model: timm/tf_mobilenetv3_small_minimal_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: 7.9 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_minimal_100.in1k --device cpu --output_dir ./tf_mobilenetv3_small_minimal_100.in1k

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

5. Inference Results

MetricCPUNPU (Ascend910)
Input size224x224224x224
Avg inference9.60 ms3.55 ms
Top-1 classclass 111class 111
Top-1 prob1.9474%1.9989%

NPU speedup: 2.7x vs CPU.

6. CPU/NPU Accuracy Comparison

Metrics

MetricValue
Max logits diff0.04073763
Mean logits diff0.00937892
Cosine Similarity0.999930
Max prob diff0.051434%
Mean prob diff0.001003%
Relative L2 error1.224621%
Top-1 matchYes
Top-5 overlap5/5

Top-5 predictions:

RankCPU classCPU probNPU classNPU prob
1class 1111.9474%class 1111.9989%
2class 6441.5847%class 6441.6216%
3class 4991.5195%class 4991.5134%
4class 9161.4519%class 9161.4584%
5class 5491.4026%class 5491.3951%

Conclusion

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

  • Cosine Similarity: 0.999930 (near 1.0)
  • Max prob difference: 0.0514%

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