python训练模型识别人脸性别及年龄代码
代码语言:python
所属分类:人工智能
代码描述:python训练模型识别人脸性别及年龄代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#A Gender and Age Detection program by Mahesh Sawant import cv2 import math # import argparse def highlightFace(net, frame, conf_threshold=0.7): frameOpencvDnn=frame.copy() frameHeight=frameOpencvDnn.shape[0] frameWidth=frameOpencvDnn.shape[1] blob=cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False) net.setInput(blob) detections=net.forward() faceBoxes=[] for i in range(detections.shape[2]): confidence=detections[0,0,i,2] if confidence>conf_threshold: x1=int(detections[0,0,i,3]*frameWidth) y1=int(detections[0,0,i,4]*frameHeight) x2=int(detections[0,0,i,5]*frameWidth) y2=int(detections[0,0,i,6]*frameHeight) faceBoxes.append([x1,y1,x2,y2]) cv2.rectangle(frameOpencvDnn, (x1,y1), (x2,y2), (0,255,0), int(round(frameHeight/150)), 8) return frameOpencvDnn,faceBoxes # parser=argparse.ArgumentParser() # parser.add_argument('--image') # args=parser.parse_args() faceProto="/data/wwwroot/default/model/opencv_face_detector.pbtxt" faceModel="/data/wwwroot/default/model/opencv_face_detector_uint8.pb" ageProto="/data/wwwroot/default/model/age_deploy.prototxt" ageModel="/data/wwwroot/default/model/age_net.caffemodel" genderProto="/data/wwwroot/default/model/gender_deploy.prototxt" genderModel="/data/wwwroot/default/model/gender_net.caffemodel" MODEL_MEAN_VALUES=(78.4263377603, 87.7689143744, 114.895847746) ageList=['(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32).........完整代码请登录后点击上方下载按钮下载查看
网友评论0