Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created July 2, 2020 13:10
Show Gist options
  • Save Keiku/d0d9881fbd7280df5142f899206bdd97 to your computer and use it in GitHub Desktop.
Save Keiku/d0d9881fbd7280df5142f899206bdd97 to your computer and use it in GitHub Desktop.
InsightFace demo for face detection
# Reference: 1. Getting Started with Pre-trained Model from RetinaFace — insightface 0.1.5 documentation http://insightface.ai/build/examples_face_detection/demo_retinaface.html
# How to install insightface
# pip install insightface
# pip install mxnet-cu100
import insightface
import urllib
import urllib.request
import cv2
import numpy as np
def url_to_image(url):
resp = urllib.request.urlopen(url)
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
return image
url = 'https://github.com/deepinsight/insightface/blob/master/sample-images/t1.jpg?raw=true'
img = url_to_image(url)
model = insightface.model_zoo.get_model('retinaface_r50_v1')
# if you use gpu, set ctx_id=0
model.prepare(ctx_id=-1, nms=0.4)
bbox, landmark = model.detect(img, threshold=0.5, scale=1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment