Winston de Jong
commited on
Commit
·
fdfeac0
1
Parent(s):
bb3348b
Add certainty metric to UI
Browse files- __pycache__/face_detection.cpython-312.pyc +0 -0
- app.py +6 -6
__pycache__/face_detection.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/face_detection.cpython-312.pyc and b/__pycache__/face_detection.cpython-312.pyc differ
|
|
|
app.py
CHANGED
|
@@ -75,7 +75,7 @@ def process_image_str(groupImageFilePath: str):
|
|
| 75 |
groupImage_d = ImageDraw.ImageDraw(groupImage)
|
| 76 |
font = ImageFont.truetype("Arial Bold.ttf", 30)
|
| 77 |
|
| 78 |
-
labels = ""
|
| 79 |
n = 1
|
| 80 |
|
| 81 |
for image, location in zip(images, locations):
|
|
@@ -85,22 +85,22 @@ def process_image_str(groupImageFilePath: str):
|
|
| 85 |
# do AI stuff here
|
| 86 |
with torch.no_grad():
|
| 87 |
outputs_t = model(intputTensor)
|
| 88 |
-
|
| 89 |
groupImage_d.rectangle(location, outline=(0, 255, 0), width=2)
|
| 90 |
groupImage_d.text((location[0] + 4, location[1] + 2), f"{n}", fill=(0, 255, 0), font=font)
|
| 91 |
-
labels += f"{n}
|
| 92 |
|
| 93 |
n += 1
|
| 94 |
|
| 95 |
-
return [gr.Image(groupImage), gr.
|
| 96 |
# return gr.Image(images[0])
|
| 97 |
|
| 98 |
|
| 99 |
# 5. Create the Gradio interface
|
| 100 |
interface = gr.Interface(
|
| 101 |
fn=process_image_str, # Function to process the image
|
| 102 |
-
inputs=gr.Image(type='filepath'), # Upload input
|
| 103 |
-
outputs=[gr.Image(), gr.
|
| 104 |
allow_flagging='never',
|
| 105 |
title="Celebrity Face Detector",
|
| 106 |
description="Upload a picture of a celebrity or group of celebrities to identify them"
|
|
|
|
| 75 |
groupImage_d = ImageDraw.ImageDraw(groupImage)
|
| 76 |
font = ImageFont.truetype("Arial Bold.ttf", 30)
|
| 77 |
|
| 78 |
+
labels = "| | Name | Certainty | \n | -------- | ------- | ------- |\n"
|
| 79 |
n = 1
|
| 80 |
|
| 81 |
for image, location in zip(images, locations):
|
|
|
|
| 85 |
# do AI stuff here
|
| 86 |
with torch.no_grad():
|
| 87 |
outputs_t = model(intputTensor)
|
| 88 |
+
cert, pred_t = torch.max(torch.softmax(outputs_t, dim=1), dim=1)
|
| 89 |
groupImage_d.rectangle(location, outline=(0, 255, 0), width=2)
|
| 90 |
groupImage_d.text((location[0] + 4, location[1] + 2), f"{n}", fill=(0, 255, 0), font=font)
|
| 91 |
+
labels += f"| {n} | {celeb_list[pred_t.item()]} | {int(cert.item() * 100)}% | \n"
|
| 92 |
|
| 93 |
n += 1
|
| 94 |
|
| 95 |
+
return [gr.Image(groupImage), gr.Markdown(labels)]
|
| 96 |
# return gr.Image(images[0])
|
| 97 |
|
| 98 |
|
| 99 |
# 5. Create the Gradio interface
|
| 100 |
interface = gr.Interface(
|
| 101 |
fn=process_image_str, # Function to process the image
|
| 102 |
+
inputs=gr.Image(type='filepath', label="Input Image"), # Upload input
|
| 103 |
+
outputs=[gr.Image(label="Output"), gr.Markdown(label="Output Legend")], # Display output
|
| 104 |
allow_flagging='never',
|
| 105 |
title="Celebrity Face Detector",
|
| 106 |
description="Upload a picture of a celebrity or group of celebrities to identify them"
|