Spaces:
Runtime error
Runtime error
Henry Lydecker
commited on
Commit
•
d70cad8
1
Parent(s):
e7a6f18
Add Alphav1 application file
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Are you wearing a mask?
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
import torchvision
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
# Face masks
|
9 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', "model_weights/face_masks_full.pt")
|
10 |
+
|
11 |
+
# Animals
|
12 |
+
# model = torch.hub.load('ultralytics/yolov5', 'custom', "model_weights/datasets_1000_41class.pt",force_reload=True)
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
def yolo(im, size=640):
|
17 |
+
g = (size / max(im.size)) # gain
|
18 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
19 |
+
|
20 |
+
results = model(im) # inference
|
21 |
+
results.render() # updates results.imgs with boxes and labels
|
22 |
+
return Image.fromarray(results.imgs[0])
|
23 |
+
|
24 |
+
|
25 |
+
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
26 |
+
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
27 |
+
|
28 |
+
title = "Detecting masked and unmasked faces with YOLOv5"
|
29 |
+
description = "YOLOv5 Gradio demo for finding faces with and without masks, using object detection. Upload an image or click an example image to use."
|
30 |
+
article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
|
31 |
+
|
32 |
+
examples = [['data/picard.jpg'], ['data/stockmasks.jpg'],['data/batman.png']]
|
33 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(cache_examples=True,enable_queue=True)
|