File size: 4,254 Bytes
d68691f e8dfdf0 d68691f a2f410a d68691f a2f410a 23df74f a2f410a 23df74f d68691f e8dfdf0 0b5779b 99ea7e6 0b5779b e8dfdf0 d68691f 85b6cb5 23df74f 6ac5477 63e4913 6ac5477 63e4913 6ac5477 63e4913 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
import gradio as gr
from deepface import DeepFace
def face_similarity(img1, img2):
result = DeepFace.verify(img1, img2)
# distance๋ฅผ ์ด์ฉํด ์ ์ฌ๋๋ฅผ 1์์ ๋นผ์ ๋์์๋ก ์ ์ฌํ๊ฒ ๋ณํ
similarity = (1 - result["distance"])*100
# ์ ์ฌ๋์ ๋ฐ๋ฅธ ๋ฉ์์ง ์กฐ๊ฑด ๋ถ๊ธฐ
if similarity > 40:
message = "๋ ๋ถ์ ์ฒ์์ฐ๋ถ!"
elif 30 < similarity <= 40:
message = "๋ ๋ถ์ ๋ด๊บผ์ธ๋ฏ ๋ด๊บผ์๋ ๋ด๊บผ๊ฐ์...?"
else:
message = "์คํ๋ ค ์ข์! ์ ๋ฐ๋์ ์ฌ๋์ด ๋๋ฆด์ง๋ ๋ชฐ๋ผ์"
return f"์ ์ฌ๋: {similarity:.2f}\n{message}"
iface = gr.Interface(
fn=face_similarity,
inputs=[gr.Image(type="numpy"), gr.Image(type="numpy")],
outputs="text",
title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ",
description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค."
)
iface.launch()
# import gradio as gr
# from deepface import DeepFace
# def face_similarity(img1, img2):
# result = DeepFace.verify(img1, img2)
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ
# verified = result["verified"]
# # ์ ์ฌ๋์ ๋ฐ๋ฅธ ๋ฉ์์ง ์กฐ๊ฑด ๋ถ๊ธฐ
# if similarity >= 0.5:
# message = "๋ ๋ถ์ ์ฒ์์ฐ๋ถ!"
# elif 0.3 <= similarity < 0.5:
# message = "๋ ๋ถ์ ๋ด๊บผ์ธ๋ฏ ๋ด๊บผ์๋ ๋ด๊บผ๊ฐ์...?"
# else:
# message = "์คํ๋ ค ์ข์! ์ ๋ฐ๋์ ์ฌ๋์ด ๋๋ฆด์ง๋ ๋ชฐ๋ผ์"
# return f"์ ์ฌ๋: {similarity}, ๋งค์นญ ๊ฒฐ๊ณผ: {verified}\n{message}"
# iface = gr.Interface(fn=face_similarity,
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))],
# outputs="text",
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ",
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.")
# iface.launch()
# import gradio as gr
# from deepface import DeepFace
# def face_similarity(img1, img2):
# result = DeepFace.verify(img1, img2)
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ
# verified = result["verified"]
# return f"์ ์ฌ๋: {similarity}, ๋งค์นญ ๊ฒฐ๊ณผ: {verified}"
# iface = gr.Interface(fn=face_similarity,
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))],
# outputs="text",
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ",
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.")
# iface.launch()
# import gradio as gr
# from deepface import DeepFace
# import pandas as pd
# from PIL import Image
# import numpy as np
# # ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ
# results = []
# def save_results(img1_path, img2_path, similarity):
# # ๊ฒฐ๊ณผ๋ฅผ ๊ธ๋ก๋ฒ ๋ฆฌ์คํธ์ ์ถ๊ฐ
# results.append([img1_path, img2_path, similarity])
# # ๊ฒฐ๊ณผ๋ฅผ pandas DataFrame์ผ๋ก ๋ณํ
# df = pd.DataFrame(results, columns=['Image 1', 'Image 2', 'Similarity'])
# # DataFrame์ CSV ํ์ผ๋ก ์ ์ฅ
# df.to_csv('similarity_results.csv', index=False)
# def face_similarity(img1, img2):
# result = DeepFace.verify(img1, img2)
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ
# verified = result["verified"]
# # ์ด๋ฏธ์ง ํ์ผ ์ ์ฅ
# img1_path = f"img1_{len(results)}.jpg"
# img2_path = f"img2_{len(results)}.jpg"
# # Convert img1 and img2 to PIL.Image objects and save them
# img1_pil = Image.fromarray(img1.astype(np.uint8))
# img2_pil = Image.fromarray(img2.astype(np.uint8))
# img1_pil.save(img1_path)
# img2_pil.save(img2_path)
# # ๊ฒฐ๊ณผ ์ ์ฅ
# save_results(img1_path, img2_path, similarity)
# return f"์ ์ฌ๋: {similarity}, ์ธ์ฆ ๊ฒฐ๊ณผ: {verified}"
# iface = gr.Interface(fn=face_similarity,
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))],
# outputs="text",
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ",
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.")
# iface.launch()
|