Food Segmentation Model (DeepLabV3+ with MobileNetV2)
A semantic segmentation model trained on the FoodSeg103 dataset for food image segmentation.
Model Description
- Architecture: DeepLabV3+ with MobileNetV2 encoder
- Backbone: MobileNetV2 (pretrained on ImageNet)
- Task: Semantic Segmentation
- Dataset: FoodSeg103 (103 food categories + background)
- Input Size: 512x512 RGB images
- Output: 104-class segmentation mask
Training Details
| Metric | Value |
|---|---|
| Best Validation Loss | 0.9726 |
| Best Validation mIoU | 23.33% |
| Training Epochs | 44 |
| Optimizer | AdamW (lr=1e-4, weight_decay=1e-2) |
| Scheduler | CosineAnnealingWarmRestarts |
| Loss Function | Dice Loss + Cross Entropy |
| Batch Size | 16 |
Usage
import torch
import segmentation_models_pytorch as smp
from huggingface_hub import hf_hub_download
# Download model weights
model_path = hf_hub_download(
repo_id="mawiie/food-segmentation-mobilenet",
filename="best_model.pth"
)
# Create model architecture
model = smp.DeepLabV3Plus(
encoder_name="mobilenet_v2",
encoder_weights=None, # We'll load our own weights
in_channels=3,
classes=104,
)
# Load trained weights
model.load_state_dict(torch.load(model_path, map_location="cpu"))
model.eval()
# Inference
# Normalize with ImageNet stats: mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)
# Input shape: (B, 3, 512, 512)
# Output shape: (B, 104, 512, 512)
Data Augmentation
Training:
- Horizontal flip (p=0.5)
- Vertical flip (p=0.1)
- Affine transforms (scale, rotate, shear)
- Random crop to 512x512
- Color augmentations (brightness, contrast, HSV)
- Gaussian blur
Validation:
- Center crop to 512x512
Framework
- PyTorch
- segmentation-models-pytorch
- Albumentations
License
MIT License