We-Co

[We-Co] Python Ai 얼굴인식 모델 및 구현 본문

Python/Tensorflow

[We-Co] Python Ai 얼굴인식 모델 및 구현

위기의코딩맨 2023. 5. 15. 12:37
반응형

안녕하세요. 위기의 코딩맨입니다.

오늘은 Python으로 얼굴인식 모델에 대해 알아보고 구현해보도록 하겠습니다.

[MobileNet]

해당 모델은 CPU환경에서도 가볍게 사용하기 위한 모델입니다.

하지만 다른 모델들 보다 성능은 떨어진다고 합니다.

컴퓨터 성능이 제한되거나 배터리 퍼포먼스가 중요한 곳에서 사용될 목적으로 설계된 Cnn 모델의 구조입니다.

사용은 드론이나 핸드폰 등에서 주로 사용됩니다.

 

MobileNet의 Github 

https://github.com/tensorflow/tfjs-models/tree/master/mobilenet

 

GitHub - tensorflow/tfjs-models: Pretrained models for TensorFlow.js

Pretrained models for TensorFlow.js. Contribute to tensorflow/tfjs-models development by creating an account on GitHub.

github.com

[Labeled Faces in the Wild]

해당 모델은 동영상 등 얼굴인식에서 99.38%의 정확도를 자랑하는 데이터셋 LFW로 많이 알려져 있습니다.

유명 정치인 등 많은 얼굴의 이미지 데이터를 기반으로 5749명의 13233개의 사진을 사용하고 있습니다.

Opencv와 함께 사용되기도 합니다!

LFW의 Github

https://github.com/ageitgey/face_recognition/blob/master/README_Korean.md

 

GitHub - ageitgey/face_recognition: The world's simplest facial recognition api for Python and the command line

The world's simplest facial recognition api for Python and the command line - GitHub - ageitgey/face_recognition: The world's simplest facial recognition api for Python and the command line

github.com

OpenCV의 Github

https://github.com/ukayzm/opencv/tree/master/unknown_face_classifier

 

GitHub - ukayzm/opencv: Practice OpenCV and TensorFlow

Practice OpenCV and TensorFlow. Contribute to ukayzm/opencv development by creating an account on GitHub.

github.com

 

[megaface]

일반인 이미지의 기반으로 얼굴인식 모델을 구현한 방식으로서 정확도는 많이 떨어진다고 알려져있습니다.

(출처 : https://koreascience.kr/article/JAKO201864236535544.pdf) 51p

 

megaface의 github

https://github.com/deepinx/megaface-evaluation/blob/master/gen_megaface.py  

 

GitHub - deepinx/megaface-evaluation: A Simple Tool to Evaluate Your Models on Megaface Benchmark Implemented in Python and Mxne

A Simple Tool to Evaluate Your Models on Megaface Benchmark Implemented in Python and Mxnet - GitHub - deepinx/megaface-evaluation: A Simple Tool to Evaluate Your Models on Megaface Benchmark Imple...

github.com

 

 

[ 구현 예제 ] 

간단한 예제를 한번 작성해보도록 하겠습니다.

python의  face recognition 라이브러리를 사용하여 예제를 작성했습니다.

!pip install face_recognition   

먼저 face_recognitaion을 설치해 줍니다.

import face_recognition
import cv2
from PIL import Image, ImageDraw
import numpy as np

사용하기 위한 라이브러리를 import해서 가져와 주고

image = face_recognition.load_image_file("/content/a.jpg")
face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn"
for face_location in face_locations:
    top, right, bottom, left = face_location 
    face_image = image[top:bottom, left:right]
    pil_image = Image.fromarray(face_image)
    pil_image.show()

얼굴 인식을 위한 이미지를 원하는 경로에 넣어줍니다.

그리고 face_lacations에 face_recognitaion의 face_locations를 사용하기 위한 이미지, 모델을 설정해줍니다.

그렇게되면 해당 이미지의 얼굴을 인식하고 정보를 얻을 수 있습니다.

 

지구오락실

 

해당 이미지를 입력으로 넣어보도록 하겠습니다.

결과

해당 이미지에 해당하는 얼굴 이미지를 출력한 결과 값입니다.

제 얼굴 이미지로 테스트를 진행 했을 경우에도 잘 인식하는 것을 확인했습니다.

 

오늘은 얼굴 인식 모델의 종류를 알아보고 그 중 하나의 모델을 사용해 보았습니다.

학습은 별도로 진행하진 않았지만 재밌엇습니다!

반응형