Package: insightface-paddle
简体中文| EnglishInsightFace Paddle1. Introduction1.1 OverviewInsightFacePaddleis an open source deep face detection and recognition toolkit, powered by PaddlePaddle.InsightFacePaddleprovide three related pretrained models now, includeBlazeFacefor face detection,ArcFaceandMobileFacefor face recognition.This tutorial is mainly about Whl package inference usingPaddleInfernence.For face recognition task, please refer to:Face recognition tuturial.For face detection task, please refer to:Face detection tuturial.1.2 BenchmarkFor face detection task, on WiderFace dataset, the following table shows mAP, speed and time cost for BlazeFace.Model structureModel sizeWiderFace mAPCPU time costGPU time costBlazeFace-FPN-SSH-Paddle0.65MB0.9187/0.8979/0.816831.7ms5.6msRetinaFace1.68MB-/-/0.825182.0ms17.4msFor face recognition task, on MSAM dataset, the following table shows precision, speed and time cost for MobileFaceNet.Model structurelfwcfp_fpagedb30CPU time costGPU time costMobileFaceNet-Paddle0.99450.93430.96134.3ms2.3msMobileFaceNet-mxnet0.99500.88940.95917.3ms4.7msBenchmark environment:CPU: Intel(R) Xeon(R) Gold 6184 CPU @ 2.40GHzGPU: a single NVIDIA Tesla V100Note:Performance ofRetinaFaceis tested using scripttest.py. The image shape is modified to640x480here. Performance ofMobileFaceNet-mxnetis tested using scriptverification.py.1.3 VisualizationOne example result predicted byInsightFacePaddleis as follow. Please refer to theDemofor more.1.4 CommunityScan the QR code below with your QQ (QQ group number:705899115) to discuss more about deep learning together.2. InstallationInstall PaddlePaddlePaddlePaddle 2.1 or later is required forInsightFacePaddle. You can use the following steps to install PaddlePaddle.# for GPUpip3installpaddlepaddle-gpu# for CPUpip3installpaddlepaddleFor more details about installation. please refer toPaddlePaddle.Install requirementsInsightFacePaddledependencies are listed inrequirements.txt, you can use the following command to install the dependencies.pip3install--upgrade-rrequirements.txt-ihttps://mirror.baidu.com/pypi/simpleInstallInsightFacePaddle[Recommanded] You can usepipto install the lastest versionInsightFacePaddlefrompypi.pip3install--upgradeinsightface-paddleYou can also build whl package and install by following commands.cd./InsightFacePaddle
python3setup.pybdist_wheel
pip3installdist/*3. Quick StartInsightFacePaddlesupport two ways of use, includingCommad LineandPython API.3.1 Command LineYou can useInsightFacePaddlein Command Line.3.1.1 Get helpYou can get the help aboutInsightFacePaddleby following command.insightfacepaddle-hThe args are as follows:argstypedefaulthelpdet_modelstrBlazeFaceThe detection model.rec_modelstrMobileFaceThe recognition model.use_gpuboolTrueWhether use GPU to predict. Default byTrue.enable_mkldnnboolFalseWhether use MKLDNN to predict, valid only when--use_gpuisFalse. Default byFalse.cpu_threadsint1The num of threads with CPU, valid only when--use_gpuisFalseand--enable_mkldnnisTrue. Default by1.inputstr-The path of video to be predicted. Or the path or directory of image file(s) to be predicted.outputstr-The directory to save prediction result.detboolFalseWhether to detect.det_threshfloat0.8The threshold of detection postprocess. Default by0.8.recboolFalseWhether to recognize.indexstr-The path of index file.cdd_numint5The number of candidates in the recognition retrieval. Default by5.rec_threshfloat0.45The threshold of match in recognition, use to remove candidates with low similarity. Default by0.45.max_batch_sizeint1The maxium of batch_size to recognize. Default by1.build_indexstr-The path of index to be build.img_dirstr-The img(s) dir used to build index.labelstr-The label file path used to build index.3.1.2 Build indexIf use recognition, before start predicting, you have to build the index.insightfacepaddle--build_index./demo/friends/index.bin--img_dir./demo/friends/gallery--label./demo/friends/gallery/label.txtAn example used to build index is as follows:3.1.3 PredictDetection onlyImage(s)Use the image below to predict:The prediction command:insightfacepaddle--det--input./demo/friends/query/friends1.jpg--output./outputThe result is under the directory./output:Videoinsightfacepaddle--det--input./demo/friends/query/friends.mp4--output./outputRecognition onlyImage(s)Use the image below to predict:The prediction command:insightfacepaddle--rec--index./demo/friends/index.bin--input./demo/friends/query/Rachel.pngThe result is output in the terminal:INFO:root:File:Rachel.,predictlabel(s):['Rachel']Detection and recognitionImage(s)Use the image below to predict:The prediction command:insightfacepaddle--det--rec--index./demo/friends/index.bin--input./demo/friends/query/friends2.jpg--output./outputThe result is under the directory./output:Videoinsightfacepaddle--det--rec--index./demo/friends/index.bin--input./demo/friends/query/friends.mp4--output./output3.2 PythonYou can useInsightFacePaddlein Python. First, importInsightFacePaddleandloggingbecauseInsightFacePaddleusing that to control log.importinsightface_paddleasfaceimportlogginglogging.basicConfig(level=logging.INFO)3.2.1 Get helpparser=face.parser()help_info=parser.print_help()print(help_info)3.2.2 Building indexparser=face.parser()args=parser.parse_args()args.build_index="./demo/friends/index.bin"args.img_dir="./demo/friends/gallery"args.label="./demo/friends/gallery/label.txt"predictor=face.InsightFace(args)predictor.build_index()3.2.3 PredictionDetection onlyImage(s)parser=face.parser()args=parser.parse_args()args.det=Trueargs.output="./output"input_path="./demo/friends/query/friends1.jpg"predictor=face.InsightFace(args)res=predictor.predict(input_path)print(next(res))NumPyimportcv2parser=face.parser()args=parser.parse_args()args.det=Trueargs.output="./output"path="./demo/friends/query/friends1.jpg"img=cv2.imread(path)[:,:,::-1]predictor=face.InsightFace(args)res=predictor.predict(img)print(next(res))The prediction result saved as"./output/tmp.png".Videoparser=face.parser()args=parser.parse_args()args.det=Trueargs.output="./output"input_path="./demo/friends/query/friends.mp4"predictor=face.InsightFace(args)res=predictor.predict(input_path)for_inres:print(_)Recognition onlyImage(s)parser=face.parser()args=parser.parse_args()args.rec=Trueargs.index="./demo/friends/index.bin"input_path="./demo/friends/query/Rachel.png"predictor=face.InsightFace(args)res=predictor.predict(input_path,print_info=True)next(res)NumPyimportcv2parser=face.parser()args=parser.parse_args()args.rec=Trueargs.index="./demo/friends/index.bin"path="./demo/friends/query/Rachel.png"img=cv2.imread(path)[:,:,::-1]predictor=face.InsightFace(args)res=predictor.predict(img,print_info=True)next(res)Detection and recognitionImage(s)parser=face.parser()args=parser.parse_args()args.det=Trueargs.rec=Trueargs.index="./demo/friends/index.bin"args.output="./output"input_path="./demo/friends/query/friends2.jpg"predictor=face.InsightFace(args)res=predictor.predict(input_path,print_info=True)next(res)NumPyimportcv2parser=face.parser()args=parser.parse_args()args.det=Trueargs.rec=Trueargs.index="./demo/friends/index.bin"args.output="./output"path="./demo/friends/query/friends2.jpg"img=cv2.imread(path)[:,:,::-1]predictor=face.InsightFace(args)res=predictor.predict(img,print_info=True)next(res)The prediction result saved as"./output/tmp.png".Videoparser=face.parser()args=parser.parse_args()args.det=Trueargs.rec=Trueargs.index="./demo/friends/index.bin"args.output="./output"input_path="./demo/friends/query/friends.mp4"predictor=face.InsightFace(args)res=predictor.predict(input_path,print_info=True)for_inres:pass