用OpenCV和深度學習進行年齡識別
點擊下方卡片,關注“新機器視覺”公眾號
視覺/圖像重磅干貨,第一時間送達
極市導讀
通過本文可Get如何使用OpenCV,深度學習和Python執(zhí)行年齡的自動識別/預測。擼完本教程您將能以相當高的精確度,預測靜態(tài)圖像文件、實時視頻中人的年齡。
用OpenCV和深度學習進行年齡識別
在本文的第一部分關于年齡識別,包括從圖片或視頻中自動預測人的年齡所需要的步驟(以及為何將年齡識別當做分類問題而不是回歸問題來處理)。
下面我們將介紹這個基于深度學習的年齡識別模型,然后學習如何將該模型應用在兩個方面:
-
靜態(tài)圖像中的年齡識別 -
實時視頻中的年齡識別
什么是年齡識別?
年齡識別是僅用人臉的照片去自動識別其年齡的過程,通常,年齡識別可分為兩個階段進行實現(xiàn):
-
階段1. :檢測輸入圖像/視頻中的人臉; -
階段2:提取人的面部區(qū)域(ROI),并通過年齡檢測算法預測人的年齡。
對于第一階段,可以使用任何能夠為圖片中的人臉生成邊框的人臉檢測器。這些檢測器包括但不限于Haar cascades,HOG+線性SVM,單鏡頭檢測器(SSD)等。
具體使用哪種人臉檢測器取決于您的項目:
-
Haar cascades速度很快,并且能夠在嵌入式設備上實時運行。缺點是準確度較低,并且極易出現(xiàn)假陽性檢測。 -
HOG+線性SVM模型比Haar cascades更精確,但速度較慢。它們對遮擋(即部分面部可見)或視角變化(即面部的不同視圖)的容錯性也較低。 -
基于深度學習的人臉檢測器功能最為強大,它提供了最高的準確度,但比Haar cascades和HOG+線性SVM需要更多的計算資源。
當選擇人臉檢測器時,需要花點時間考慮您的項目需求——速度或準確性,哪個對您更加重要?除此之外,還建議您對每個人臉檢測器進行試驗,以便從實驗結果中擇優(yōu)而從。
一旦您的人臉檢測器在圖像/視頻中生成了人臉的邊界框坐標,就可以進入第二階段——確定人的年齡。
確定了臉部的邊界框坐標(x,y)后,首先提取面部ROI,而忽略圖像/幀的其余部分。以便將年齡檢測器的注意力放在人臉上,而非圖像中其他不相關的“噪點”。然后將面部ROI傳遞給模型,從而得到實際的年齡預測。
年齡檢測器的算法有很多,但是最受歡迎的是基于深度學習的年齡檢測器——在本教程中,將使用這種基于深度學習的年齡檢測器。
基于深度學習的年齡檢測器模型
本文中使用的深度學習年齡檢測器模型是Levi和Hassner發(fā)表的《使用卷積神經(jīng)網(wǎng)絡進行年齡和性別分類》中構建和訓練的。該文作者提出了一個類似AlexNet的簡單體系,該體系總共學習了8個年齡段:
0-2 4-6 8-12 15-20 25-32 38-43 48-53 60-100
您可能會注意到這些年齡段是不連續(xù)的,這是有意而為。因為用于訓練模型的Adience數(shù)據(jù)集定義了年齡段(下一節(jié)中將介紹為什么這樣做)。
在這篇文章中,我們將使用預先訓練的年齡檢測器模型。如果您有興趣學習如何從頭開始訓練它,請務必閱讀《用Python進行計算機視覺深度學習》,在那里我將向您展示如何訓練。
我們?yōu)槭裁床粚⒛挲g預測看做回歸問題?
您會在上面注意到,我們將年齡離散化為"不同的區(qū)間”,從而將年齡預測作為分類問題——為什么不將它看做回歸問題?
從技術上講,沒有理由不能將年齡預測看做回歸任務。甚至有一些模型可以通過回歸來實現(xiàn)。問題在于年齡預測本質上是主觀的,并且僅基于容貌。
一個五十多歲的人,從未吸過煙、出門總是擦防曬霜、每天都要護理皮膚,相比一個三十多歲的人一天要抽很多煙、不擦防曬霜、從事體力勞動,且沒有適當?shù)钠つw護理的人,五十歲的人很可能看起來比三十歲的人年輕。
而且,基因是衰老最重要的驅動因素。有些人就是比其他人衰老得慢。
例如,看看下面的 Matthew Perry(在電視情景喜劇Friends中扮演Chandler Bing)的圖片,并將它與Jennifer Aniston(扮演Rachel Green)的圖片進行比較:
您能猜出 Matthew Perry(50歲)實際上比 Jennifer Aniston(51歲)小一歲嗎?若非您事先了解了關于這些演員的情況,否則我不會相信。
但另一方面,您能猜到這些演員在48-53歲嗎?這個準確率恐怕高一些。
雖然人類天生不擅長預測年齡的準確值,但我們實際上在預測年齡段方面還是不錯的。當然上面只是一個示例,Jennifer Aniston的基因近乎完美,再加上有非常優(yōu)秀的整形外科醫(yī)生,她似乎青春不老。
但這印證了我的觀點——如果人類準確地預測一個人的年齡很困難的話,那么機器肯定也會同樣困難。
一旦將年齡預測看做回歸問題,那么對于一個模型,要準確預測人的圖像中的年齡值是極困難的。但如果您將其視為分類問題,為模型定義了年齡段,那么我們的年齡預測模型將更容易訓練,通常會比基于回歸的預測提供更高的準確性。
簡而言之:將年齡預測看做分類問題可以極大地"緩解”準確程度——通常我們不需要一個人的確切年齡,粗略的估計就足夠了。
項目結構
您可從本文相關鏈接中獲取代碼,模型和圖片,提取文件后,您的項目將如下所示:
$ tree --dirsfirst
.
├── age_detector
│ ├── age_deploy.prototxt
│ └── age_net.caffemodel
├── face_detector
│ ├── deploy.prototxt
│ └── res10_300x300_ssd_iter_140000.caffemodel
├── images
│ ├── adrian.png
│ ├── neil_patrick_harris.png
│ └── samuel_l_jackson.png
├── detect_age.py
└── detect_age_video.py
3 directories, 9 files
前兩個目錄由年齡預測器和面部檢測器組成。這兩個深度學習模型都基于Caffe。
這里提供了三張用于年齡預測的測試圖片,您也可以添加自己的圖片。
在本教程的其余部分,我們將討論這兩個Python腳本:
-
detect\_age.py:圖片年齡預測 -
detect\_age\_video.py:視頻年齡預測
這些腳本都會檢測圖片/幀中的人臉,然后使用OpenCV對它們進行年齡預測。
運行該 OpenCV 圖像年齡檢測器
首先,開始在靜態(tài)圖像中使用OpenCV進行年齡檢測。在目錄中打開detect\_age.py文件,運行工作:
# import the necessary packages
import numpy as np
import argparse
import cv2
import os
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-f", "--face", required=True,
help="path to face detector model directory")
ap.add_argument("-a", "--age", required=True,
help="path to age detector model directory")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
為了啟動我們的年齡檢測器腳本,我們先導入NumPy和OpenCV。我建議查看我的pip install opencv教程來配置您的系統(tǒng)。
此外,需要導入Python內置的os模塊,它可以添加模型所需的路徑。
最后,導入argparse來解析命令行參數(shù)。
此處的腳本需要四個命令行參數(shù):
-
image:提供為年齡檢測輸入圖像的路徑 -
face:為預先訓練的面部檢測器模型提供路徑 -
age:預先訓練的年齡探測器模型 -
confidence:最小概率閾值,以便篩除低置信檢測
如上所述,本文的年齡檢測器是一種分類器,可以根據(jù)預定義的年齡分段,通過人的面部 ROI 預測這個人的年齡——我們不會將其視為回歸問題。現(xiàn)在讓我們定義這些年齡段的bucket:
# define the list of age buckets our age detector will predict
AGE_BUCKETS = ["(0-2)", "(4-6)", "(8-12)", "(15-20)", "(25-32)",
"(38-43)", "(48-53)", "(60-100)"]

