• Stars
    star
    345
  • Rank 122,014 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The remake of the https://github.com/biubug6/Pytorch_Retinaface

Retinaface

DOI

https://habrastorage.org/webt/uj/ff/vx/ujffvxxpzixwlmae8gyh7jylftq.jpeg

This repo is build on top of https://github.com/biubug6/Pytorch_Retinaface

Differences

Train loop moved to Pytorch Lightning

IT added a set of functionality:

  • Distributed training
  • fp16
  • Syncronized BatchNorm
  • Support for various loggers like W&B or Neptune.ml

Hyperparameters are defined in the config file

Hyperparameters that were scattered across the code moved to the config at retinadace/config

Augmentations => Albumentations

Color that were manually implemented replaced by the Albumentations library.

Todo:

  • Horizontal Flip is not implemented in Albumentations
  • Spatial transforms like rotations or transpose are not implemented yet.

Color transforms defined in the config.

Added mAP calculation for validation

In order to track the progress, mAP metric is calculated on validation.

Installation

pip install -U retinaface_pytorch

Example inference

import cv2
from retinaface.pre_trained_models import get_model

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

model = get_model("resnet50_2020-07-20", max_size=2048)
model.eval()
annotation = model.predict_jsons(image)
  • Jupyter notebook with the example: Open In Colab
  • Jupyter notebook with the example on how to combine face detector with mask detector: Open In Colab

Data Preparation

The pipeline expects labels in the format:

