byoussef's picture
Update README.md
4a4d504 verified
|
raw
history blame
2.83 kB
metadata
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

Model Usage

Image Classification in 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

@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}
}
@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}}
}