ibrahimdaud commited on
Commit
4d82f7a
·
verified ·
1 Parent(s): d2d7bb5

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +152 -18
README.md CHANGED
@@ -4,6 +4,7 @@ tags:
4
  - image-classification
5
  - food-recognition
6
  - raw-food
 
7
  - pytorch
8
  - resnet
9
  - se-resnet
@@ -11,28 +12,41 @@ tags:
11
  - model-comparison
12
  datasets:
13
  - ibrahimdaud/raw-food-recognition
 
14
  metrics:
15
  - accuracy
 
 
16
  ---
17
 
18
- # Raw Food Recognition Models: ResNet-50 vs SE-ResNet-50
19
 
20
- This repository contains both ResNet-50 and SE-ResNet-50 models trained for raw food ingredient recognition using the merged raw food recognition dataset.
21
 
22
- ## Model Comparison
23
 
24
- | Model | Parameters | Validation Accuracy | Architecture |
25
- |-------|-----------|-------------------|--------------|
26
- | ResNet-50 | ~25.6M | 97.84% | Standard residual network |
27
- | SE-ResNet-50 | ~26.0M | 95.72% | ResNet-50 with SE attention |
28
 
29
- ## Dataset
 
 
 
 
30
 
31
  Both models were trained on the [ibrahimdaud/raw-food-recognition](https://huggingface.co/datasets/ibrahimdaud/raw-food-recognition) dataset, which contains 90+ raw food categories.
32
 
 
 
 
 
 
 
 
 
 
 
33
  ## Usage
34
 
35
- ### Download Both Models
36
 
37
  ```python
38
  from huggingface_hub import hf_hub_download
@@ -55,7 +69,7 @@ se_resnet_path = hf_hub_download(
55
  se_resnet_checkpoint = torch.load(se_resnet_path, map_location='cpu')
56
  ```
57
 
58
- ### Load ResNet-50
59
 
60
  ```python
61
  # Create ResNet-50 model
@@ -65,11 +79,7 @@ resnet_model = create_resnet50(
65
  )
66
  resnet_model.load_state_dict(resnet_checkpoint['model_state_dict'])
67
  resnet_model.eval()
68
- ```
69
 
70
- ### Load SE-ResNet-50
71
-
72
- ```python
73
  # Create SE-ResNet-50 model
74
  se_resnet_model = create_se_resnet50(
75
  num_classes=90,
@@ -80,7 +90,98 @@ se_resnet_model.load_state_dict(se_resnet_checkpoint['model_state_dict'])
80
  se_resnet_model.eval()
81
  ```
82
 
83
- ### Compare Predictions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  ```python
86
  import torch
@@ -126,21 +227,41 @@ print(f" Confidence: {se_resnet_confidence*100:.2f}%")
126
 
127
  ## Model Details
128
 
129
- ### ResNet-50
 
 
130
  - **Architecture**: Standard residual network with bottleneck blocks
131
  - **Parameters**: ~25.6M
132
  - **Pretrained**: ImageNet weights
133
  - **Best Validation Accuracy**: 97.84%
134
 
135
- ### SE-ResNet-50
136
  - **Architecture**: ResNet-50 with Squeeze-and-Excitation attention blocks
137
  - **Parameters**: ~26.0M
138
  - **Pretrained**: ImageNet weights (excluding SE blocks)
139
  - **SE Reduction Ratio**: 16
140
  - **Best Validation Accuracy**: 95.72%
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  ## Training Details
143
 
 
144
  - **Dataset**: ibrahimdaud/raw-food-recognition
145
  - **Number of Classes**: 90
146
  - **Image Size**: 224x224
@@ -148,12 +269,25 @@ print(f" Confidence: {se_resnet_confidence*100:.2f}%")
148
  - **Learning Rate**: 0.001
149
  - **Batch Size**: 32
150
 
 
 
 
 
 
 
 
151
  ## Files in Repository
152
 
 
153
  - `resnet50_pytorch_model.bin` - ResNet-50 model weights
154
  - `se_resnet50_pytorch_model.bin` - SE-ResNet-50 model weights
155
  - `resnet50_metadata.json` - ResNet-50 metadata
156
  - `se_resnet50_metadata.json` - SE-ResNet-50 metadata
 
 
 
 
 
157
  - `README.md` - This file
158
 
159
  ## Citation
@@ -162,7 +296,7 @@ If you use these models, please cite:
162
 
163
  ```bibtex
164
  @model{raw_food_recognition_models_2024,
165
- title={Raw Food Recognition Models: ResNet-50 and SE-ResNet-50},
166
  author={Ibrahim Daud},
167
  year={2024},
168
  publisher={HuggingFace},
 
4
  - image-classification
5
  - food-recognition
6
  - raw-food
7
+ - multilabel-classification
8
  - pytorch
9
  - resnet
10
  - se-resnet
 
12
  - model-comparison
13
  datasets:
14
  - ibrahimdaud/raw-food-recognition
15
+ - ibrahimdaud/multi-label-food-recognition
16
  metrics:
17
  - accuracy
18
+ - mean-average-precision
19
+ - f1-score
20
  ---
21
 
22
+ # Raw Food Recognition Models: Single-Class and Multi-Label
23
 
24
+ This repository contains both single-class and multi-label classification models trained for raw food ingredient recognition.
25
 
26
+ ## Single-Class Classification Models
27
 
 
 
 
 
28
 
29
+ | Model | Parameters | Validation Accuracy | Architecture |
30
+ | ------------ | ---------- | ------------------- | --------------------------- |
31
+ | ResNet-50 | ~25.6M | 97.84% | Standard residual network |
32
+ | SE-ResNet-50 | ~26.0M | 95.72% | ResNet-50 with SE attention |
33
+
34
 
35
  Both models were trained on the [ibrahimdaud/raw-food-recognition](https://huggingface.co/datasets/ibrahimdaud/raw-food-recognition) dataset, which contains 90+ raw food categories.
36
 
37
+
38
+ ## Multi-Label Classification Models
39
+
40
+ | Model | Training Mode | Parameters | Best mAP | Architecture |
41
+ |-------|--------------|------------|----------|--------------|
42
+ | Multi-Label ResNet-50 | Freeze Encoder | ~24,656,463 | 0.3747 | ResNet-50 encoder (frozen) + classifier |
43
+
44
+
45
+ Multi-label models were trained on the [ibrahimdaud/multi-label-food-recognition](https://huggingface.co/datasets/ibrahimdaud/multi-label-food-recognition) dataset for recognizing multiple ingredients in a single image.
46
+
47
  ## Usage
48
 
49
+ ### Download Single-Class Models
50
 
51
  ```python
52
  from huggingface_hub import hf_hub_download
 
69
  se_resnet_checkpoint = torch.load(se_resnet_path, map_location='cpu')
70
  ```
71
 
72
+ ### Load Single-Class Models
73
 
74
  ```python
75
  # Create ResNet-50 model
 
79
  )
