Skip to content

The thesis project was accepted by the School of Data Science - International University (VNU-HCMC)

Notifications You must be signed in to change notification settings

vnk8071/yolov5-mask-detection

Repository files navigation

YOLOv5 - WEARING MASK - OBJECT DETECTION

Data collected from FSOFT, the Organizing Commitee provides a dataset of 976 pictures labeled with bounding boxes in 3 classes: wearing masks, not wearing masks and wearing masks incorrectly; 1 pre-trained model; 1 public test dataset of 89 pictures for participants to make preliminary analysis of the model.

Install requirements

conda create -n yolov5detector python=3.8
conda activate yolov5detector
pip install -r requirements.txt

Download data (YOLO format)

bash setup_data.sh

The directory of dataset structured:

    ├────────── /data/ ──────────│
  images                       labels                   
    ├── train                    ├── train
    │    ├── 1.png               │    ├── 1.txt
    │    ├── ...                 │    ├── ...
    │    └── 792.png             │    └── 792.txt                    
    ├── val                      ├── val
    │    ├── 793.png             │    ├── 793.txt
    │    ├── ...                 │    ├── ...
    │    └── 976.png             │    └── 976.txt 
    └── test                     └── test
            ├── 977.png               ├── 977.txt
            ├── ...                   ├── ...
            └── 1064.png              └── 1064.txt

Train

python train.py --batch-size 64 --name <version> --device 0

Note:

  • [version]: To save weights and results
  • Remember to check the config before train in config/train_cfg.yaml

Evaluate

python val.py --weights ./results/train/<version>/weights/best.pt  --task val --batch-size 64 --name <version> --device 0

Inference

python detect.py --weights results/train/<version>/weights/best.pt --source ./data/images/test --dir ./inference/<version>

Result

result

Some inferences:

sample1

sample2

For more detail: https://drive.google.com/drive/folders/1bE2kh3Rp1IhNWma5EoYjvwJFjlWjLiim?usp=sharing

Inheritance trained:

Change the path in config/train_cfg.yaml

weights: 'pretrains/pretrain.pt' ➡️ 'pretrains/yolov5s_best.pt'

Or use different pretrained models (yolov5n, yolov5m, yolov5l, yolov5x) by
weights: 'pretrains/pretrain.pt' ➡️ 'pretrains/{model}.pt'

Or train from the scratch

model_cfg: '' ➡️ 'models/yolov5s.yaml'

User Interface App by using Flask:

python app.py

Package image by Docker

docker build -t mask_detection:1.0
docker run -p 5000:5000 mask_detection:1.0

or can pull image from docker hub

docker run -t -p 5000:5000 vnk8071/mask_detection:1.0

Check on website: http://localhost:5000

YOLOv5 🚀 by Ultralytics, GPL-3.0 license

Source: https://github.com/ultralytics/yolov5

About

The thesis project was accepted by the School of Data Science - International University (VNU-HCMC)

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages