Data · AI · Development

FOOD-HEALTH-DETECTOR

Binary healthy food classifier with a custom CNN on Food-101 and a Streamlit demo.

1 star2025role: team development (3 members)status: completed

01 Problem and context

Whether a dish is healthy is not an inherent visual property: it depends on ingredients, cooking methods, and portion size, while a photograph captures only indirect traces of all three. The study explores how far a convolutional network can go with a label that is only partially recoverable from pixels.

Whether a plate of food is healthy is not a visual property. It follows from ingredients, cooking method and portion size, and a photograph keeps only indirect traces of all three. This study takes Food-101, a set of 101 prepared-dish categories, collapses it into a binary healthy versus not-healthy problem, and measures how far a convolutional network trained from scratch can get on a label that is only partly recoverable from pixels.

02 Solution

A custom-built CNN (three convolutional blocks with batch normalization, a dense layer with dropout, and a sigmoid output) trained on Food-101 mapped to a binary classification problem, and systematically benchmarked against transfer learning with MobileNetV2. Class imbalance was addressed on two fronts: data augmentation on the minority class and class weights in the loss function. Evaluation reports the per-class confusion matrix, not just overall accuracy.

  1. Framing the binary problem: an explicit mapping of the 101 categories into two classes, with the criterion written class by class in code, so it can be audited and argued with.
  2. Preparation: download, removal of corrupt or truncated images, and reorganisation into the two-class structure.
  3. Balancing on two fronts: offline augmentation of the minority class plus class weights in the loss for the residual imbalance.
  4. FoodNet design: three convolutional blocks of 32, 64 and 128 filters with batch normalisation and pooling, a 256-unit dense layer with 0.5 dropout, and a sigmoid output.
  5. Training with Adam at 1e-4, an 80/20 split, early stopping on validation loss with best-weight restoration.
  6. A comparison against MobileNetV2 transfer learning, to justify keeping a custom architecture.
  7. Evaluation with a per-class classification report and a confusion matrix, not just headline accuracy.

03 Results

Verifiable figures in the repository and its documentation:

0.71validation accuracy
101Food-101 categories remapped into two classes

04 How it's built

A computer vision system that classifies images of food dishes as healthy or unhealthy. It reorganizes the 101 categories from the Food-101 dataset into two binary classes and trains a CNN built from scratch (FoodNet, three convolutional blocks with BatchNormalization and Dropout) in TensorFlow/Keras. The pipeline covers downloading from Kaggle, cleaning corrupted images, class balancing via data augmentation, training with EarlyStopping, and confusion matrix evaluation, achieving 71% validation accuracy. Includes a Streamlit web interface.

05 Ethical decisions

  • The healthy / not-healthy label is the author's own judgement assigned category by category, not measured nutritional data. It sits in the repository in plain sight precisely so it can be reviewed, challenged or replaced.
  • Food-101 is made of mostly Western restaurant dishes, so the model inherits that cultural notion of healthy and cannot be treated as valid outside it.
  • The classifier is presented as a technical demonstration, not as nutritional or medical advice.

06 Highlights

  • Custom 3-block convolutional CNN (FoodNet) with BatchNormalization and Dropout, instead of transfer learning.
  • Reproducible 6-script pipeline: Kaggle download, reorganization of Food-101 into binary classes, data cleaning, data augmentation, training, and evaluation.
  • Training with EarlyStopping and ModelCheckpoint; evaluation using a classification report and confusion matrix on the validation set.
  • Streamlit web interface to classify user-uploaded images in real time, featuring a video demo.
  • README with a justified architecture comparison (custom CNN vs. MobileNetV2) and an ethical reflection on dataset bias.

07 Limitations

The binary label collapses information the image does not carry: two visually identical plates can differ in portion, oil or cooking method. That label noise puts a ceiling on achievable accuracy that no architecture can lift. Three conditions of the setup are worth keeping in view when reading the 0.71: images are downscaled to 64x64, which erases texture detail that matters; validation is a single random split of the same pool, with no cross-validation and no held-out test set; and augmentation was written into the same folder that is split afterwards, so derived copies of one photograph can land on both sides of the split, leaving validation accuracy somewhat optimistic.