submission complete
This commit is contained in:
|
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 173 KiB |
File diff suppressed because one or more lines are too long
70
face_recognition.py
Normal file
70
face_recognition.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Untitled0.ipynb
|
||||
|
||||
Automatically generated by Colaboratory.
|
||||
|
||||
Original file is located at
|
||||
https://colab.research.google.com/drive/15cy6ue9c3bBkppUv3w09d9JJNebdeBuV
|
||||
"""
|
||||
|
||||
# Install deepface framework.
|
||||
!pip install deepface
|
||||
# Install matplotlib
|
||||
!pip install matplotlib
|
||||
!pip install dlib
|
||||
|
||||
# Load deepface libary
|
||||
from deepface import DeepFace
|
||||
# Import OpenCV to read images
|
||||
import cv2
|
||||
# Import matplotlib to plot images
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
|
||||
def verify(img1_path, img2_path):
|
||||
# read images
|
||||
img1 = cv2.imread('images/' + img1_path)
|
||||
img2 = cv2.imread('images/' + img2_path)
|
||||
|
||||
# plot images
|
||||
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
|
||||
plt.imshow(img1)
|
||||
plt.show()
|
||||
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
|
||||
plt.imshow(img2)
|
||||
plt.show()
|
||||
|
||||
# Loop models and print results
|
||||
models = ["DeepFace", "Facenet", "VGG-Face", "Dlib"]
|
||||
for model in models:
|
||||
result = DeepFace.verify('images/' + img1_path, 'images/' + img2_path, model_name = model)
|
||||
print (model + ' result: ', result)
|
||||
|
||||
verify("angelinajolie2.jpg", "angelinajolie4.jpg")
|
||||
|
||||
verify("jenniferaniston.jpg", "reesewitherspoon.jpg")
|
||||
|
||||
def find(img_path):
|
||||
# read images
|
||||
img = cv2.imread(img_path)
|
||||
|
||||
# plot images
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
plt.imshow(img)
|
||||
plt.show()
|
||||
|
||||
# Loop models and print results
|
||||
models = ["DeepFace", "Facenet", "VGG-Face"]
|
||||
for model in models:
|
||||
result = DeepFace.find(img_path, db_path = "images", model_name = model, distance_metric = 'cosine')
|
||||
print (model + ' result: ', result)
|
||||
# plot all verified images
|
||||
for result_table in result.iloc:
|
||||
print("File: " + result_table.identity)
|
||||
# plot image
|
||||
img = cv2.imread(result_table.identity)
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
plt.imshow(img)
|
||||
plt.show()
|
||||
|
||||
find("dicaprio.jpg")
|
||||
Reference in New Issue
Block a user