byoussef commited on
Commit
a5dfefa
1 Parent(s): 99ed9fd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +103 -0
README.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ - MobileNetV4
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ pipeline_tag: image-classification
10
+ ---
11
+ # Model card for MobileNetV4_Conv_Medium_TFLite_224
12
+
13
+ A MobileNet-V4 image classification model. Trained on ImageNet-1k by Ross Wightman.
14
+
15
+ Converted to TFLite Float32 & Float16 formats by Youssef Boulaouane.
16
+
17
+
18
+ ## Model Details
19
+ - **Pytorch Weights:** https://huggingface.co/timm/mobilenetv4_conv_medium.e500_r224_in1k
20
+ - **Model Type:** Image classification
21
+ - **Model Stats:**
22
+ - Params (M): 9.7
23
+ - GMACs: 0.8
24
+ - Activations (M): 5.8
25
+ - Input Shape (1, 224, 224, 3)
26
+ - **Dataset:** ImageNet-1k
27
+ - **Papers:**
28
+ - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
29
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
30
+ - **Original:** https://github.com/tensorflow/models/tree/master/official/vision
31
+
32
+ ## Model Usage
33
+ ### Image Classification in Python
34
+ ```python
35
+ import numpy as np
36
+ import tensorflow as tf
37
+ from PIL import Image
38
+
39
+ # Load label file
40
+ with open('imagenet_classes.txt', 'r') as file:
41
+ lines = file.readlines()
42
+
43
+ index_to_label = {index: line.strip() for index, line in enumerate(lines)}
44
+
45
+ # Initialize interpreter and IO details
46
+ tfl_model = tf.lite.Interpreter(model_path=tf_model_path)
47
+ tfl_model.allocate_tensors()
48
+ input_details = tfl_model.get_input_details()
49
+ output_details = tfl_model.get_output_details()
50
+
51
+ # Load and preprocess the image
52
+ image = Image.open(image_path).resize((224, 224), Image.BICUBIC)
53
+
54
+ image = np.array(image, dtype=np.float32)
55
+ mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
56
+ std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
57
+ image = (image / 255.0 - mean) / std
58
+
59
+ image = np.expand_dims(image, axis=-1)
60
+ image = np.rollaxis(image, 3)
61
+
62
+ # Inference and postprocessing
63
+ input = input_details[0]
64
+ tfl_model.set_tensor(input["index"], image)
65
+ tfl_model.invoke()
66
+
67
+ tfl_output = tfl_model.get_tensor(output_details[0]["index"])
68
+ tfl_output_tensor = tf.convert_to_tensor(tfl_output)
69
+ tfl_softmax_output = tf.nn.softmax(tfl_output_tensor, axis=1)
70
+
71
+ tfl_top5_probs, tfl_top5_indices = tf.math.top_k(tfl_softmax_output, k=5)
72
+
73
+ # Get the top5 class labels and probabilities
74
+ tfl_probs_list = tfl_top5_probs[0].numpy().tolist()
75
+ tfl_index_list = tfl_top5_indices[0].numpy().tolist()
76
+
77
+ for index, prob in zip(tfl_index_list, tfl_probs_list):
78
+ print(f"{index_to_label[index]}: {round(prob*100, 2)}%")
79
+ ```
80
+
81
+ ### Deployment on Mobile
82
+ Refer to guides available here: https://ai.google.dev/edge/lite/inference
83
+
84
+ ## Citation
85
+ ```bibtex
86
+ @article{qin2024mobilenetv4,
87
+ title={MobileNetV4-Universal Models for the Mobile Ecosystem},
88
+ 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},
89
+ journal={arXiv preprint arXiv:2404.10518},
90
+ year={2024}
91
+ }
92
+ ```
93
+ ```bibtex
94
+ @misc{rw2019timm,
95
+ author = {Ross Wightman},
96
+ title = {PyTorch Image Models},
97
+ year = {2019},
98
+ publisher = {GitHub},
99
+ journal = {GitHub repository},
100
+ doi = {10.5281/zenodo.4414861},
101
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
102
+ }
103
+ ```