byoussef commited on
Commit
7450fff
1 Parent(s): c7563f5

Create README.md

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