All Projects

Face Mask Classifier.

Two models, head to head — a fine-tuned ResNet50 and a custom CNN, trained on the same 12K-image dataset, evaluated the same way.

Computer VisionArchived12K images (Kaggle)Custom CNN — 98%ResNet50 — 91%TensorFlow / Keras
12,000
Dataset size
98%
Custom CNN accuracy
91%
ResNet50 accuracy
19.26M
Custom CNN params

Overview

Dataset

12,000 images, evenly split

Kaggle's Face Mask Detection dataset: 6,000 masked / 6,000 unmasked. Split into 10,000 train (5K/5K), 800 validation (400/400), 800 test (400/400).

Results

The custom model won, unexpectedly

Both models were scored on the same held-out test set with evaluate.py. The from-scratch CNN outperformed the pretrained ResNet50 — the author's own writeup speculates this may come down to the custom model's larger parameter count (19,264,322) or the small test set size, rather than a definitive architectural conclusion.

ResNet50
acc 0.91 · precision 0.93 · recall 0.87 · F1 0.90
Custom CNN
acc 0.98 · precision 0.97 · recall 0.98 · F1 0.98

Method

The same Kaggle dataset trains two independent models — a transfer-learning ResNet50 and a from-scratch CNN — then one evaluation script scores both the same way.

  1. 01
    Dataset

    12K images, Kaggle, 50/50 split

  2. 02
    Two models

    ResNet50 vs. custom CNN

  3. 03
    evaluate.py

    accuracy · precision · recall · F1

Fig. 1Masked vs. unmasked classification

Stack

ResNet50ImageNet transfer learningCustom CNNKeras Sequential, from scratchImageDataGeneratordata loading + normalization

Reproduce it

Train + evaluate
$ pip install -r requirements.txt
$ python resnet_train.py <train_dir> <val_dir> <epochs> <save_name>
$ python tf_model_train.py <train_dir> <val_dir> <epochs> <save_name>
$ python evaluate.py <test_dir> <model_path>
Predict on one image
$ python main.py --img_path path/to/img --model_path path/to/model