我們的年齡是在預先訓練好的年齡檢測器的bucket(即類別標簽)中定義的。我們將使用此列表和相關的索引來獲取年齡段,從而在輸出的圖像上進行注釋。
完成了導入,命令行參數(shù)和年齡段的設置,我們現(xiàn)在就可以加載兩個預先訓練的模型:
# load our serialized face detector model from disk
print("[INFO] loading face detector model...")
prototxtPath = os.path.sep.join([args["face"], "deploy.prototxt"])
weightsPath = os.path.sep.join([args["face"],
"res10_300x300_ssd_iter_140000.caffemodel"])
faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
# load our serialized age detector model from disk
print("[INFO] loading age detector model...")
prototxtPath = os.path.sep.join([args["age"], "age_deploy.prototxt"])
weightsPath = os.path.sep.join([args["age"], "age_net.caffemodel"])
ageNet = cv2.dnn.readNet(prototxtPath, weightsPath)
在這里,我們加載兩個模型:
-
我們的人臉檢測器可以找到并定位圖片中的人臉(第25-28行) -
年齡分類器確定特定面孔所屬的年齡范圍(第32-34行)
這些模型均使用Caffe框架進行了訓練。在PyImageSearch Gurus課程中介紹了如何訓練Caffe分類器。
現(xiàn)在我們已經(jīng)完成了所有初始化,從磁盤加載圖像并檢測面部ROI:
# load the input image and construct an input blob for the image
image = cv2.imread(args["image"])
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300),
(104.0, 177.0, 123.0))
# pass the blob through the network and obtain the face detections
print("[INFO] computing face detections...")
faceNet.setInput(blob)
detections = faceNet.forward()
我們使用OpenCV的blobFromImage方法——請在我的教程中閱讀有關blobFromImage的更多信息。
為了檢測圖片中的人臉,我們通過CNN傳送blob,得到了detections的列表。現(xiàn)在讓我們循環(huán)面部ROI的檢測:
# loop over the detections
for i in range(0, detections.shape[2]):
# extract the confidence (i.e., probability) associated with the
# prediction
confidence = detections[0, 0, i, 2]
# filter out weak detections by ensuring the confidence is
# greater than the minimum confidence
if confidence > args["confidence"]:
# compute the (x, y)-coordinates of the bounding box for the
# object
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
# extract the ROI of the face and then construct a blob from
# *only* the face ROI
face = image[startY:endY, startX:endX]
faceBlob = cv2.dnn.blobFromImage(face, 1.0, (227, 227),
(78.4263377603, 87.7689143744, 114.895847746),
swapRB=False)
當我們循環(huán)detections時,我們清除了低置信度的面部(第51-55行)。
對于滿足了最低置信度標準的面部,我們提取它們的ROI坐標(第58-63行)。現(xiàn)在,我們在僅包含單個面部的圖像中有了小小收獲。我們在第64-66行根據(jù)此ROI創(chuàng)建一個blob(即faceBlob)。
現(xiàn)在,我們將進行年齡識別:
# make predictions on the age and find the age bucket with
# the largest corresponding probability
ageNet.setInput(faceBlob)
preds = ageNet.forward()
i = preds[0].argmax()
age = AGE_BUCKETS[i]
ageConfidence = preds[0][i]
# display the predicted age to our terminal
text = "{}: {:.2f}%".format(age, ageConfidence * 100)
print("[INFO] {}".format(text))
# draw the bounding box of the face along with the associated
# predicted age
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(image, (startX, startY), (endX, endY),
(0, 0, 255), 2)
cv2.putText(image, text, (startX, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
# display the output image
cv2.imshow("Image", image)
cv2.waitKey(0)
我們使用face blob進行年齡預測(第70-74行),從而得出年齡段和年齡的置信度。我們使用這些數(shù)據(jù)點以及面部ROI的坐標來注釋最初輸入的圖片(第77-86行)并顯示結果(第89和90行)。
在下一部分中,我們將分析結果。
OpenCV的年齡識別結果
讓我們運行OpenCV年齡檢測器。
首先,從本教程的"下載"部分下載源代碼,預先訓練的年齡檢測器模型及示例圖像。
從那里打開一個終端,然后執(zhí)行以下命令:
$ python detect_age.py --image images/adrian.png --face face_detector --age age_detector
[INFO] loading face detector model...
[INFO] loading age detector model...
[INFO] computing face detections...
[INFO] (25-32): 57.51%
在這里,您可以看到我們的OpenCV年齡檢測器以57.51%的置信度預測了我的年齡為25-32歲——實際上,該年齡檢測器是正確的(我拍攝這張照片時是30歲)。
讓我們再舉一個例子,這是著名演員Neil Patrick Harris小時候的照片:
$ python detect_age.py --image images/neil_patrick_harris.png --face face_detector --age age_detector
[INFO] loading face detector model...
[INFO] loading age detector model...
[INFO] computing face detections...
[INFO] (8-12): 85.72%
我們的年齡預測是正確的,拍攝這張照片時,Nat Patrick Harris看起來的確在8-12歲年齡段中的某個年齡。
嘗試另一張圖片:Samuel L. Jackson,他是我最喜歡的演員之一:
$ python detect_age.py --image images/samuel_l_jackson.png --face face_detector --age age_detector
[INFO] loading face detector model...
[INFO] loading age detector model...
[INFO] computing face detections...
[INFO] (48-53): 69.38%
OpenCV年齡檢測器針對Samuel L. Jackson的結果出錯了——Jackson大約71歲,年齡預測大約有18歲的偏差。
僅僅看照片Jackson先生看上去像71歲嗎?我猜測應該是50到60歲左右,他不像70歲多一點的男人。但這恰恰印證了我在前文提出的觀點:
用視覺進行年齡預測的過程很困難,當計算機或人試圖猜測某人的年齡時,我認為這是主觀的。
為了評估年齡檢測器,不能依賴人的實際年齡去評價。相反,需要衡量預測年齡和感知年齡之間的準確度。
為實時視頻運行我們的OpenCV年齡檢測器
現(xiàn)在我們可以在靜態(tài)圖像中實現(xiàn)年齡檢測,但實時視頻可以嗎?
您應該猜我們可以。我們的視頻腳本與圖像腳本非常相似。不同之處在于,我們需要設置視頻流并在每個幀上循環(huán)進行年齡檢測。本文將重點介紹視頻功能,可根據(jù)需要參考上面的流程。
要了解如何在視頻中進行年齡識別,那就來看看detect\_age\_video.py。
# import the necessary packages
from imutils.video import VideoStream
import numpy as np
import argparse
import imutils
import time
import cv2
import os
我們需要導入三個新的模塊:
-
VideoStream -
imutils -
time
這些導入允許我們對視頻進行設置和使用webcam功能。
我決定定義一個快捷函數(shù)來獲取幀,定位面部并預測年齡。函數(shù)通過進行檢測和邏輯預測,使我們的幀處理循環(huán)不會那么龐大(您也可以將此函數(shù)放到單獨的文件中)?,F(xiàn)在讓我們進入這個程序:
def detect_and_predict_age(frame, faceNet, ageNet, minConf=0.5):
# define the list of age buckets our age detector will predict
AGE_BUCKETS = ["(0-2)", "(4-6)", "(8-12)", "(15-20)", "(25-32)",
"(38-43)", "(48-53)", "(60-100)"]
# initialize our results list
results = []
# grab the dimensions of the frame and then construct a blob
# from it
(h, w) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300),
(104.0, 177.0, 123.0))
# pass the blob through the network and obtain the face detections
faceNet.setInput(blob)
detections = faceNet.forward()
我們的 detect\_and\_predict\_age 輔助函數(shù)接受以下參數(shù):
-
frame:視頻通過webcam獲取的單個幀 -
faceNet:初始化的深度學習人臉檢測器 -
ageNet:初始化的深度學習年齡分類器 -
minConf:篩去較差人臉識別的置信度閾值
這里的參數(shù)和我們的圖片年齡檢測器腳本的命令行參數(shù)是相似的。
我們的AGE\_BUCKETS再次被定義(第12和13行)。然后我們定義一個空列表來保存面部定位和年齡檢測的results。(第20-26行進行面部檢測。)
接下來,我們將處理每個detections:
# loop over the detections
for i in range(0, detections.shape[2]):
# extract the confidence (i.e., probability) associated with
# the prediction
confidence = detections[0, 0, i, 2]
# filter out weak detections by ensuring the confidence is
# greater than the minimum confidence
if confidence > minConf:
# compute the (x, y)-coordinates of the bounding box for
# the object
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
# extract the ROI of the face
face = frame[startY:endY, startX:endX]
# ensure the face ROI is sufficiently large
if face.shape[0] < 20 or face.shape[1] < 20:
continue
請看29-43行——它們循環(huán)檢測,以確保較高的置信度,然后提取出面部ROI。
第46-47行是新的——由于以下兩個原因,我們要確保視頻中的面部ROI足夠大:
-
首先,我們要篩掉幀中檢測到的假陽性面部。 -
其次,年齡分類結果對于遠離相機的臉(即臉部很小)來說并不準確。
為了完成我們的輔助功能,我們將進行年齡識別并返回結果:
# construct a blob from *just* the face ROI
faceBlob = cv2.dnn.blobFromImage(face, 1.0, (227, 227),
(78.4263377603, 87.7689143744, 114.895847746),
swapRB=False)
# make predictions on the age and find the age bucket with
# the largest corresponding probability
ageNet.setInput(faceBlob)
preds = ageNet.forward()
i = preds[0].argmax()
age = AGE_BUCKETS[i]
ageConfidence = preds[0][i]
# construct a dictionary consisting of both the face
# bounding box location along with the age prediction,
# then update our results list
d = {
"loc": (startX, startY, endX, endY),
"age": (age, ageConfidence)
}
results.append(d)
# return our results to the calling function
return results
在這里預測人臉的年齡并提取出年齡段和年齡置信度(第56-60行)。第65-68行在一個字典中存儲面部定位和年齡預測。循環(huán)檢測的最后一步是將該字典放到結果列表中(第69行)。
如果所有檢測都已經(jīng)完成,并且結果都得到了,那我們將結果返回給調用者。
定義好輔助函數(shù)后,現(xiàn)在我們可以繼續(xù)處理視頻了。但我們需要先定義命令行參數(shù):
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--face", required=True,
help="path to face detector model directory")
ap.add_argument("-a", "--age", required=True,
help="path to age detector model directory")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
我們的腳本需要三個命令行參數(shù):
-
face:預先訓練的面部檢測器模型的目錄的路徑 -
age:預先訓練的年齡檢測器模型的目錄 -
confidence:最小概率閾值,以便篩除低置信檢測
在這里,我們將加載模型并初始化視頻:
# load our serialized face detector model from disk
print("[INFO] loading face detector model...")
prototxtPath = os.path.sep.join([args["face"], "deploy.prototxt"])
weightsPath = os.path.sep.join([args["face"],
"res10_300x300_ssd_iter_140000.caffemodel"])
faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
# load our serialized age detector model from disk
print("[INFO] loading age detector model...")
prototxtPath = os.path.sep.join([args["age"], "age_deploy.prototxt"])
weightsPath = os.path.sep.join([args["age"], "age_net.caffemodel"])
ageNet = cv2.dnn.readNet(prototxtPath, weightsPath)
# initialize the video stream and allow the camera sensor to warm up
print("[INFO] starting video stream...")
vs = VideoStream(src=0).start()
time.sleep(2.0)
第86-89行加載并初始化了我們的面部檢測器,而第93-95行加載了年齡檢測器。
然后,我們使用VideoStream類來初始化webcam(第99和100行)。webcam準備好后,我們將開始處理幀:
# loop over the frames from the video stream
while True:
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
frame = vs.read()
frame = imutils.resize(frame, width=400)
# detect faces in the frame, and for each face in the frame,
# predict the age
results = detect_and_predict_age(frame, faceNet, ageNet,
minConf=args["confidence"])
# loop over the results
for r in results:
# draw the bounding box of the face along with the associated
# predicted age
text = "{}: {:.2f}%".format(r["age"][0], r["age"][1] * 100)
(startX, startY, endX, endY) = r["loc"]
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(frame, (startX, startY), (endX, endY),
(0, 0, 255), 2)
cv2.putText(frame, text, (startX, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
# show the output frame
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()
在上面的循環(huán)中,我們:
-
獲取幀,并將其調整為已知寬度(第106和107行) -
通過我們的 detect_and_predict_age便捷函數(shù)傳遞幀,以便(1)檢測面部(2)確定年齡(第111和112行) -
在幀上注釋結果(第115-124行) -
顯示和捕獲鍵盤輸入(第127和128行) -
如果鍵入 q,那么退出并清空(第131-136行)
在下一節(jié)中,我們將啟動年齡檢測器,看看它是否有效!
使用OpenCV進行實時年齡檢測的結果
現(xiàn)在,讓我們將OpenCV年齡檢測器應用于實時視頻。
確保您已從本教程的"下載"部分下載源代碼和預先訓練的年齡檢測器。
從那里打開一個終端,然后輸入以下命令:
$ python detect_age_video.py --face face_detector --age age_detector
[INFO] loading face detector model...
[INFO] loading age detector model...
[INFO] starting video stream...
在這里,您可以看到OpenCV年齡檢測器將我的年齡范圍準確地預測為25-32歲(在寫本文時,我還是31歲)。
如何改善年齡預測結果?
由Levi和Hassner訓練的年齡預測模型的問題之一是,它嚴重偏向25-32歲年齡組,如他們原始版本中的這個混淆矩陣表所示:
為了在您的模型中解決此問題,請考慮收集更多的訓練數(shù)據(jù),使用類權重、數(shù)據(jù)擴充和正則化技術。
不幸的是,這意味著我們的模型預測的25-32歲結果可能實際上屬于其他的年齡段——在分析本教程的結果以及我自己的年齡預測中也遇到了幾次這樣的情況。
您可以通過以下方法消除這種偏差:
-
收集其他年齡段的額外訓練數(shù)據(jù)以幫助平衡數(shù)據(jù)集; -
使用類權重來處理類失衡的問題; -
注意數(shù)據(jù)擴充; -
訓練模型時使用正則化。
其次,年齡預測結果可以通過使用人臉對齊來改善。
人臉對齊功能會識別人臉的幾何結構,然后嘗試使用平移,縮放和旋轉獲得人臉的規(guī)范化。
在許多情況下(但并非總是如此),人臉對齊可以改善面部應用的效果,包括面部識別,年齡預測等。
為簡單起見,我們在本教程中沒有使用人臉對齊功能,但您可以按照這個教程學習有關人臉對齊的更多信息,然后將其應用于自己的年齡預測程序中。
性別預測呢?
我特意選擇不在本教程中介紹性別預測。
使用計算機視覺和深度學習來識別一個人的性別似乎是一個有趣的分類問題,但實際上這是一個道德問題。
某人在視覺上看上去怎樣,穿著什么或如何表現(xiàn),這些都并不意味著他們可能是某種(或其他)性別。
試圖將性別劃分為兩類的軟件只會把我們束縛在對于性別的過時觀念里。因此,我鼓勵您盡可能不要在自己的程序中使用性別識別。
如果必須進行性別識別,請確保對自己負責,并確保您不去創(chuàng)建使他人遵循性別偏見的應用程序(例如根據(jù)感知到的性別去定義用戶體驗)。
性別識別幾乎沒有價值,而且它引起的問題比它解決的問題還要多。請盡可能避免它。
總結
在本教程中,您學習了如何使用OpenCV通過深度學習進行年齡識別。
為此,我們利用了Levi和Hassner在2015年出版的《使用卷積神經(jīng)網(wǎng)絡進行年齡和性別分類》中的預訓練模型。該模型使我們能夠以相當高的準確度去預測八個不同的年齡段;但是,我們必須認識到年齡預測是一個很有挑戰(zhàn)性的問題。
有很多因素可以決定一個人的視覺年齡,包括他們的生活方式,工作,吸煙習慣,最重要的是基因。其次,請記住,人們試圖掩飾自己的年齡——如果人類準確地預測某人的年齡有困難的話,那么機器學習模型同樣會有困難。
因此,您需要根據(jù)感知年齡(而非實際年齡)去評估所有的年齡預測結果。在您自己的計算機視覺項目中進行年齡識別時,請記住這一點。
希望您喜歡本教程!
原文鏈接:https://www.pyimagesearch.com/2020/04/13/opencv-age-detection-with-deep-learning
—版權聲明—
僅用于學術分享,版權屬于原作者。
若有侵權,請聯(lián)系微信號:yiyang-sy 刪除或修改!
