Created
July 2, 2020 13:10
-
-
Save Keiku/d0d9881fbd7280df5142f899206bdd97 to your computer and use it in GitHub Desktop.
InsightFace demo for face detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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