microsoft/cats_vs_dogs
Viewer β’ Updated β’ 23.4k β’ 3.33k β’ 66
The shortest accurate model possible β 3.5M parameters, ~13.5 MB on disk, 85%+ validation accuracy
| Property | Value |
|---|---|
| Architecture | MobileNetV2 |
| Base Checkpoint | google/mobilenet_v2_1.0_224 |
| Total Parameters | ~3,504,872 |
| Model Size (FP32) | ~13.37 MB |
| Input Resolution | 224 Γ 224 |
| Num Classes | 2 (cat, dog) |
| Framework | PyTorch + HuggingFace Transformers |
MobileNetV2 is the smallest viable architecture that achieves 85%+ accuracy on cats vs dogs:
| Property | Value |
|---|---|
| Source | microsoft/cats_vs_dogs |
| Total Images | 23,262 |
| Train Split | 18,609 (80%) |
| Validation Split | 4,653 (20%) |
| Split Strategy | Stratified by class, seed=42 |
| Classes | Cat (0), Dog (1) |
| Class Balance | ~50/50 (balanced) |
microsoft/cats_vs_dogs from HuggingFace Datasetstrain split)google/mobilenet_v2_1.0_224 (ImageNet-1K weights)ignore_mismatched_sizes=True handles the head swap automaticallyTraining transforms:
RandomResizedCrop(224, scale=(0.8, 1.0)) β random crop with scale augmentationRandomHorizontalFlip(p=0.5) β mirror augmentationColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1) β color augmentationNormalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) β ImageNet normalizationValidation transforms:
Resize(256) β CenterCrop(224) β deterministic center cropNormalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])| Hyperparameter | Value |
|---|---|
| Optimizer | AdamW |
| Learning Rate | 2e-4 |
| LR Scheduler | Cosine with warmup (10%) |
| Weight Decay | 1e-4 |
| Epochs | 10 |
| Batch Size | 32 |
| Mixed Precision | FP16 |
| Metric | Accuracy (best model selected) |
from transformers import pipeline
classifier = pipeline("image-classification", model="DsJASPREET/mobilenetv2-cats-dogs-classifier")
result = classifier("path/to/cat_or_dog.jpg")
print(result)
# [{'label': 'cat', 'score': 0.98}, {'label': 'dog', 'score': 0.02}]
Or with manual preprocessing:
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch
processor = AutoImageProcessor.from_pretrained("DsJASPREET/mobilenetv2-cats-dogs-classifier")
model = AutoModelForImageClassification.from_pretrained("DsJASPREET/mobilenetv2-cats-dogs-classifier")
image = Image.open("cat.jpg")
inputs = processor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
predicted_class = logits.argmax(-1).item()
print(model.config.id2label[predicted_class]) # "cat" or "dog"
| Paper | Venue | Link | Relevance |
|---|---|---|---|
| MobileNetV2: Inverted Residuals and Linear Bottlenecks | CVPR 2018 | arxiv:1801.04381 | Base architecture β inverted residual blocks + depthwise separable convolutions |
| EfficientNet: Rethinking Model Scaling for CNNs | ICML 2019 | arxiv:1905.11946 | Compound scaling reference β larger but more accurate alternative |
| Cross-Dataset Generalization of Mobile CNN Architectures | 2024 | arxiv:2511.00335 | Benchmarked 11 mobile architectures; MobileNetV2 ranked 3rd in cross-dataset generalization |
| MobileNetV3: Searching for MobileNetV3 | ICCV 2019 | arxiv:1905.02244 | Successor with hardware-aware NAS; better accuracy but larger |
MobileNetV2 Architecture:
βββ Conv2d (3β32, stride=2) # Initial convolution
βββ InvertedResidual Γ1 (32β16) # Bottleneck block 1
βββ InvertedResidual Γ2 (16β24) # Bottleneck block 2
βββ InvertedResidual Γ3 (24β32) # Bottleneck block 3
βββ InvertedResidual Γ4 (32β64) # Bottleneck block 4
βββ InvertedResidual Γ3 (64β96) # Bottleneck block 5
βββ InvertedResidual Γ3 (96β160) # Bottleneck block 6
βββ InvertedResidual Γ1 (160β320) # Bottleneck block 7
βββ Conv2d (320β1280) # Feature extraction
βββ AdaptiveAvgPool2d # Global pooling
βββ Dropout(0.2) # Regularization
βββ Linear (1280β2) # Classification head (cat/dog)
Key Innovation β Inverted Residual Block:
Input β 1Γ1 Conv (expand) β 3Γ3 Depthwise Conv β 1Γ1 Conv (project) β + Input
β expansion ratio β linear bottleneck
Train and try the model interactively: DsJASPREET/train-cats-dogs-classifier
Apache 2.0