[
  {
    "file_name": "0--Parade/0_Parade_marchingband_1_849.jpg",
    "annotations": [
      {
        "bbox": [
          449,
          330,
          571,
          720
        ],
        "landmarks": [
          [
            488.906,
            373.643
          ],
          [
            542.089,
            376.442
          ],
          [
            515.031,
            412.83
          ],
          [
            485.174,
            425.893
          ],
          [
            538.357,
            431.491
          ]
        ]
      }
    ]
  },

You can convert the default labels of the WiderFaces to the json of the propper format with this script.

Training

Install dependencies

pip install -r requirements.txt
pip install -r requirements_dev.txt

Define config

Example configs could be found at retinaface/configs

Define environmental variables

export TRAIN_IMAGE_PATH=<path to train images>
export VAL_IMAGE_PATH=<path to validation images>
export TRAIN_LABEL_PATH=<path to train annotations>
export VAL_LABEL_PATH=<path to validation annotations>

Run training script

python retinaface/train.py -h
usage: train.py [-h] -c CONFIG_PATH

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_PATH, --config_path CONFIG_PATH
                        Path to the config.

Inference

python retinaface/inference.py -h
usage: inference.py [-h] -i INPUT_PATH -c CONFIG_PATH -o OUTPUT_PATH [-v]
                    [-g NUM_GPUS] [-m MAX_SIZE] [-b BATCH_SIZE]
                    [-j NUM_WORKERS]
                    [--confidence_threshold CONFIDENCE_THRESHOLD]
                    [--nms_threshold NMS_THRESHOLD] -w WEIGHT_PATH
                    [--keep_top_k KEEP_TOP_K] [--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.
  -v, --visualize       Visualize predictions
  -g NUM_GPUS, --num_gpus NUM_GPUS
                        The number of GPUs to use.
  -m MAX_SIZE, --max_size MAX_SIZE
                        Resize the largest side to this number
  -b BATCH_SIZE, --batch_size BATCH_SIZE
                        batch_size
  -j NUM_WORKERS, --num_workers NUM_WORKERS
                        num_workers
  --confidence_threshold CONFIDENCE_THRESHOLD
                        confidence_threshold
  --nms_threshold NMS_THRESHOLD
                        nms_threshold
  -w WEIGHT_PATH, --weight_path WEIGHT_PATH
                        Path to weights.
  --keep_top_k KEEP_TOP_K
                        keep_top_k
  --world_size WORLD_SIZE
                        number of nodes for distributed training
  --local_rank LOCAL_RANK
                        node rank for distributed training
  --fp16                Use fp6
python -m torch.distributed.launch --nproc_per_node=<num_gpus> retinaface/inference.py <parameters>

Web app

https://retinaface.herokuapp.com/

Code for the web app: https://github.com/ternaus/retinaface_demo

Converting to ONNX

The inference could be sped up on CPU by converting the model to ONNX.

Ex: python -m converters.to_onnx -m 1280 -o retinaface1280.onnx

More Repositories

1

TernausNet

UNet model with VGG11 encoder pre-trained on Kaggle Carvana dataset
Python
1,046
star
2

robot-surgery-segmentation

Wining solution and its improvement for MICCAI 2017 Robotic Instrument Segmentation Sub-Challenge
Jupyter Notebook
618
star
3

TernausNetV2

TernausNetV2: Fully Convolutional Network for Instance Segmentation
Jupyter Notebook
546
star
4

kaggle_dstl_submission

Code for a winning model (3 out of 419) in a Dstl Satellite Imagery Feature Detection challenge
Python
168
star
5

cloths_segmentation

Code for binary segmentation of cloths
Python
166
star
6

people_segmentation

Code for the model to segment people at the image
Python
97
star
7

angiodysplasia-segmentation

Wining solution and its further development for MICCAI 2017 Endoscopic Vision Challenge Angiodysplasia Detection and Localization
Jupyter Notebook
78
star
8

midv-500-models

Model for document segmentation trained on the midv-500-models dataset.
Python
57
star
9

check_orientation

Model to check if image was rotated by 90, 180, 270 degrees.
Python
56
star
10

iglovikov_helper_functions

An unstructured set of helper functions
Python
55
star
11

datasouls_antispoof

Code and pre-trained models for detecting spoofing attacks from images.
Python
31
star
12

facemask_detection

Detection masks on faces.
Python
29
star
13

kaggle_allstate

Repository with files somehow relevant to the Kaggle competition https://www.kaggle.com/c/allstate-claims-severity
Python
28
star
14

imread_benchmark

I/O benchmark for different image processing python libraries.
Python
23
star
15

iglovikov_segmentation

Semantic segmentation pipeline using Catalyst.
Python
20
star
16

base64ToImageConverters

Library for converting from RGB / GrayScale image to base64 and back.
Python
16
star
17

retinafacemask

Detector for faces with masks / no masks on top of them.
Python
16
star
18

retinaface_demo

Code for webapp for https://github.com/ternaus/retinaface
Python
14
star
19

kaggle_planet

Planet: Understanding the Amazon from Space
Jupyter Notebook
12
star
20

react_face_detection

Detect faces in react App.
TypeScript
11
star
21

kaggle_cdiscount

Python
11
star
22

yolov5faceInference

YoloV5FaceWrapper
Python
11
star
23

High-Resolution-Image-Inpainting-GAN

Python
9
star
24

kaggle_alaska_2

https://www.kaggle.com/c/alaska2-image-steganalysis
Python
8
star
25

spb_bridges

Jupyter Notebook
8
star
26

insightfaceWrapper

Wrapper for easier inference for insightface
Python
8
star
27

frog-rcnn

Mask RCNN by Heng CherKeng
Python
7
star
28

giana

WORK IN PROGRESS. Code for GIANA challenge
Python
7
star
29

lsun_2017

Large-Scale Scene Understanding Challenge at CVPR 2017
Python
7
star
30

people_segmentation_demo

Python
4
star
31

kaggle_otto

Otto Group Product Classification Challenge
Python
4
star
32

kaggle_camera

https://www.kaggle.com/c/sp-society-camera-model-identification
Jupyter Notebook
3
star
33

nexar

https://www.getnexar.com/challenge-2
Python
3
star
34

kaggle_liberty

https://www.kaggle.com/c/liberty-mutual-group-property-inspection-prediction/data
Python
3
star
35

onnx_model_optimizations

Python
2
star
36

clip2onnx

Converts CLIP models to ONNX
Python
2
star
37

kaggle_ICDM

https://www.kaggle.com/c/icdm-2015-drawbridge-cross-device-connections
Python
2
star
38

add_logo

Adds pre-defined logo to the image
Python
2
star
39

nuscenes-devkit

Jupyter Notebook
2
star
40

imagenet18

Python
2
star
41

cloths_segmentation_demo

Web App for binary cloths segmentation
Python
2
star
42

nexar2_ssd

Python
2
star
43

ternaus_chrome_extension

Chrome extension for Image and Reverse Image Search on Ternaus
JavaScript
2
star
44

quest-qmc

Automatically exported from code.google.com/p/quest-qmc
Fortran
2
star
45

ternaus-cleantext

Cleans text as in the CLIP model
Python
2
star
46

ternaus.github.io

HTML
2
star
47

quest-qmc-analyzer

Python
1
star
48

mask_generator

Random Mask generator
1
star
49

grade-system

1
star
50

kaggle_statefarm

Python
1
star
51

imagenet_2017

raw code for ImageNet 2017
1
star
52

FaceSwap

Based oon https://github.com/MarekKowalski/FaceSwap
Python
1
star
53

boost_imagenet

Example on how to fine tune models to boost the performance of models on ImageNet
Python
1
star
54

kaggle_mnist

Python
1
star
55

satelite_paper

TeX
1
star
56

kaggle_eeg

Python
1
star
57

kaggle_seals

Jupyter Notebook
1
star
58

kaggle_santander2

Supplementary code for competition https://www.kaggle.com/c/santander-product-recommendation
Python
1
star
59

submission_merger

tool to merge submissions generated by different models for kaggle competitions.
Python
1
star
60

kaggle_bag

Python
1
star