Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-segmentation
|
| 5 |
+
- food-segmentation
|
| 6 |
+
- pytorch
|
| 7 |
+
- segmentation-models-pytorch
|
| 8 |
+
- deeplabv3plus
|
| 9 |
+
- mobilenetv2
|
| 10 |
+
datasets:
|
| 11 |
+
- foodseg103
|
| 12 |
+
metrics:
|
| 13 |
+
- iou
|
| 14 |
+
library_name: segmentation-models-pytorch
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Food Segmentation Model (DeepLabV3+ with MobileNetV2)
|
| 18 |
+
|
| 19 |
+
A semantic segmentation model trained on the FoodSeg103 dataset for food image segmentation.
|
| 20 |
+
|
| 21 |
+
## Model Description
|
| 22 |
+
|
| 23 |
+
- **Architecture:** DeepLabV3+ with MobileNetV2 encoder
|
| 24 |
+
- **Backbone:** MobileNetV2 (pretrained on ImageNet)
|
| 25 |
+
- **Task:** Semantic Segmentation
|
| 26 |
+
- **Dataset:** FoodSeg103 (103 food categories + background)
|
| 27 |
+
- **Input Size:** 512x512 RGB images
|
| 28 |
+
- **Output:** 104-class segmentation mask
|
| 29 |
+
|
| 30 |
+
## Training Details
|
| 31 |
+
|
| 32 |
+
| Metric | Value |
|
| 33 |
+
|--------|-------|
|
| 34 |
+
| **Best Validation Loss** | 0.9726 |
|
| 35 |
+
| **Best Validation mIoU** | 23.33% |
|
| 36 |
+
| **Training Epochs** | 44 |
|
| 37 |
+
| **Optimizer** | AdamW (lr=1e-4, weight_decay=1e-2) |
|
| 38 |
+
| **Scheduler** | CosineAnnealingWarmRestarts |
|
| 39 |
+
| **Loss Function** | Dice Loss + Cross Entropy |
|
| 40 |
+
| **Batch Size** | 16 |
|
| 41 |
+
|
| 42 |
+
## Usage
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
import torch
|
| 46 |
+
import segmentation_models_pytorch as smp
|
| 47 |
+
from huggingface_hub import hf_hub_download
|
| 48 |
+
|
| 49 |
+
# Download model weights
|
| 50 |
+
model_path = hf_hub_download(
|
| 51 |
+
repo_id="mawiie/food-segmentation-mobilenet",
|
| 52 |
+
filename="best_model.pth"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Create model architecture
|
| 56 |
+
model = smp.DeepLabV3Plus(
|
| 57 |
+
encoder_name="mobilenet_v2",
|
| 58 |
+
encoder_weights=None, # We'll load our own weights
|
| 59 |
+
in_channels=3,
|
| 60 |
+
classes=104,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# Load trained weights
|
| 64 |
+
model.load_state_dict(torch.load(model_path, map_location="cpu"))
|
| 65 |
+
model.eval()
|
| 66 |
+
|
| 67 |
+
# Inference
|
| 68 |
+
# Normalize with ImageNet stats: mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)
|
| 69 |
+
# Input shape: (B, 3, 512, 512)
|
| 70 |
+
# Output shape: (B, 104, 512, 512)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
## Data Augmentation
|
| 74 |
+
|
| 75 |
+
**Training:**
|
| 76 |
+
- Horizontal flip (p=0.5)
|
| 77 |
+
- Vertical flip (p=0.1)
|
| 78 |
+
- Affine transforms (scale, rotate, shear)
|
| 79 |
+
- Random crop to 512x512
|
| 80 |
+
- Color augmentations (brightness, contrast, HSV)
|
| 81 |
+
- Gaussian blur
|
| 82 |
+
|
| 83 |
+
**Validation:**
|
| 84 |
+
- Center crop to 512x512
|
| 85 |
+
|
| 86 |
+
## Framework
|
| 87 |
+
|
| 88 |
+
- PyTorch
|
| 89 |
+
- segmentation-models-pytorch
|
| 90 |
+
- Albumentations
|
| 91 |
+
|
| 92 |
+
## License
|
| 93 |
+
|
| 94 |
+
MIT License
|