File size: 2,831 Bytes
8733a52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbeef0a
8733a52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
tags:
- image-classification
- timm
- MobileNetV4
license: apache-2.0
datasets:
- imagenet-1k
pipeline_tag: image-classification
---
# Model card for MobileNetV4_Conv_Small_TFLite_224

A MobileNet-V4 image classification model. Trained on ImageNet-1k by Ross Wightman.

Converted to TFLite Float32 & Float16 formats by Youssef Boulaouane.


## Model Details
- **Pytorch Weights:** https://huggingface.co/timm/mobilenetv4_conv_small.e2400_r224_in1k
- **Model Type:** Image classification
- **Model Stats:**
  - Params (M): 3.8
  - GMACs: 0.2
  - Activations (M): 2.0
  - Input Shape (1, 224, 224, 3) 
- **Dataset:** ImageNet-1k
- **Papers:**
  - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
  - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
- **Original:** https://github.com/tensorflow/models/tree/master/official/vision

## Model Usage
### Image Classification in Python
```python
import tensorflow as tf

# Load label file
with open('imagenet_classes.txt', 'r') as file:
    lines = file.readlines()

index_to_label = {index: line.strip() for index, line in enumerate(lines)}

# Initialize interpreter and IO details
tfl_model = tf.lite.Interpreter(model_path=tf_model_path)
tfl_model.allocate_tensors()
input_details = tfl_model.get_input_details()
output_details = tfl_model.get_output_details()

# Load and preprocess the image
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]

image = tf.image.resize(
    tf.image.decode_image(tf.io.read_file(image_path), channels=3),
    [256, 256],
    method="bicubic",
)
image = tf.image.central_crop(image, central_fraction=224.0/256.0)
image = (image - mean) / std

# Inference and postprocessing
input = input_details[0]
tfl_model.set_tensor(input["index"], image)
tfl_model.invoke()

tfl_output = tfl_model.get_tensor(output_details[0]["index"])
tfl_output_tensor = tf.convert_to_tensor(tfl_output)
tfl_softmax_output = tf.nn.softmax(tfl_output_tensor, axis=1)

tfl_top5_probs, tfl_top5_indices = tf.math.top_k(tfl_softmax_output, k=5)
```

### Deployment on Mobile
Refer to guides available here: https://ai.google.dev/edge/lite/inference

## Citation
```bibtex
@article{qin2024mobilenetv4,
  title={MobileNetV4-Universal Models for the Mobile Ecosystem},
  author={Qin, Danfeng and Leichner, Chas and Delakis, Manolis and Fornoni, Marco and Luo, Shixin and Yang, Fan and Wang, Weijun and Banbury, Colby and Ye, Chengxi and Akin, Berkin and others},
  journal={arXiv preprint arXiv:2404.10518},
  year={2024}
}
```
```bibtex
@misc{rw2019timm,
  author = {Ross Wightman},
  title = {PyTorch Image Models},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  doi = {10.5281/zenodo.4414861},
  howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}
```