80
  resnet_model.load_state_dict(resnet_checkpoint['model_state_dict'])
81
  resnet_model.eval()
 
82
 
 
 
 
83
  # Create SE-ResNet-50 model
84
  se_resnet_model = create_se_resnet50(
85
  num_classes=90,
 
90
  se_resnet_model.eval()
91
  ```
92
 
93
+ ### Download Multi-Label Models
94
+
95
+ ```python
96
+ from huggingface_hub import hf_hub_download
97
+ import torch
98
+ from models.multilabel_resnet50 import create_multilabel_resnet50
99
+
100
+ # Download Freeze Encoder model
101
+ freeze_path = hf_hub_download(
102
+ repo_id="ibrahimdaud/raw-food-recognition-models",
103
+ filename="multilabel_freeze_pytorch_model.bin"
104
+ )
105
+ freeze_checkpoint = torch.load(freeze_path, map_location='cpu')
106
+
107
+ # Download Full Training model
108
+ full_path = hf_hub_download(
109
+ repo_id="ibrahimdaud/raw-food-recognition-models",
110
+ filename="multilabel_full_pytorch_model.bin"
111
+ )
112
+ full_checkpoint = torch.load(full_path, map_location='cpu')
113
+
114
+ # Download Fine-Tuning model
115
+ finetune_path = hf_hub_download(
116
+ repo_id="ibrahimdaud/raw-food-recognition-models",
117
+ filename="multilabel_finetune_pytorch_model.bin"
118
+ )
119
+ finetune_checkpoint = torch.load(finetune_path, map_location='cpu')
120
+ ```
121
+
122
+
123
+ ### Load Multi-Label Models
124
+
125
+ ```python
126
+ # Load Freeze Encoder model
127
+ freeze_model = create_multilabel_resnet50(
128
+ num_classes=freeze_checkpoint['num_classes'],
129
+ pretrained=False
130
+ )
131
+ freeze_model.load_state_dict(freeze_checkpoint['model_state_dict'])
132
+ freeze_model.eval()
133
+
134
+ # Load Full Training model
135
+ full_model = create_multilabel_resnet50(
136
+ num_classes=full_checkpoint['num_classes'],
137
+ pretrained=False
138
+ )
139
+ full_model.load_state_dict(full_checkpoint['model_state_dict'])
140
+ full_model.eval()
141
+
142
+ # Load Fine-Tuning model
143
+ finetune_model = create_multilabel_resnet50(
144
+ num_classes=finetune_checkpoint['num_classes'],
145
+ pretrained=False
146
+ )
147
+ finetune_model.load_state_dict(finetune_checkpoint['model_state_dict'])
148
+ finetune_model.eval()
149
+ ```
150
+
151
+ ### Multi-Label Inference
152
+
153
+ ```python
154
+ import torch
155
+ from PIL import Image
156
+ import torchvision.transforms as transforms
157
+
158
+ # Preprocess image
159
+ transform = transforms.Compose([
160
+ transforms.Resize((224, 224)),
161
+ transforms.ToTensor(),
162
+ transforms.Normalize(mean=[0.485, 0.456, 0.406],
163
+ std=[0.229, 0.224, 0.225])
164
+ ])
165
+
166
+ image = Image.open('path/to/image.jpg').convert('RGB')
167
+ image_tensor = transform(image).unsqueeze(0)
168
+
169
+ # Get multi-label predictions
170
+ with torch.no_grad():
171
+ logits = freeze_model(image_tensor) # or full_model, finetune_model
172
+ probs = torch.sigmoid(logits) # Multi-label probabilities
173
+
174
+ # Get top-k predictions
175
+ top_k = 5
176
+ top_probs, top_indices = torch.topk(probs[0], top_k)
177
+
178
+ # Assuming you have class names
179
+ for prob, idx in zip(top_probs, top_indices):
180
+ print(f"Class {{idx.item()}}: {{prob.item():.4f}}")
181
+ ```
182
+
183
+
184
+ ### Compare Single-Class Predictions
185
 
186
  ```python
187
  import torch
 
227
 
228
  ## Model Details
229
 
230
+ ### Single-Class Models
231
+
232
+ #### ResNet-50
233
  - **Architecture**: Standard residual network with bottleneck blocks
234
  - **Parameters**: ~25.6M
235
  - **Pretrained**: ImageNet weights
236
  - **Best Validation Accuracy**: 97.84%
237
 
238
+ #### SE-ResNet-50
239
  - **Architecture**: ResNet-50 with Squeeze-and-Excitation attention blocks
240
  - **Parameters**: ~26.0M
241
  - **Pretrained**: ImageNet weights (excluding SE blocks)
242
  - **SE Reduction Ratio**: 16
243
  - **Best Validation Accuracy**: 95.72%
244
 
245
+ ### Multi-Label Models
246
+
247
+ #### Freeze Encoder Mode
248
+ - **Training Strategy**: Encoder frozen, only classifier trained
249
+ - **Use Case**: Fast training, preserves encoder features
250
+ - **Best for**: When you have limited data or want quick results
251
+
252
+ #### Full Training Mode
253
+ - **Training Strategy**: Both encoder and classifier trained from scratch
254
+ - **Use Case**: Maximum flexibility, learns task-specific features
255
+ - **Best for**: When you have sufficient data and compute
256
+
257
+ #### Fine-Tuning Mode
258
+ - **Training Strategy**: Encoder trained with lower learning rate, classifier with higher rate
259
+ - **Use Case**: Balanced approach, preserves some encoder knowledge while adapting
260
+ - **Best for**: General-purpose multi-label classification
261
+
262
  ## Training Details
263
 
264
+ ### Single-Class Models
265
  - **Dataset**: ibrahimdaud/raw-food-recognition
266
  - **Number of Classes**: 90
267
  - **Image Size**: 224x224
 
269
  - **Learning Rate**: 0.001
270
  - **Batch Size**: 32
271
 
272
+ ### Multi-Label Models
273
+ - **Dataset**: ibrahimdaud/multi-label-food-recognition
274
+ - **Image Size**: 224x224
275
+ - **Optimizer**: Adam
276
+ - **Loss Function**: BCEWithLogitsLoss
277
+ - **Evaluation Metrics**: Mean Average Precision (mAP), F1-Score, Hamming Loss
278
+
279
  ## Files in Repository
280
 
281
+ ### Single-Class Models
282
  - `resnet50_pytorch_model.bin` - ResNet-50 model weights
283
  - `se_resnet50_pytorch_model.bin` - SE-ResNet-50 model weights
284
  - `resnet50_metadata.json` - ResNet-50 metadata
285
  - `se_resnet50_metadata.json` - SE-ResNet-50 metadata
286
+
287
+ ### Multi-Label Models
288
+ - `multilabel_freeze_pytorch_model.bin` - Multi-label ResNet-50 (Freeze Encoder)
289
+ - `multilabel_freeze_metadata.json` - Freeze Encoder metadata
290
+
291
  - `README.md` - This file
292
 
293
  ## Citation
 
296
 
297
  ```bibtex
298
  @model{raw_food_recognition_models_2024,
299
+ title={Raw Food Recognition Models: Single-Class and Multi-Label Classification},
300
  author={Ibrahim Daud},
301
  year={2024},
302
  publisher={HuggingFace},