Giter Club home page Giter Club logo

mtcnnmaskdetection's Introduction

Case study: MTCNN for mask detection

There is a recent surge for wearing masks in public spaces due to the COVID-19 pandemic, which has affected how we go through our everyday lives. Many public services require people to wear masks so as to avoid spreading the virus even more. This is a challenge for face detection mechanisms since the face can be occluded up to the nose, which yields lower confidence intervals for such models. While researchers are trying build new detection models or even retraining them with more difficult examples, I wanted to evaluate how current models perform under these harder scenarios.

The Multi-task Cascaded Convolutional Networks (MTCNN) designed by Zhang et al. is a three-stage detection model that produces both bounding boxes and facial landmarks. Compared to Viola and Jones face detector, MTCNN has greater recall and precision. I'll make sure to test their detector on the face mask dataset as well, but I think it is safe to say its results will be lower.

sample image

Face tracker

I also added a face ID tracker which you can use to empirically check out how the MTCNN performs under variable situations where conditions change, such as illumniation and occlusion. The tracker is essentially the same as PyImageSearch's centroid tracker, I only did some minor changes.

Implementation

Unless you want to verify the results, you're going to find yourself using only main.py which has the ID tracker already integrated.

foo@bar:MtcnnMaskDetection$ python main.py camera_id

Finally, if you do want to run the test as well, cd to the test directory and run

foo@bar:MtcnnMaskDetection$ python run_tests.py path/to/labels

Dataset and test

The test images were taken from Kaggle's Medical Mask Dataset, which contains 3000 faces wearing masks and ~700 faces with badly worn masks (or even none at all). The test results didn't take into account people with no masks whatsoever. To the best of my knowledge, recall is the only available metric since the groundtruth labels ignore some unmasked faces, which MTCNN may not, so it may seem it has a higher false positive rate.

Results

Groundtruth bounding boxes are given in green while predictions are given in red. Easy example Hard example

recall as function of IoU

License

The code under this repo has an MIT License, so it can be reproduced for private and/or commercial use.

mtcnnmaskdetection's People

Contributors

tempdata73 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mtcnnmaskdetection's Issues

other project: face_verification has no issues? how to ask a question?

hi,
i found your interesting projects and repos on github.

here your activated issues, so i use it to ask something for your repo "face_verification":

will you open issues there? would be great to ask about details how/which to download model and if tensorflow 2.x is compatible. i would give it a try to see the demo running on my system.

may push this over to newly issues on face_verification --> https://github.com/tempdata73/face_verification ?

greatly appreciate that, thx,
ozett

Getting CUDA error when using GPU

When running with CPU there is no issue...when I enable GPU then i get:

`(deep) deep/MtcnnMaskDetection git:(master) [D]% python main.py ../automl/efficientdet/video_calle.mp4
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/pnet-6b6ef92b.pth" to /home/javier/.cache/torch/checkpoints/pnet-6b6ef92b.pth
100%|##########################################################################################################| 28.1k/28.1k [00:00<00:00, 253kB/s]
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/rnet-b13c48bc.pth" to /home/javier/.cache/torch/checkpoints/rnet-b13c48bc.pth
100%|############################################################################################################| 394k/394k [00:00<00:00, 616kB/s]
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/onet-60cc8dd5.pth" to /home/javier/.cache/torch/checkpoints/onet-60cc8dd5.pth
100%|##########################################################################################################| 1.49M/1.49M [00:02<00:00, 559kB/s]

Traceback (most recent call last):
File "main.py", line 60, in
main(**parse_args())
File "main.py", line 49, in main
track_video(vcap)
File "main.py", line 33, in track_video
bboxes, scores = detections.fetch_faces(frame, return_landmarks=False)
File "/home/javier/repos/deep/MtcnnMaskDetection/utils/detections.py", line 24, in fetch_faces
bboxes, landmarks = detect_faces(image)
File "/home/javier/repos/deep/lib/python3.6/site-packages/torch_mtcnn/detector.py", line 58, in detect_faces
boxes = run_first_stage(image, pnet, scale=s, threshold=thresholds[0])
File "/home/javier/repos/deep/lib/python3.6/site-packages/torch_mtcnn/first_stage.py", line 34, in run_first_stage
probs = output[1].data.numpy()[0, 1, :, :]

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.