CreatorJarvis commited on
Commit
a96e937
ยท
verified ยท
1 Parent(s): baf2d35

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +154 -30
README.md CHANGED
@@ -1,58 +1,182 @@
1
  ---
2
  base_model: HuggingFaceTB/SmolVLM2-500M-Video-Instruct
3
  library_name: transformers
4
- model_name: smolvlm2-500m-FoodExtract-Vision
5
  tags:
6
- - generated_from_trainer
7
- - trl
 
 
 
 
8
  - sft
9
- licence: license
 
 
 
 
 
 
10
  ---
11
 
12
- # Model Card for smolvlm2-500m-FoodExtract-Vision
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- This model is a fine-tuned version of [HuggingFaceTB/SmolVLM2-500M-Video-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct).
15
- It has been trained using [TRL](https://github.com/huggingface/trl).
 
 
 
 
 
 
16
 
17
  ## Quick start
18
 
19
  ```python
20
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
- generator = pipeline("text-generation", model="None", device="cuda")
24
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
- print(output["generated_text"])
 
 
 
 
 
 
26
  ```
27
 
28
- ## Training procedure
29
 
30
- [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="150" height="24"/>](https://wandb.ai/jarviszhang-new-york-university/vlm-food-extraction/runs/we6trzon)
 
 
 
 
 
 
 
 
31
 
 
32
 
33
- This model was trained with SFT.
34
 
35
- ### Framework versions
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- - TRL: 0.27.1
38
- - Transformers: 4.57.6
39
- - Pytorch: 2.9.0+cu126
40
- - Datasets: 4.0.0
41
- - Tokenizers: 0.22.2
42
 
43
- ## Citations
 
 
 
 
44
 
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- Cite TRL as:
48
-
49
  ```bibtex
50
- @misc{vonwerra2022trl,
51
- title = {{TRL: Transformer Reinforcement Learning}},
52
- author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
53
- year = 2020,
54
- journal = {GitHub repository},
55
- publisher = {GitHub},
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
  ```