Spaces:
Runtime error
Runtime error
File size: 1,598 Bytes
3dda64a f4d2bbb 3dda64a 3bd4e85 8cba427 f4d2bbb ad7b3d7 f4d2bbb 1842142 2689406 d5d890f fd08ff0 7d41cbf bb8326e 3cd009b ceac16c 3dda64a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import RetinaFace
import numpy as np
def RFace(img):
faces = RetinaFace.extract_faces(img, align = True)
last = np.zeros((20,20), np.uint8)
for count, image in enumerate(faces):
if count == 0:
last = image
else:
h1, w1 = last.shape[:2]
h2, w2 = image.shape[:2]
#create empty matrix
vis = np.zeros((max(h1, h2), w1+w2,3), np.uint8)
#combine 2 images
vis[:h1, :w1,:3] = last
vis[:h2, w1:w1+w2,:3] = image
last = vis
return last
examples=[['Rdj.jpg'],['Rdj2.jpg'],['2.jpg'],['3.jpg'],['many.jpg'],['many2.jpg'],['many3.jpg']]
desc = "RetinaFace is a robust single-stage face detector, it performs a pixel-wise face localisation on various scales of faces (i.e. extracting key features of the face of various scales) using a technique of joint extra-supervised and self-supervised multi-task learning. Its face detection performance is especially impressive for images of crowds, which other face detectors usually struggle handling. On top of the state-of-the-art face detection capabilities (achieving AP equal to 91.4% on the WIDER FACE hard test set, the excellent score for the most challenging dataset for face detection), the network is also capable of 2D face alignment and 3D face reconstruction, and is also used on top of existing face recognition algorithms to improve their results."
gr.Interface(fn=RFace, inputs=gr.inputs.Image(type="filepath"), outputs="image", title="RetinaFace Face Detector and Extractor (with Alignment)",examples=examples, description=desc).launch(inbrowser=True)
|