face-recognition - PyPI

文章推薦指數: 80 %
投票人數:10人

Facial Recognition · Find and recognize unknown faces in a photograph based on photographs of known people · Compare faces by numeric face distance instead of ... Skiptomaincontent Switchtomobileversion SearchPyPI Search face-recognition1.3.0 pipinstallface-recognition CopyPIPinstructions Latestversion Released: Feb20,2020 RecognizefacesfromPythonorfromthecommandline Navigation Projectdescription Releasehistory Downloadfiles Projectlinks Homepage Statistics GitHubstatistics: Stars: Forks: Openissues/PRs: ViewstatisticsforthisprojectviaLibraries.io,orbyusingourpublicdatasetonGoogleBigQuery Meta License:MITLicense(MITlicense) Author:AdamGeitgey Tags face_recognition Maintainers ageitgey Classifiers DevelopmentStatus 4-Beta IntendedAudience Developers License OSIApproved::MITLicense NaturalLanguage English ProgrammingLanguage Python::2 Python::2.7 Python::3 Python::3.5 Python::3.6 Python::3.7 Python::3.8 Projectdescription Projectdetails Releasehistory Downloadfiles Projectdescription FaceRecognition RecognizeandmanipulatefacesfromPythonorfromthecommandline with theworld’ssimplestfacerecognitionlibrary. Builtusingdlib’sstate-of-the-artface recognition builtwithdeeplearning.Themodelhasanaccuracyof99.38%onthe LabeledFacesintheWild benchmark. Thisalsoprovidesasimpleface_recognitioncommandlinetool thatlets youdofacerecognitiononafolderofimagesfromthecommandline! Features Findfacesinpictures Findallthefacesthatappearinapicture: importface_recognition image=face_recognition.load_image_file("your_file.jpg") face_locations=face_recognition.face_locations(image) Findandmanipulatefacialfeaturesinpictures Getthelocationsandoutlinesofeachperson’seyes,nose,mouthand chin. importface_recognition image=face_recognition.load_image_file("your_file.jpg") face_landmarks_list=face_recognition.face_landmarks(image) Findingfacialfeaturesissuperusefulforlotsofimportantstuff. Butyoucanalsouseforreallystupidstuff likeapplyingdigital make-up (think‘Meitu’): Identifyfacesinpictures Recognizewhoappearsineachphoto. importface_recognition known_image=face_recognition.load_image_file("biden.jpg") unknown_image=face_recognition.load_image_file("unknown.jpg") biden_encoding=face_recognition.face_encodings(known_image)[0] unknown_encoding=face_recognition.face_encodings(unknown_image)[0] results=face_recognition.compare_faces([biden_encoding],unknown_encoding) YoucanevenusethislibrarywithotherPythonlibrariestodo real-timefacerecognition: Seethis example forthecode. Installation Requirements Python3.3+orPython2.7 macOSorLinux(Windowsnotofficiallysupported,butmightwork) InstallingonMacorLinux First,makesureyouhavedlibalreadyinstalledwithPythonbindings: HowtoinstalldlibfromsourceonmacOSor Ubuntu Then,installthismodulefrompypiusingpip3(orpip2for Python2): pip3installface_recognition Ifyouarehavingtroublewithinstallation,youcanalsotryouta pre-configured VM. InstallingonRaspberryPi2+ RaspberryPi2+installation instructions InstallingonWindows WhileWindowsisn’tofficiallysupported,helpfulusershaveposted instructionsonhowtoinstallthislibrary: @masoudr’sWindows10installationguide(dlib+ face_recognition) Installingapre-configuredVirtualMachineimage Downloadthepre-configuredVM image (forVMwarePlayerorVirtualBox). Usage Command-LineInterface Whenyouinstallface_recognition,yougetasimplecommand-line program calledface_recognitionthatyoucanusetorecognizefacesina photographorfolderfullforphotographs. First,youneedtoprovideafolderwithonepictureofeachperson you alreadyknow.Thereshouldbeoneimagefileforeachpersonwiththe filesnamedaccordingtowhoisinthepicture: Next,youneedasecondfolderwiththefilesyouwanttoidentify: Theninyousimplyrunthecommandface_recognition,passingin thefolderofknownpeopleandthefolder(orsingleimage)with unknown peopleandittellsyouwhoisineachimage: $face_recognition./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person There’sonelineintheoutputforeachface.Thedatais comma-separated withthefilenameandthenameofthepersonfound. Anunknown_personisafaceintheimagethatdidn’tmatchanyone in yourfolderofknownpeople. AdjustingTolerance/Sensitivity Ifyouaregettingmultiplematchesforthesameperson,itmightbe that thepeopleinyourphotoslookverysimilarandalowertolerance value isneededtomakefacecomparisonsmorestrict. Youcandothatwiththe--toleranceparameter.Thedefault tolerance valueis0.6andlowernumbersmakefacecomparisonsmorestrict: $face_recognition--tolerance0.54./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person Ifyouwanttoseethefacedistancecalculatedforeachmatchin order toadjustthetolerancesetting,youcanuse--show-distancetrue: $face_recognition--show-distancetrue./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama,0.378542298956785 /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None MoreExamples Ifyousimplywanttoknowthenamesofthepeopleineachphotograph butdon’t careaboutfilenames,youcoulddothis: $face_recognition./pictures_of_people_i_know/./unknown_pictures/|cut-d','-f2 BarackObama unknown_person SpeedingupFaceRecognition Facerecognitioncanbedoneinparallelifyouhaveacomputerwith multipleCPUcores.Forexampleifyoursystemhas4CPUcores,you can processabout4timesasmanyimagesinthesameamountoftimeby using allyourCPUcoresinparallel. IfyouareusingPython3.4ornewer,passina --cpusparameter: $face_recognition--cpus4./pictures_of_people_i_know/./unknown_pictures/ Youcanalsopassin--cpus-1touseallCPUcoresinyoursystem. PythonModule Youcanimporttheface_recognitionmoduleandtheneasily manipulate faceswithjustacoupleoflinesofcode.It’ssupereasy! APIDocs: https://face-recognition.readthedocs.io. Automaticallyfindallthefacesinanimage importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_locations=face_recognition.face_locations(image) #face_locationsisnowanarraylistingtheco-ordinatesofeachface! Seethis example totryitout. Youcanalsoopt-intoasomewhatmoreaccuratedeep-learning-basedface detectionmodel. Note:GPUacceleration(vianvidia’sCUDAlibrary)isrequiredfor good performancewiththismodel.You’llalsowanttoenableCUDAsupport whencomplilingdlib. importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_locations=face_recognition.face_locations(image,model="cnn") #face_locationsisnowanarraylistingtheco-ordinatesofeachface! Seethis example totryitout. IfyouhavealotofimagesandaGPU,youcanalso findfacesin batches. Automaticallylocatethefacialfeaturesofapersoninanimage importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_landmarks_list=face_recognition.face_landmarks(image) #face_landmarks_listisnowanarraywiththelocationsofeachfacialfeatureineachface. #face_landmarks_list[0]['left_eye']wouldbethelocationandoutlineofthefirstperson'slefteye. Seethis example totryitout. Recognizefacesinimagesandidentifywhotheyare importface_recognition picture_of_me=face_recognition.load_image_file("me.jpg") my_face_encoding=face_recognition.face_encodings(picture_of_me)[0] #my_face_encodingnowcontainsauniversal'encoding'ofmyfacialfeaturesthatcanbecomparedtoanyotherpictureofaface! unknown_picture=face_recognition.load_image_file("unknown.jpg") unknown_face_encoding=face_recognition.face_encodings(unknown_picture)[0] #Nowwecanseethetwofaceencodingsareofthesamepersonwith`compare_faces`! results=face_recognition.compare_faces([my_face_encoding],unknown_face_encoding) ifresults[0]==True: print("It'sapictureofme!") else: print("It'snotapictureofme!") Seethis example totryitout. PythonCodeExamples Alltheexamplesareavailable here. FaceDetection Findfacesina photograph Findfacesinaphotograph(usingdeep learning) Findfacesinbatchesofimagesw/GPU(usingdeep learning) FacialFeatures Identifyspecificfacialfeaturesina photograph Apply(horriblyugly)digital make-up FacialRecognition Findandrecognizeunknownfacesinaphotographbasedon photographsofknown people ComparefacesbynumericfacedistanceinsteadofonlyTrue/False matches Recognizefacesinlivevideousingyourwebcam-Simple/Slower Version(RequiresOpenCVtobe installed) Recognizefacesinlivevideousingyourwebcam-FasterVersion (RequiresOpenCVtobe installed) Recognizefacesinavideofileandwriteoutnewvideofile (RequiresOpenCVtobe installed) RecognizefacesonaRaspberryPiw/ camera RunawebservicetorecognizefacesviaHTTP(RequiresFlasktobe installed) RecognizefaceswithaK-nearestneighbors classifier HowFaceRecognitionWorks Ifyouwanttolearnhowfacelocationandrecognitionworkinsteadof dependingonablackboxlibrary,readmy article. Caveats Thefacerecognitionmodelistrainedonadultsanddoesnotwork verywellonchildren.Ittendstomix upchildrenquiteeasyusingthedefaultcomparisonthresholdof0.6. DeploymenttoCloudHosts(Heroku,AWS,etc) Sinceface_recognitiondependsondlibwhichiswrittenin C++,itcanbetrickytodeployanapp usingittoacloudhostingproviderlikeHerokuorAWS. Tomakethingseasier,there’sanexampleDockerfileinthisrepothat showshowtorunanappbuiltwith face_recognitioninaDocker container.Withthat,youshouldbeabletodeploy toanyservicethatsupportsDockerimages. CommonIssues Issue:Illegalinstruction(coredumped)whenusing face_recognitionorrunningexamples. Solution:dlibiscompiledwithSSE4orAVXsupport,butyourCPU istoooldanddoesn’tsupportthat. You’llneedtorecompiledlibaftermakingthecodechange outlined here. Issue: RuntimeError:Unsupportedimagetype,mustbe8bitgrayorRGBimage. whenrunningthewebcamexamples. Solution:Yourwebcamprobablyisn’tsetupcorrectlywithOpenCV.Look herefor more. Issue:MemoryErrorwhenrunningpip2installface_recognition Solution:Theface_recognition_modelsfileistoobigforyour availablepipcachememory.Instead, trypip2--no-cache-dirinstallface_recognitiontoavoidthe issue. Issue: AttributeError:'module'objecthasnoattribute'face_recognition_model_v1' Solution:Theversionofdlibyouhaveinstalledistooold.You needversion19.7ornewer.Upgradedlib. Issue: AttributeError:'Module'objecthasnoattribute'cnn_face_detection_model_v1' Solution:Theversionofdlibyouhaveinstalledistooold.You needversion19.7ornewer.Upgradedlib. Issue:TypeError:imread()gotanunexpectedkeywordargument'mode' Solution:Theversionofscipyyouhaveinstalledistooold.You needversion0.17ornewer.Upgradescipy. Thanks Many,manythankstoDavisKing (@nulhom) forcreatingdlibandforprovidingthetrainedfacialfeature detectionandfaceencodingmodels usedinthislibrary.FormoreinformationontheResNetthatpowers thefaceencodings,checkout hisblog post. ThankstoeveryonewhoworksonalltheawesomePythondatascience librarieslikenumpy,scipy,scikit-image, pillow,etc,etcthatmakesthiskindofstuffsoeasyandfunin Python. ThankstoCookiecutter andthe audreyr/cookiecutter-pypackage projecttemplate formakingPythonprojectpackagingwaymoretolerable. History 1.2.3(2018-08-21) Youcannowpassmodel=”small”toface_landmarks()tousethe5-pointfacemodelinsteadofthe68-pointmodel. NowofficiallysupportingPython3.7 NewexampleofusingthislibraryinaJupyterNotebook 1.2.2(2018-04-02) Addedtheface_detectionCLIcommand Removeddependenciesonscipytomakeinstallationeasier CleanedupKNNexampleandfixedabugwithdrawingfontstolabeldetectedfacesinthedemo 1.2.1(2018-02-01) Fixedversionnumberinginsideofmodulecode. 1.2.0(2018-02-01) Fixedabugwherebatchsizeparameterdidn’tworkcorrectlywhendoingbatchfacedetectionsonGPU. UpdatedOpenCVexamplestodoproperBGR->RGBconversion Updatedwebcamexamplestoavoidcommonmistakesandreducesupportquestions AddedaKNNclassificationexample Addedanexampleofautomaticallyblurringfacesinimagesorvideos UpdatedDockerfileexampletousedlibv19.9whichremovestheboostdependency. 1.1.0(2017-09-23) Willusedlib’s5-pointfaceposeestimatorwhenpossibleforspeed(insteadof68-pointfaceposeesimator) dlibv19.7isnowtheminimumrequiredversion face_recognition_modelsv0.3.0isnowtheminimumrequiredversion 1.0.0(2017-08-29) Addedsupportfordlib’sCNNfacedetectionmodelviamodel=”cnn”parameteronfacedetecioncall AddedsupportforGPUbatchedfacedetectionsusingdlib’sCNNfacedetectormodel Addedfind_faces_in_picture_cnn.pytoexamples Addedfind_faces_in_batches.pytoexamples Addedface_rec_from_video_file.pytoexamples dlibv19.5isnowtheminimumrequiredversion face_recognition_modelsv0.2.0isnowtheminimumrequiredversion 0.2.2(2017-07-07) Added–show-distancetocli Fixedabugwhere–tolerancewasignoredincliiftestingasingleimage Addedbenchmark.pytoexamples 0.2.1(2017-07-03) Added–tolerancetocli 0.2.0(2017-06-03) TheCLIcannowtakeadvantageofmultipleCPUs.Justpassinthe-cpusXparameterwhereXisthenumberofCPUstouse. Addedface_distance.pyexample ImprovedCLIteststoactuallytesttheCLIfunctionality Updatedfacerec_on_raspberry_pi.pytocaptureinrgb(notbgr)format. 0.1.14(2017-04-22) FixedaValueErrorcrashwhenusingtheCLIonPython2.7 0.1.13(2017-04-20) RaspberryPisupport. 0.1.12(2017-04-13) Fixed:Facelandmarkswasn’treturningallchinpoints. 0.1.11(2017-03-30) Fixedaminorbuginthecommand-lineinterface. 0.1.10(2017-03-21) Minorprefimprovementswithfacecomparisons. Testupdates. 0.1.9(2017-03-16) Fixminimumscipyversionrequired. 0.1.8(2017-03-16) FixmissingPillowdependency. 0.1.7(2017-03-13) Firstworkingrelease. Projectdetails Projectlinks Homepage Statistics GitHubstatistics: Stars: Forks: Openissues/PRs: ViewstatisticsforthisprojectviaLibraries.io,orbyusingourpublicdatasetonGoogleBigQuery Meta License:MITLicense(MITlicense) Author:AdamGeitgey Tags face_recognition Maintainers ageitgey Classifiers DevelopmentStatus 4-Beta IntendedAudience Developers License OSIApproved::MITLicense NaturalLanguage English ProgrammingLanguage Python::2 Python::2.7 Python::3 Python::3.5 Python::3.6 Python::3.7 Python::3.8 Releasehistory Releasenotifications| RSSfeed Thisversion 1.3.0 Feb20,2020 1.2.3 Aug21,2018 1.2.2 Apr2,2018 1.2.1 Feb1,2018 1.1.0 Feb1,2018 1.0.0 Aug29,2017 0.2.2 Aug7,2017 0.2.1 Aug3,2017 0.2.0 Jul3,2017 0.1.14 Apr22,2017 0.1.13 Apr20,2017 0.1.11 Mar30,2017 0.1.10 Mar21,2017 0.1.9 Mar16,2017 0.1.8 Mar16,2017 0.1.7 Mar13,2017 0.1.6 Mar6,2017 0.1.5 Mar6,2017 0.1.4 Mar6,2017 0.1.3 Mar4,2017 0.1.2 Mar4,2017 0.1.1 Mar4,2017 0.1.0 Mar4,2017 Downloadfiles Downloadthefileforyourplatform.Ifyou'renotsurewhichtochoose,learnmoreaboutinstallingpackages. SourceDistribution face_recognition-1.3.0.tar.gz (3.2MB viewhashes) Uploaded Feb20,2020 source BuiltDistribution face_recognition-1.3.0-py2.py3-none-any.whl (15.5kB viewhashes) Uploaded Feb20,2020 py2 py3 Close Hashesforface_recognition-1.3.0.tar.gz Hashesforface_recognition-1.3.0.tar.gz Algorithm Hashdigest SHA256 5e5efdd1686aa566af0d3cc1313b131e4b197657a8ffd03669e6d3fad92705ec Copy MD5 4e54f245f8fe4751a9f0ef5301a7cd40 Copy BLAKE2-256 6c4975dda409b94841f01cbbc34114c9b67ec618265084e4d12d37ab838f4fd3 Copy Close Close Hashesforface_recognition-1.3.0-py2.py3-none-any.whl Hashesforface_recognition-1.3.0-py2.py3-none-any.whl Algorithm Hashdigest SHA256 c543e91c8cfbf24d19db04e511ebbddcb23894bcee510133729ee78e9f4b5e83 Copy MD5 09b05a63345b4c9860bd83a84c48ea1d Copy BLAKE2-256 1e95f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0 Copy Close English español français 日本語 português(Brasil) українська Ελληνικά Deutsch 中文(简体) 中文(繁體) русский עברית esperanto Supportedby AWS Cloudcomputing Datadog Monitoring Facebook/Instagram PSFSponsor Fastly CDN Google ObjectStorageandDownloadAnalytics Huawei PSFSponsor Microsoft PSFSponsor NVIDIA PSFSponsor Pingdom Monitoring Salesforce PSFSponsor Sentry Errorlogging StatusPage Statuspage



請為這篇文章評分?