galatasaray commited on
Commit
71496cd
1 Parent(s): 7ad803f

WriteCommit

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
11
+ model = torch.hub.load('/yolov5', 'custom', path='/saved_model/s1000_best.pt', source='local') # local model
12
+
13
+
14
+ def yolo(im, size=640):
15
+ g = (size / max(im.size)) # gain
16
+ im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
17
+
18
+ results = model(im) # inference
19
+ results.render() # updates results.imgs with boxes and labels
20
+ return Image.fromarray(results.imgs[0])
21
+
22
+
23
+ inputs = gr.inputs.Image(type='pil', label="Original Image")
24
+ outputs = gr.outputs.Image(type="pil", label="Output Image")
25
+
26
+ title = "S1000 Detection"
27
+ description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
28
+ article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes " \
29
+ "simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, " \
30
+ "and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> |" \
31
+ "<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
32
+
33
+ path_folder = '/datasets/s1000/'
34
+ examples = [[path_folder+'s1000 (1).png'], [path_folder+'s1000 (2).png'],[path_folder+'s1000 (3).png'],[path_folder+'s1000 (4).png'],[path_folder+'s1000 (5).png']]
35
+ gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(
36
+ debug=True)