File size: 2,367 Bytes
aab326d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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 ❌")