Instructions to use Alas-V/ConvNeXt-Food-CLF-75 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use Alas-V/ConvNeXt-Food-CLF-75 with timm:
import timm model = timm.create_model("hf_hub:Alas-V/ConvNeXt-Food-CLF-75", pretrained=True) - Notebooks
- Google Colab
- Kaggle
ConvNeXt-Food-CLF-75
Multiβlabel food ingredient classifier (75 classes) based on ConvNeXtβTiny with CBAM attention and GeM pooling.
Trained on a heavily cleaned subset of MMβFoodβ100K.
The model serves as a semantic guide for a downstream segmentation pipeline, but can also be used standalone for ingredient recognition.
π‘ Full source code, training scripts, and detailed dataset preparation are available in the GitHub repository.
This model card focuses on how to use the model. For deeper technical details, see the links throughout or visit the GitHub repo.
Model Description
ConvNeXt-Food-CLF-75 takes an RGB food image and predicts which of 75 ingredients it contains.
Each prediction is a multiβlabel probability β a dish can contain multiple ingredients simultaneously (e.g., βriceβ and βchickenβ).
- Input: RGB image (any size, automatically resized to 640Γ640 and normalized with ImageNet statistics)
- Output:
- A list of ingredient names (default threshold 0.5)
- Raw probability scores for each of the 75 classes
- Optional: feature embedding from the penultimate layer (for transfer learning)
Supported Classes (75 ingredients)
| almond | cheese butter | grape | onion | sauce |
| apple | chicken duck | ice cream | orange | sausage |
| asparagus | chocolate | juice | pasta | seaweed |
| avocado | cilantro mint | kiwi | peach | shellfish |
| banana | coffee | lamb | peanut | shrimp |
| beans | corn | lemon | pear | soup |
| biscuit | crab | lettuce | peas | spring onion |
| bread | cucumber | mango | pepper | sprouts |
| broccoli | date | meat | pineapple | steak |
| cabbage | egg | melon | pizza | strawberry |
| cake | eggplant | milk | pork | tea |
| carrot | fish | mushroom | potato | tofu |
| cashew | french fries | noodle | pumpkin | tomato |
| cauliflower | garlic | okra | rice | watermelon |
| celery stick | ginger | olives | salad | wonton dumplings |
Intended Uses
- Food ingredient classification into 75 categories independently or for downstream systems (calorie estimation, dietary logging, recipe retrieval).
- Feature extraction: the embedding before the final layer can be fed into a segmentation network to condition mask prediction.
- Research on multiβlabel classification with longβtail distributions and noisy training data.
Bias, Risks, and Limitations
- Dataset bias: Trained on a cleaned subset of MMβFoodβ100K. It may underrepresent cuisines not well covered in that dataset.
- Class imbalance: The smallest classes contain as few as ~100 training images; performance may be lower for those ingredients.
- Ambiguity: Visually similar dishes (e.g., βappleβ vs. βpeachβ) may be confused.
- Hallucinations: The model can occasionally predict ingredients that are not visible, especially when cues are subtle or missing.
Recommendations
- Always use the provided preprocessing pipeline (resize to 640Γ640, ImageNet normalization).
- Consider using TestβTime Augmentation (TTA) for critical applications.
- Validate predictions against your own data distribution if you plan to deploy the model.
OutβofβScope Use
- Not intended for medical diagnosis or dietary prescription.
- Not a zeroβshot classifier β it only covers the 75 classes listed above.
Training Procedure
Full training logs, hyperparameters, and stageβbyβstage breakdown are in the GitHub model documentation.
Model Architecture
| Component | Details |
|---|---|
| Backbone | ConvNeXtβTiny (pretrained on ImageNetβ1k) |
| Attention | CBAM (Channel + Spatial) |
| Pooling | GeM (Generalized Mean) with learnable p |
| Head | Linear(1024 β 512) β GELU β Dropout(0.3) β Linear(512 β 75) |
| Input | RGB image resized to 640Γ640 |
| Output | Multiβlabel logits (binary relevance per ingredient) |
Training Configuration
| Parameter | Value |
|---|---|
| Loss | BCEWithLogitsLoss (class weights: background=1, others=30) |
| Optimizer | AdamW (head LR=1eβ4, backbone LR=5eβ6) |
| Scheduler | OneCycleLR (early stages), CosineAnnealingWarmRestarts (later) |
| Weight decay | 1eβ4 |
| Batch size | 10 |
| Input size | 640Γ640 |
| MixUp | p=0.5, Ξ±=0.2 |
| Mixed precision | AMP (torch.amp) |
Training Stages
- Feature Extraction (28 epochs): Only the classification head is trained, backbone frozen.
- Discriminative FineβTuning (8 epochs): Head + stages 2β3 of backbone unfrozen, lower LR for backbone.
- Staged Unfreezing (1 epoch): Head is trained again to adapt to newly unfrozen features.
- Final Feature Extraction (5 epochs): Only the classification head is trained at a low LR (5eβ5).
StageβbyβStage Results
| Stage | Epoch | F1 (macro) | mAP | Val Loss |
|---|---|---|---|---|
| Feature Extraction | 28 | 0.3533 | 0.5067 | 0.0637 |
| Discriminative FineβTuning | 36 | 0.6121 | 0.7017 | 0.0469 |
| Staged Unfreezing | 37 | 0.6426 | 0.7097 | 0.0479 |
| Final Feature Extraction | 40 | 0.6546 | 0.7142 | 0.0489 |
Evaluation Results (Final Model)
| Metric | Value |
|---|---|
| Macro F1 | 0.6546 |
| mAP | 0.7142 |
| Validation loss | 0.0489 |
Validation set: 2,000 fixed images, split before training.
Hardware and Training Time
| Component | Detail |
|---|---|
| GPU | NVIDIA RTX 2060 (6 GB VRAM) |
| CPU | Intel Xeon E5β2660 v3 |
| OS | CachyOS (Archβbased) |
| Python | 3.10+ |
| PyTorch | 2.5 |
| timm | 1.0.9 |
| Training time | β1 hour per epoch |
| Batch size | 10 |
| Mixed precision | AMP |
Despite the limited 6 GB VRAM, the model trains comfortably with a batch size of 10 at 640Γ640 resolution.
Dataset
The model was trained on a cleaned subset of MMβFoodβ100K, a largeβscale food dataset with noisy 4,000+ ingredient labels.
A rigorous multiβstep cleaning pipeline reduced the original chaos to 75 balanced classes:
- Manually curated target class list (103 initial classes).
- Extracted all matching ingredient names from the dataset.
- Merged semantically identical ingredients (e.g., βenoki mushroomsβ + βshiitake mushroomsβ β βmushroomβ).
- Removed irrelevant matches (e.g., βcheesecakeβ for the βcheeseβ class).
- Filtered out classes with fewer than 100 images.
- Created multiβhot label vectors and serialized the final dataset.
Result: ~88k images (86.3k train, 2k validation), 75 classes.
π The complete cleaning pipeline with all scripts and documentation is here:dataset_preparation/ on GitHub
How to Use
Option 1: Quick inference using the provided script (recommended)
The repository includes a selfβcontained inference.py script. First, clone this HF repo or download the files, then:
Linux / MacOS:
git clone https://huggingface.co/Alas-V/ConvNeXt-Food-CLF-75
cd ConvNeXt-Food-CLF-75
python -m venv venv
source venv/bin/activate
pip install -r requirements-inference.txt
python -m model.inference --image path/to/meal.jpg --checkpoint pytorch_model.bin --mode text
for Windows
git clone https://huggingface.co/Alas-V/ConvNeXt-Food-CLF-75
cd ConvNeXt-Food-CLF-75
python -m venv venv
.\venv\Scripts\Activate
pip install -r requirements-inference.txt
python -m model.inference --image path/to/photo.jpg --checkpoint checkpoint.pth.tar
| Argument | Description | Default |
|---|---|---|
| --image | Path to an image or a folder | required |
| --checkpoint | Path to the model checkpoint | required |
| --threshold | Confidence threshold (0.0β1.0) | 0.5 |
| --mode | text prints ingredients, image saves annotated photo | text |
| --output_dir | Folder for annotated images (only with --mode image) | predictions |
| --device | cuda or cpu | cuda if available, else cpu |
Qualitative Examples
Correct Predictions
Challenging Cases (Hallucinations / Missing Ingredients)
π Acknowledgements
MMβFoodβ100K for the original dataset.
timm for the ConvNeXt backbone.
Albumentations for image augmentations.
Citation
If you use this model or the cleaned dataset in your work, please cite it as follows:
@misc{alasv2026convnextfoodclf75,
author = {Artem V.},
title = {ConvNeXt-Food-CLF-75: A Multi-Label Food Ingredient Classifier},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/Alas-V/ConvNeXt-Food-CLF-75}},
note = {Model trained on a cleaned subset of MM-Food-100K}
}
π License
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
- Downloads last month
- 118