mobilenet_v2_1.0_224
googleIntroduction
MobileNet V2 is a model pre-trained on ImageNet-1k, designed for efficient image classification with low latency and low power consumption, making it suitable for mobile and resource-constrained environments. It builds on the concept of MobileNets to balance latency, size, and accuracy for various use cases.
Architecture
MobileNet V2 employs an architecture characterized by inverted residuals and linear bottlenecks, allowing it to efficiently execute on mobile devices. The model is parameterized with a depth multiplier and input resolution, e.g., mobilenet_v2_1.0_224
, where 1.0
is the depth multiplier and 224
is the input image resolution.
Training
The MobileNet V2 model is pre-trained on the ImageNet-1k dataset, allowing it to classify images into one of 1000 classes, with an additional class for the "background."
Guide: Running Locally
To run MobileNet V2 locally, follow these steps:
-
Install Requirements: Ensure you have Python installed, along with the Hugging Face Transformers library and PyTorch.
pip install transformers torch pillow requests
-
Load the Model: Use the following code to load and test the model on an example image.
from transformers import AutoImageProcessor, AutoModelForImageClassification from PIL import Image import requests url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw) preprocessor = AutoImageProcessor.from_pretrained("google/mobilenet_v2_1.0_224") model = AutoModelForImageClassification.from_pretrained("google/mobilenet_v2_1.0_224") inputs = preprocessor(images=image, return_tensors="pt") outputs = model(**inputs) logits = outputs.logits predicted_class_idx = logits.argmax(-1).item() print("Predicted class:", model.config.id2label[predicted_class_idx])
-
Cloud GPUs: For faster inference, consider using cloud-based GPU services like AWS EC2, Google Cloud, or Azure, which provide powerful computational resources.
License
The MobileNet V2 model is available under an "other" license, which may have specific restrictions or requirements. Users should review the licensing terms provided with the model.