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)