Skip to main content

Unstructured set of the helper functions.

Project description

Facemask detection

Detection of the masks on the faces.

Use

import albumentations as A
import torch
from facemask_detection.pre_trained_models import get_model

model = get_model("tf_efficientnet_b0_ns_2020-07-29")
model.eval()

transform = A.Compose([A.SmallestMaxSize(max_size=256, p=1),
                       A.CenterCrop(height=224, width=224, p=1),
                       A.Normalize(p=1)])

image = <numpy array with the shape (height, width, 3)>

transformed_image = transform(image=image)['image']

input = torch.from_numpy(np.transpose(transformed_image, (2, 0, 1))).unsqueeze(0)

print("Probability of the mask on the face = ", model(input)[0].item())

Jupyter notebook with the example: Open In Colab

Train set

Train dataset was composed from the data:

No mask:

Mask:

Trainining

Define config, similar to facemask_detection_configs/2020-07-29.yaml.

Run

python facemask_detection/train.py -c <config>

Inference

python -m torch.distributed.launch --nproc_per_node=1 facemask_detection/inference.py -h
usage: inference.py [-h] -i INPUT_PATH -c CONFIG_PATH -o OUTPUT_PATH
                    [-b BATCH_SIZE] [-j NUM_WORKERS] -w WEIGHT_PATH
                    [--world_size WORLD_SIZE] [--local_rank LOCAL_RANK]
                    [--fp16]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_PATH, --input_path INPUT_PATH
                        Path with images.
  -c CONFIG_PATH, --config_path CONFIG_PATH
                        Path to config.
  -o OUTPUT_PATH, --output_path OUTPUT_PATH
                        Path to save jsons.
  -b BATCH_SIZE, --batch_size BATCH_SIZE
                        batch_size
  -j NUM_WORKERS, --num_workers NUM_WORKERS
                        num_workers
  -w WEIGHT_PATH, --weight_path WEIGHT_PATH
                        Path to weights.
  --world_size WORLD_SIZE
                        number of nodes for distributed training
  --local_rank LOCAL_RANK
                        node rank for distributed training
  --fp16                Use fp6

Example:

python -m torch.distributed.launch --nproc_per_node=<num_gpu> facemask_detection/inference.py \
                                   -i <input_path> \
                                   -w <path to weights> \
                                   -o <path to the output_csv> \
                                   -c <path to config>
                                   -b <batch size>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facemask_detection-0.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

facemask_detection-0.0.2-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file facemask_detection-0.0.2.tar.gz.

File metadata

  • Download URL: facemask_detection-0.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for facemask_detection-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2195adaf05eb7d814db74519d8c3def920436e9ffe7c2fae311f3ef63bc5d9eb
MD5 0bbd489e6f8691f39748da5308871e28
BLAKE2b-256 d9e1bbbd1d215c18e60cbaf1b7aed68e28e0b0349dfbc0b4a2d8b619c9e085b4

See more details on using hashes here.

File details

Details for the file facemask_detection-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: facemask_detection-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for facemask_detection-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c77a01f61f0b50e5ab7a30cd135daea62c0ccd5c98bb0fa12465a5659aeb72b8
MD5 6d6b7e7813faf19cd928ef304bbcd074
BLAKE2b-256 6354eb73ef98d78a7841b21ffaacc0c46047f90a4b7547f2c0b95dcf90aad473

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page