An open API service indexing awesome lists of open source software.

https://github.com/gperdrizet/face-mask-detection

Demo face mask detection web app with PyTorch CNN
https://github.com/gperdrizet/face-mask-detection

cnn computer-vision deeplearning image-classification machine-learning pytorch streamlit

Last synced: about 13 hours ago
JSON representation

Demo face mask detection web app with PyTorch CNN

Awesome Lists containing this project

README

          

# Face mask detection

Try live deployment of app [here](https://mask-detector-puv1.onrender.com)

A deep learning project for detecting face masks in images using a PyTorch CNN model, with a simple Streamlit web application for deployment.

## Web application

A simple Streamlit app for real-time face mask detection with:

- **Image upload**: Upload JPG, JPEG, or PNG images
- **Webcam capture**: Take photos directly with your camera
- **Real-time inference**: Get instant mask detection results
- **Probability display**: Shows mask detection probability (0.0 - 1.0)
- **CPU-only**: Runs on CPU, no GPU required

## Model

- **Architecture**: 4-layer CNN with batch normalization and dropout (~500K parameters)
- **Input size**: 128x128 pixels RGB
- **Output**: Binary classification (with_mask / without_mask)
- **Training**: PyTorch 2.0+ with data augmentation

## Model performance

See the notebook [face_mask_detection.ipynb](https://github.com/gperdrizet/face-mask-detection/blob/main/notebooks/face_mask_detection.ipynb) for full model architecture, training and evaluation details.

## Running the project yourself

### Using the dev container (recommended)

This project includes a dev container configuration with all dependencies pre-installed.

1. **Open in VS Code**: Make sure you have Docker and the Dev Containers extension installed
2. **Reopen in Container**: VS Code will prompt you to reopen in the container, or use Command Palette → "Dev Containers: Reopen in Container"
3. **Train the Model**: Open and run all cells in `notebooks/face_mask_detection.ipynb` to train the model and save it to `models/face_mask_detector_production.pth`
4. **Run the App**: From the `app/` directory, run:

```bash
streamlit run streamlit_app.py
```

The dev container has everything configured, so you don't need to install any dependencies manually!

### Manual installation (without dev container)

If you prefer not to use the dev container:

1. Install the required dependencies:
```bash
pip install -r requirements.txt
```

2. Train the model by running the notebook at `notebooks/face_mask_detection.ipynb`

3. Run the app from the `app/` directory:
```bash
streamlit run streamlit_app.py
```

### Usage

The app will open in your default browser at `http://localhost:8501`.

1. **Upload an image**: Click "Browse files" to select an image from your computer
2. **Or use your camera**: Click "Take a photo" to capture an image with your webcam

## License

See LICENSE file for details.