Upload folder using huggingface_hub
Browse files- README.md +2 -8
- requirements.txt +2 -0
- visualizar_interactivo_RINT.py +61 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: RINT
|
| 3 |
-
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: RINT
|
| 3 |
+
app_file: visualizar_interactivo_RINT.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 4.44.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ultralytics
|
| 2 |
+
opencv-python
|
visualizar_interactivo_RINT.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
|
| 4 |
+
import cv2
|
| 5 |
+
|
| 6 |
+
#info Gradio
|
| 7 |
+
#- https://www.gradio.app/docs/gradio/image
|
| 8 |
+
#- https://www.gradio.app/docs/gradio/file
|
| 9 |
+
|
| 10 |
+
# Función que recibe una imagen y la devuelve
|
| 11 |
+
def cargar_imagen(opcion, iou, conf, imagen, color):
|
| 12 |
+
if opcion == "Tanques":
|
| 13 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\prueba11 - tanks\prueba2\weights\best.pt") # 1 📁
|
| 14 |
+
elif opcion == "Tanques o vehiculos":
|
| 15 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\pruebas31-tankstrucks\modelo3\weights\best.pt") # 2 📁
|
| 16 |
+
elif opcion == "Veh. españoles v1":
|
| 17 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\prueba22\prueba102\weights\best.pt") #muchos 📁
|
| 18 |
+
elif opcion == "Veh. españoles v2 (sin VERT)":
|
| 19 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\pruebas41\modelov2(6B)+VEC\weights\best.pt") #muchos 📁 --> igual que arriba
|
| 20 |
+
elif opcion == "Veh. militares españoles agrupados":
|
| 21 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\pruebas51-9A\modelo9A\weights\best.pt") #1 📁 -> creo que no hay ninguno nuevo en 18.3
|
| 22 |
+
else: #como si fueran "Vehiculos militares españoles"
|
| 23 |
+
model = YOLO(rf"\\HELIOS\myc\LabIA\Proyecto RINT 1\MyDatasets\Z. modelos\YOLO Open Imagen\prueba22\prueba102\weights\best.pt")
|
| 24 |
+
|
| 25 |
+
if color == "Blanco y Negro":
|
| 26 |
+
from PIL import ImageOps
|
| 27 |
+
imagen = ImageOps.grayscale(imagen)
|
| 28 |
+
|
| 29 |
+
results = model(imagen, iou=iou, conf=conf, visualize=False, augment=True, verbose = False)
|
| 30 |
+
|
| 31 |
+
text = ""
|
| 32 |
+
for result in results[0].summary():
|
| 33 |
+
r = result["name"] if not "VAMTAC" in result["name"] or opcion != "Veh. militares españoles agrupados" else "VAMTAC+VERT"
|
| 34 |
+
text = text + r + " - " + str(result["confidence"]) + "\n"
|
| 35 |
+
im_rgb = cv2.cvtColor(results[0].plot(), cv2.COLOR_BGR2RGB)
|
| 36 |
+
|
| 37 |
+
return im_rgb, text
|
| 38 |
+
#results[0].verbose(), results[0].summary()
|
| 39 |
+
|
| 40 |
+
# Interfaz Gradio
|
| 41 |
+
iface = gr.Interface(
|
| 42 |
+
fn=cargar_imagen, # La función que ejecuta
|
| 43 |
+
inputs=[gr.Image(type="pil"),
|
| 44 |
+
gr.Slider(0, 1, value=0.7, label="iou"), gr.Slider(0, 1, value=0.3, label="confianza", scale = 0.1, min_width=20),
|
| 45 |
+
gr.Radio(choices=["Tanques", "Tanques o vehiculos", "Veh. militares españoles v1",
|
| 46 |
+
"Veh. militares españoles v2 (falta VERT)", "Veh. militares españoles agrupados"], label="Modelo de predicción"),
|
| 47 |
+
gr.Radio(choices=["Color", "Blanco y Negro"], label="Color"),
|
| 48 |
+
], # Entrada de imagen: gr.File(label="Elige el modelo")
|
| 49 |
+
outputs=[gr.Image(type="pil", label="Predicción"), gr.Textbox(label="Confianza")], # Salida de imagen
|
| 50 |
+
title="Predicción Vehículos Militares", # Título de la app
|
| 51 |
+
# Descripción:
|
| 52 |
+
description='''Sube una imagen y te devolverá los vehículos en la imagen.
|
| 53 |
+
|
| 54 |
+
**Veh. militares españoles agrupados** incluye VERT pero no se muestra en la imagen.
|
| 55 |
+
|
| 56 |
+
*iou* es una medida para evitar el solapamiento de detecciones y *confianza* es el mínimo necesario para mostrarse.
|
| 57 |
+
'''
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Ejecutar la aplicación
|
| 61 |
+
iface.launch(share=True)
|