Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ihaterynn/HECT-Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍱 Snackly – Malaysian Food Recognition & Nutrition Estimation App

πŸ“Š Dataset

πŸ“‚ Malaysia Food-11 Dataset on Kaggle

πŸ”— Baseline Reference Model

πŸ”— EHFRNet GitHub Repository (Backbone Inspiration)


πŸ“Œ Overview

Snackly is a lightweight AI-powered mobile app that recognizes Malaysian food items from images and estimates their nutritional values. It uses a hybrid deep learning model called HECTNet, inspired by EHFRNet, and combines both semantic and handcrafted features for robust classification in real-world conditions.

This project is designed to support health-conscious users in their dietary tracking journey and is especially useful in local contexts with food like Nasi Lemak, Roti Canai, Satay, etc.


🧠 HECTNet – Hybrid Efficient Color-Texture Network (TBC)

HECTNet Architecture

HECTNet is a custom-built model tailored for mobile-friendly food recognition. It consists of:

  • Main Branch:
    • Backbone: MobileNetV2 + LP-ViT (Location-Preserving ViT) contained within HBlocks (Hybrid Blocks)
    • Extracts semantic global context from food images
  • Auxiliary Branch:
    • Gabor-based handcrafted texture features across multiple scales
    • Captures fine-grained color and texture variations (crispy, saucy, etc.)
  • Bidirectional Cross-Attention Fusion ("Aha! Moment"):
    • Aligns and fuses the two distinct feature types
    • Allows dynamic, context-aware feature prioritization
  • Classifier:
    • Final fused vector (160D) passed into a fully connected layer β†’ softmax prediction

πŸ’‘ "Aha! Moment" is the coined term describing the model's critical moment of insight during fusionβ€”where it contextually understands which food-identifying cues matter most.


πŸ”„ Technical Pipeline Process

Technical Pipeline

The technical pipeline illustrates the step-by-step process of HECTNet's dual-branch architecture:

1. Projection to Common Latent Space

  • Main Embedding (M): 320-dimensional features from MobileNetV2 + LP-ViT backbone
  • Auxiliary Embedding (A): 32-dimensional Gabor-based texture features
  • Both embeddings are projected to a unified 160-dimensional latent space through linear transformations

2. Bidirectional Cross-Attention

  • Main attends to Aux: Semantic features query texture information for fine-grained details
  • Aux attends to Main: Texture features query semantic context for global understanding
  • Multi-head attention mechanism enables dynamic feature prioritization

3. Fusion and Final Processing

  • Attended features are combined with original projections: Mproj + M_attended and Aproj + A_attended
  • Layer normalization stabilizes the fused representations
  • Element-wise averaging creates the final unified embedding (ΞΌfused, 160-dim)

4. Classification

  • Feed-forward network processes the fused embedding
  • Softmax activation produces final food category predictions

This pipeline ensures that both semantic understanding and texture analysis contribute optimally to the final classification decision.


🍽️ Target Food Categories

Class Description
Nasi Lemak Rice dish with sambal and anchovies
Roti Canai Flatbread served with dhal
Satay Skewered grilled meat
Kaya Toast Toasted bread with kaya spread
Fried Rice Classic Malaysian-style fried rice

πŸ“± Mobile App (Frontend – Flutter)

  • Framework: Flutter (cross-platform)
  • Features:
    • Camera input or gallery upload
    • Displays top-1 food label and calorie count
    • Meal logging system (stored via Supabase)
    • Clean UI tailored for Malaysian user base

βš™οΈ Backend (FastAPI Inference Server)

  • Framework: FastAPI + Uvicorn
  • Purpose:
    • Serve the HECTNet model
    • Accept image input via POST request
    • Return predicted food label and nutritional info
  • Integrated With:
    • Supabase for authentication and food logging
    • Optional image embedding storage for retrieval

πŸ—ƒοΈ Dataset


πŸ§ͺ Training Pipeline

  • Framework: PyTorch
  • Loss Function: CrossEntropyLoss
  • Optimizer: Adam
  • Evaluation Metrics:
    • Accuracy
    • Precision, Recall, F1-score
    • AUC-ROC
  • Epochs: 100 with early stopping
  • Embedding Dim: 160D fused features

πŸ“Œ Key Technical Innovations

βœ… Bidirectional Cross-Attention Fusion

  • Mutual interaction between main (CNN-ViT) and auxiliary (handcrafted) embeddings
  • Achieves better feature complementarity

βœ… High Performance on Challenging Datasets

  • Robust to:
    • High intra-class variation (e.g., nasi lemak with/without egg)
    • Low inter-class distinctiveness (e.g., fried rice vs. nasi lemak)

βœ… Dual Embedding Use

  • Final fused 160D vector is also suitable for:
    • Visual search (content-based image retrieval)
    • Similar food recommendation

πŸš€ How to Run Locally

Make sure you have:

  • Python 3.8+
  • Flutter installed (flutter doctor)
  • A working Chrome browser for web preview

Step 1: Clone the Repository

git clone https://github.com/ihaterynn/HECT-Net.git

Step 2: Install Dependencies

pip install -r requirements.txt

Step 3: HECT-Net Backend Setup

cd backend
python hectnet_server.py

Step 4: Start the Flutter App

cd frontend
flutter run -d chrome

πŸ“ License

This project is licensed under the MIT License.

MIT License

Copyright (c) 2025 Ryan Chan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

πŸ“Ž Acknowledge Upstream:

> ⚠️ This project builds upon and significantly extends the [EHFRNet architecture](https://github.com/LduIIPLab/CVnets), originally developed by [Guorui Sheng](https://github.com/GuoruiSheng).  
> Licensed under the MIT License.

About

Novel Hybrid Embedding Color-Texture Network

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published