Spaces:
Runtime error
Runtime error
Upload application files
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Images
|
| 6 |
+
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
|
| 7 |
+
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
|
| 8 |
+
|
| 9 |
+
# Model
|
| 10 |
+
model_name ='fire_model.pt' # force_reload=True to update
|
| 11 |
+
|
| 12 |
+
if model_name:
|
| 13 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_name, force_reload=True)
|
| 14 |
+
else:
|
| 15 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def yolo(im, size=640):
|
| 19 |
+
g = (size / max(im.size)) # gain
|
| 20 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
| 21 |
+
|
| 22 |
+
results = model(im) # inference
|
| 23 |
+
results.render() # updates results.imgs with boxes and labels
|
| 24 |
+
return Image.fromarray(results.imgs[0])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
| 28 |
+
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
| 29 |
+
|
| 30 |
+
title = "YOLOv5"
|
| 31 |
+
description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
|
| 32 |
+
article = "<p style='text-align: center'> THis Demo is meant to detect specific models of fire extinguishers , trained on an artificially generated dataset from IFC MODEL with Blender" \
|
| 33 |
+
"The aim is to simulate real world fire extinguishers as much possible in order for the object detector to recognizeit" \
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
examples = [['23327.png'], ['download.jpg']]
|
| 38 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(
|
| 39 |
+
debug=True)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# try again
|