Package: retinaface-pytorch
RetinafaceThis repo is build on top ofhttps://github.com/biubug6/Pytorch_RetinafaceDifferencesTrain loop moved toPytorch LightningIT added a set of functionality:Distributed trainingfp16Syncronized BatchNormSupport for various loggers likeW&BorNeptune.mlHyperparameters are defined in the config fileHyperparameters that were scattered  across the code moved to the config atretinadace/configAugmentations =>AlbumentationsColor that were manually implemented replaced by the Albumentations library.Todo:Horizontal Flip is not implemented in AlbumentationsSpatial transforms like rotations or transpose are not implemented yet.Color transforms defined in the config.Added mAP calculation for validationIn order to track the progress, mAP metric is calculated on validation.Installationpip install -U retinaface_pytorchExample inferenceimportcv2fromretinaface.pre_trained_modelsimportget_modelimage = <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:Jupyter notebook with the example on how to combine face detector with mask detector:Data PreparationThe 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 thisscript.TrainingInstall dependenciespip install -r requirements.txt
pip install -r requirements_dev.txtDefine configExample configs could be found atretinaface/configsDefine environmental variablesexportTRAIN_IMAGE_PATH=<pathtotrainimages>exportVAL_IMAGE_PATH=<pathtovalidationimages>exportTRAIN_LABEL_PATH=<pathtotrainannotations>exportVAL_LABEL_PATH=<pathtovalidationannotations>Run training scriptpython 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.Inferencepython 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 fp6python -m torch.distributed.launch --nproc_per_node=<num_gpus> retinaface/inference.py <parameters>Weightsfor the model withconfig.Weightsfor the model withconfig.Web apphttps://retinaface.herokuapp.com/Code for the web app:https://github.com/ternaus/retinaface_demoConverting to ONNXThe inference could be sped up on CPU by converting the model to ONNX.Ex: python -m converters.to_onnx -m 1280 -o retinaface1280.onnx