Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Deploy Barcelo demo.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1FxaL8DcYgvjPrWfWruSA5hvk3J81zLY9
|
8 |
+
|
9 |
+
![ ](https://www.vicentelopez.gov.ar/assets/images/logo-mvl.png)
|
10 |
+
|
11 |
+
# Modelo
|
12 |
+
|
13 |
+
YOLO es una familia de modelos de detecci贸n de objetos a escala compuesta entrenados en COCO dataset, e incluye una funcionalidad simple para Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, and export to ONNX, CoreML and TFLite.
|
14 |
+
|
15 |
+
|
16 |
+
## Gradio Inferencia
|
17 |
+
|
18 |
+
![](https://i.ibb.co/982NS6m/header.png)
|
19 |
+
|
20 |
+
Este Notebook se acelera opcionalmente con un entorno de ejecuci贸n de GPU
|
21 |
+
|
22 |
+
|
23 |
+
----------------------------------------------------------------------
|
24 |
+
|
25 |
+
YOLOv5 Gradio demo
|
26 |
+
|
27 |
+
*Author: Ultralytics LLC and Gradio*
|
28 |
+
|
29 |
+
# C贸digo
|
30 |
+
"""
|
31 |
+
|
32 |
+
!pip install -qr https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt gradio # install dependencies
|
33 |
+
|
34 |
+
import gradio as gr
|
35 |
+
import torch
|
36 |
+
from PIL import Image
|
37 |
+
|
38 |
+
# Images
|
39 |
+
torch.hub.download_url_to_file('https://i.pinimg.com/originals/7f/5e/96/7f5e9657c08aae4bcd8bc8b0dcff720e.jpg', 'ejemplo1.jpg')
|
40 |
+
torch.hub.download_url_to_file('https://i.pinimg.com/originals/c2/ce/e0/c2cee05624d5477ffcf2d34ca77b47d1.jpg', 'ejemplo2.jpg')
|
41 |
+
|
42 |
+
# Model
|
43 |
+
#model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
|
44 |
+
|
45 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='/content/best.pt') # local model o google colab
|
46 |
+
#model = torch.hub.load('path/to/yolov5', 'custom', path='/content/yolov56.pt', source='local') # local repo
|
47 |
+
|
48 |
+
def yolo(im, size=640):
|
49 |
+
g = (size / max(im.size)) # gain
|
50 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
51 |
+
|
52 |
+
results = model(im) # inference
|
53 |
+
results.render() # updates results.imgs with boxes and labels
|
54 |
+
return Image.fromarray(results.imgs[0])
|
55 |
+
|
56 |
+
|
57 |
+
inputs = gr.inputs.Image(type='pil', label=" Imagen Original")
|
58 |
+
outputs = gr.outputs.Image(type="pil", label="Resultado")
|
59 |
+
|
60 |
+
title = 'Trampas Barcel贸'
|
61 |
+
|
62 |
+
description = "Sistemas de Desarrollado por Subcretar铆a de Innovaci贸n del Municipio de Vicente Lopez"
|
63 |
+
|
64 |
+
article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes " \
|
65 |
+
"simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, " \
|
66 |
+
"and export to ONNX, CoreML and TFLite. <a href='https://colab.research.google.com/drive/1fbeB71yD09WK2JG9P3Ladu9MEzQ2rQad?usp=sharing'>Source code</a> |" \
|
67 |
+
"<a href='https://colab.research.google.com/drive/1FxaL8DcYgvjPrWfWruSA5hvk3J81zLY9?usp=sharing'>Colab Deploy</a> | <a href='https://github.com/ultralytics/yolov5'>PyTorch Hub</a></p>"
|
68 |
+
|
69 |
+
examples = [['ejemplo1.jpg'], ['ejemplo2.jpg']]
|
70 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(
|
71 |
+
debug=True)
|
72 |
+
|
73 |
+
"""For YOLOv5 PyTorch Hub inference with **PIL**, **OpenCV**, **Numpy** or **PyTorch** inputs please see the full [YOLOv5 PyTorch Hub Tutorial](https://github.com/ultralytics/yolov5/issues/36).
|
74 |
+
|
75 |
+
|
76 |
+
## Citation
|
77 |
+
|
78 |
+
[![DOI](https://zenodo.org/badge/264818686.svg)](https://zenodo.org/badge/latestdoi/264818686)
|
79 |
+
"""
|