| # Mask Detection Model | |
| ## Model Overview | |
| **Name:** Mask Detection CNN | |
| **Author:** Your Name | |
| **Date:** 2025-09-26 | |
| **Framework:** Keras (TensorFlow backend) | |
| **Format:** HDF5 (`.h5`) | |
| **License:** MIT / CC0 (choose as needed) | |
| This model is designed to detect whether a person is wearing a mask or not from images of faces. It can be used in real-time applications such as webcam-based mask detection or image classification. | |
| --- | |
| ## Intended Use | |
| - **Primary Use:** Classify face images as "Mask" or "No Mask". | |
| - **Applications:** Public safety, automated mask compliance monitoring, educational demos. | |
| - **Limitations:** | |
| - The model works on cropped face images; it may produce inaccurate results if the input contains multiple faces without detection. | |
| - Lighting, occlusions, or extreme angles may affect accuracy. | |
| - Model trained on limited dataset; performance may vary on unseen ethnicities or environments. | |
| --- | |
| ## Model Details | |
| - **Input:** RGB image of shape `(128, 128, 3)` | |
| - **Preprocessing:** | |
| - Resize to `128x128` pixels | |
| - Normalize pixel values to range `[0, 1]` | |
| - **Output:** | |
| - `0`: Mask | |
| - `1`: No Mask | |
| - Output is a softmax probability distribution; prediction = `argmax(output)` | |
| - **Architecture:** Convolutional Neural Network (CNN) with 2-3 Conv2D + MaxPooling layers, Flatten, Dense layers | |
| --- | |
| ## Training | |
| - **Dataset:** Custom mask/no-mask face dataset | |
| - **Loss Function:** Categorical Crossentropy | |
| - **Optimizer:** Adam | |
| - **Metrics:** Accuracy | |
| - **Epochs:** Variable depending on training | |
| - **Batch Size:** Variable depending on training | |
| --- | |
| ## Evaluation | |
| - **Accuracy:** High on training/validation dataset (exact value depends on training) | |
| - **Test Notes:** Recommended to evaluate on new faces under similar conditions to training images | |
| --- | |
| ## Usage Example | |
| ```python | |
| import cv2 | |
| import numpy as np | |
| from keras.models import load_model | |
| # Load model | |
| model = load_model("mask_detection_model.h5") | |
| # Load image | |
| image = cv2.imread("face.jpg") | |
| image_resized = cv2.resize(image, (128, 128)) | |
| image_scaled = image_resized.astype("float32") / 255.0 | |
| image_input = np.expand_dims(image_scaled, axis=0) | |
| # Predict | |
| prediction = model.predict(image_input) | |
| pred_label = np.argmax(prediction, axis=1)[0] | |
| if pred_label == 0: | |
| print("Mask 😷✅") | |
| else: | |
| print("No Mask ❌") | |