Image-Text-to-Text
Transformers
Safetensors
English
smolvlm
vision-language-model
vlm
image-to-text
structured-output
food-extraction
fine-tuned
sft
trl
conversational
Instructions to use CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune") model = AutoModelForMultimodalLM.from_pretrained("CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune
- SGLang
How to use CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune with Docker Model Runner:
docker model run hf.co/CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,58 +1,182 @@
|
|
| 1 |
---
|
| 2 |
base_model: HuggingFaceTB/SmolVLM2-500M-Video-Instruct
|
| 3 |
library_name: transformers
|
| 4 |
-
model_name:
|
| 5 |
tags:
|
| 6 |
-
-
|
| 7 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
- sft
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## Quick start
|
| 18 |
|
| 19 |
```python
|
| 20 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```
|
| 27 |
|
| 28 |
-
## Training procedure
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
- Transformers: 4.57.6
|
| 39 |
-
- Pytorch: 2.9.0+cu126
|
| 40 |
-
- Datasets: 4.0.0
|
| 41 |
-
- Tokenizers: 0.22.2
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
|
|
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
Cite TRL as:
|
| 48 |
-
|
| 49 |
```bibtex
|
| 50 |
-
@misc{
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 57 |
}
|
|
|
|
|
|
|
| 58 |
```
|
|
|
|
| 1 |
---
|
| 2 |
base_model: HuggingFaceTB/SmolVLM2-500M-Video-Instruct
|
| 3 |
library_name: transformers
|
| 4 |
+
model_name: FoodExtract-Vision-SmolVLM2-500M-fine-tune
|
| 5 |
tags:
|
| 6 |
+
- vision-language-model
|
| 7 |
+
- vlm
|
| 8 |
+
- image-to-text
|
| 9 |
+
- structured-output
|
| 10 |
+
- food-extraction
|
| 11 |
+
- fine-tuned
|
| 12 |
- sft
|
| 13 |
+
- trl
|
| 14 |
+
license: apache-2.0
|
| 15 |
+
datasets:
|
| 16 |
+
- mrdbourke/FoodExtract-1k-Vision
|
| 17 |
+
language:
|
| 18 |
+
- en
|
| 19 |
+
pipeline_tag: image-text-to-text
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# FoodExtract-Vision-SmolVLM2-500M
|
| 23 |
+
|
| 24 |
+
A fine-tuned Vision-Language Model for **structured food and drink extraction** from images. Given an input image, the model outputs a structured JSON containing food classification, image title, and extracted food/drink items.
|
| 25 |
+
|
| 26 |
+
## Model Description
|
| 27 |
+
|
| 28 |
+
| Attribute | Value |
|
| 29 |
+
|-----------|-------|
|
| 30 |
+
| **Base Model** | [SmolVLM2-500M-Video-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct) |
|
| 31 |
+
| **Training Method** | Supervised Fine-Tuning (SFT) |
|
| 32 |
+
| **Training Strategy** | Vision Encoder Frozen, LLM & Cross-Modal Connector Trainable |
|
| 33 |
+
| **Total Parameters** | 507M |
|
| 34 |
+
| **Trainable Parameters** | 421M (83%) |
|
| 35 |
+
| **Frozen Parameters** | 86M (17%) |
|
| 36 |
+
| **Precision** | bfloat16 |
|
| 37 |
+
|
| 38 |
+
## Intended Use
|
| 39 |
+
|
| 40 |
+
This model is designed for:
|
| 41 |
+
- ๐ **Food/Drink Classification**: Determine if an image contains food or drinks
|
| 42 |
+
- ๐ **Structured Data Extraction**: Extract food and drink items into JSON format
|
| 43 |
+
- ๐ท๏ธ **Image Captioning**: Generate food-related titles for images
|
| 44 |
+
|
| 45 |
+
### Output Format
|
| 46 |
|
| 47 |
+
```json
|
| 48 |
+
{
|
| 49 |
+
"is_food": 1,
|
| 50 |
+
"image_title": "macaron assortment",
|
| 51 |
+
"food_items": ["yellow macaron", "white macaron", "green macaron"],
|
| 52 |
+
"drink_items": []
|
| 53 |
+
}
|
| 54 |
+
```
|
| 55 |
|
| 56 |
## Quick start
|
| 57 |
|
| 58 |
```python
|
| 59 |
from transformers import pipeline
|
| 60 |
+
import torch
|
| 61 |
+
|
| 62 |
+
# Load the fine-tuned model
|
| 63 |
+
pipe = pipeline(
|
| 64 |
+
"image-text-to-text",
|
| 65 |
+
model="CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune",
|
| 66 |
+
dtype=torch.bfloat16,
|
| 67 |
+
device_map="auto"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# Prepare input message
|
| 71 |
+
message = [{
|
| 72 |
+
"role": "user",
|
| 73 |
+
"content": [
|
| 74 |
+
{"type": "image", "image": your_image}, # PIL.Image object
|
| 75 |
+
{"type": "text", "text": """Classify the given input image into food or not and if edible food or drink items are present, extract those to a list. If no food/drink items are visible, return empty lists.
|
| 76 |
|
| 77 |
+
Only return valid JSON in the following form:
|
| 78 |
+
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
'is_food': 0,
|
| 82 |
+
'image_title': '',
|
| 83 |
+
'food_items': [],
|
| 84 |
+
'drink_items': []
|
| 85 |
+
}
|
| 86 |
+
```} ] }]
|
| 87 |
```
|
| 88 |
|
|
|
|
| 89 |
|
| 90 |
+
## Training Details
|
| 91 |
+
|
| 92 |
+
### Dataset
|
| 93 |
+
|
| 94 |
+
| Split | Samples | Description |
|
| 95 |
+
|-------|---------|-------------|
|
| 96 |
+
| Train | 1,208 | 80% of total dataset |
|
| 97 |
+
| Validation | 302 | 20% of total dataset |
|
| 98 |
+
| **Total** | **1,510** | Food images (1k) + Non-food images (500) |
|
| 99 |
|
| 100 |
+
**Dataset Source**: [mrdbourke/FoodExtract-1k-Vision](https://huggingface.co/datasets/mrdbourke/FoodExtract-1k-Vision)
|
| 101 |
|
| 102 |
+
### Training Configuration
|
| 103 |
|
| 104 |
+
| Hyperparameter | Value |
|
| 105 |
+
|----------------|-------|
|
| 106 |
+
| Epochs | 4 |
|
| 107 |
+
| Batch Size (per device) | 4 |
|
| 108 |
+
| Gradient Accumulation Steps | 4 |
|
| 109 |
+
| Effective Batch Size | 16 |
|
| 110 |
+
| Learning Rate | 2e-4 |
|
| 111 |
+
| LR Scheduler | Constant |
|
| 112 |
+
| Warmup Ratio | 0.03 |
|
| 113 |
+
| Optimizer | AdamW (fused) |
|
| 114 |
+
| Max Grad Norm | 1.0 |
|
| 115 |
+
| Precision | bf16 |
|
| 116 |
+
| Gradient Checkpointing | โ |
|
| 117 |
|
| 118 |
+
### Training Strategy
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
The **Vision Encoder was frozen** during training to:
|
| 121 |
+
- Preserve pre-trained visual representations
|
| 122 |
+
- Reduce trainable parameters and memory usage
|
| 123 |
+
- Improve training stability on small datasets
|
| 124 |
+
- Mitigate overfitting
|
| 125 |
|
| 126 |
+
This approach is inspired by the [SmolDocling paper](https://arxiv.org/abs/2503.11576).
|
| 127 |
|
| 128 |
+
### Training Results
|
| 129 |
+
|
| 130 |
+
| Epoch | Training Loss | Validation Loss |
|
| 131 |
+
|-------|---------------|-----------------|
|
| 132 |
+
| 1 | 0.0842 | 0.0759 |
|
| 133 |
+
| 2 | 0.0816 | 0.0757 |
|
| 134 |
+
| 3 | 0.0237 | 0.0751 |
|
| 135 |
+
| 4 | 0.0172 | 0.0807 |
|
| 136 |
+
|
| 137 |
+
**Final Training Loss**: 0.0518
|
| 138 |
+
|
| 139 |
+
### Experiment Tracking
|
| 140 |
+
|
| 141 |
+
[<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="30"/>](https://wandb.ai/jarviszhang-new-york-university/vlm-food-extraction/runs/we6trzon)
|
| 142 |
+
|
| 143 |
+
## Demo
|
| 144 |
+
|
| 145 |
+
Try the model on Hugging Face Spaces:
|
| 146 |
+
|
| 147 |
+
๐ **[FoodExtract-Vision Demo](https://huggingface.co/spaces/CreatorJarvis/FoodExtract-Vision)**
|
| 148 |
+
|
| 149 |
+
The demo compares outputs from the base model vs. the fine-tuned model side-by-side.
|
| 150 |
+
|
| 151 |
+
## Limitations
|
| 152 |
+
|
| 153 |
+
- Trained on a relatively small dataset (1.5k images)
|
| 154 |
+
- May struggle with complex multi-item food scenes
|
| 155 |
+
- Occasional repetitive generation patterns
|
| 156 |
+
- Best performance on single-dish food images
|
| 157 |
+
|
| 158 |
+
## Framework Versions
|
| 159 |
+
|
| 160 |
+
| Library | Version |
|
| 161 |
+
|---------|---------|
|
| 162 |
+
| TRL | 0.27.1 |
|
| 163 |
+
| Transformers | 4.57.6 |
|
| 164 |
+
| PyTorch | 2.9.0+cu126 |
|
| 165 |
+
| Datasets | 4.0.0 |
|
| 166 |
+
| Tokenizers | 0.22.2 |
|
| 167 |
+
|
| 168 |
+
## Citation
|
| 169 |
+
|
| 170 |
+
If you use this model, please cite:
|
| 171 |
|
|
|
|
|
|
|
| 172 |
```bibtex
|
| 173 |
+
@misc{foodextract-vision-2025,
|
| 174 |
+
title = {FoodExtract-Vision: Fine-tuned SmolVLM2 for Structured Food Extraction},
|
| 175 |
+
author = {Jarvis Zhang},
|
| 176 |
+
year = 2025,
|
| 177 |
+
publisher = {Hugging Face},
|
| 178 |
+
howpublished = {\url{[https://huggingface.co/CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune](https://huggingface.co/CreatorJarvis/FoodExtract-Vision-SmolVLM2-500M-fine-tune)}}
|
|
|
|
| 179 |
}
|
| 180 |
+
|
| 181 |
+
|
| 182 |
```
|