Skip to content

hiennguyen9874/deepstream-face-recognition

Repository files navigation

Deepstream face detection & recognition

Demo output video: Deepstream face detection & recognition

Supported deepstream version:

This docs for dGPU, for jetson using ./JETSON.md

Export .engine

Face detection model

  • Export checkpoint to onnx model:
    • Clone yolov7-face-detection and cd into yolov7-face-detection folder
    • Download weight and save into weights/yolov7-tiny33.pt
    • Export to onnx: python3 export.py --weights ./weights/yolov7-tiny33.pt --img-size 640 --batch-size 1 --dynamic-batch --grid --end2end --max-wh 640 --topk-all 100 --iou-thres 0.5 --conf-thres 0.2 --device 1 --simplify --cleanup --trt
  • Or download onnx file from from github.com/hiennguyen9874/yolov7-face-detection/releases/tag/v0.1
  • Export to TensorRT: /usr/src/tensorrt/bin/trtexec --onnx=samples/models/Primary_Detector/yolov7-tiny41-nms-trt.onnx --saveEngine=samples/engines/Primary_Detector/yolov7-tiny41-nms-trt.trt --workspace=14336 --fp16 --minShapes=images:1x3x640x640 --optShapes=images:1x3x640x640 --maxShapes=images:4x3x640x640 --shapes=images:1x3x640x640

Face recognition model

  • Download webface_r50.onnx from deepinsight/insightface and cleaning onnx file: python3 scripts/onnx_clean.py --onnx-path samples/models/Secondary_Recognition/webface_r50.onnx --image-size 112,112 --batch-size 1 --simplify --dynamic --cleanup --add-norm
  • Or download onnx file from from: github.com/hiennguyen9874/deepstream-face-recognition/releases/tag/v0.1
  • Export to TensorRT: /usr/src/tensorrt/bin/trtexec --onnx=samples/models/Secondary_Recognition/webface_r50_norm_dynamic_simplify_cleanup.onnx --saveEngine=samples/engines/Secondary_Recognition/webface_r50_norm_dynamic_simplify_cleanup.trt --workspace=14336 --fp16 --minShapes=input.1:1x3x112x112 --optShapes=input.1:4x3x112x112 --maxShapes=input.1:16x3x112x112 --shapes=input.1:4x3x112x112

Download demo video

Docker

Prerequisites

  • Docker
  • Nvidia-driver
  • Nvidia-docker2

Usage

  • Pull image: docker pull hiennguyen9874/deepstream-face-recognition:deepstream-6.0.1
  • Run bash inside docker: docker run --runtime nvidia --rm -it -v $(pwd):/app hiennguyen9874/deepstream-face-recognition:deepstream-6.0.1
    • Add new face:
      • A: python3 scripts/add_face_from_file.py A docs/A.png docs/A2.png
      • B: python3 scripts/add_face_from_file.py B docs/B.png docs/B2.png
      • C: python3 scripts/add_face_from_file.py C docs/C.png docs/C2.png
    • Build source: bash sources/install.sh
    • Run: ./bin/deepstream-app -c samples/configs/deepstream_app.txt
    • Output in ./outputs/videos

Without docker

Prerequisites

Add new face

  • A: python3 scripts/add_face_from_file.py A docs/A.png docs/A2.png
  • B: python3 scripts/add_face_from_file.py B docs/B.png docs/B2.png
  • C: python3 scripts/add_face_from_file.py C docs/C.png docs/C2.png

Build

  • sudo bash sources/install.sh

Run

  • ./bin/deepstream-app -c samples/configs/deepstream_app.txt