fcernafukuzaki commited on
Commit
6e32b8a
verified
1 Parent(s): 887e75e

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +77 -0
  2. best.pt +3 -0
  3. requirements.txt +18 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import streamlit as st
4
+ import torch
5
+ from PIL import Image
6
+ from ultralytics import YOLO
7
+
8
+
9
+ class YOLODetect():
10
+ def __init__(self, modelo):
11
+ self.modelo = modelo
12
+
13
+ def predecir(self, source, imgsz=1280, conf=0.7, iou=0.50):
14
+ # conf float 0.25 umbral de confianza del objeto para la detecci贸n
15
+ # iou float 0.7 umbral de intersecci贸n sobre uni贸n (IoU) para NMS
16
+ self.results = self.modelo.predict(source=source, save=True, imgsz=imgsz, conf=conf, iou=iou)
17
+ return self.results
18
+
19
+ def render(self):
20
+ result = self.results[0]
21
+ file_name = os.path.join(result.save_dir, result.path)
22
+ render = Image.open(file_name)
23
+ return render
24
+
25
+ path_best_model = 'best.pt'
26
+ modelo_yolo = YOLO(path_best_model)
27
+
28
+ def detect_objects(size, iou, conf, im):
29
+ '''Wrapper fn for gradio'''
30
+ g = (int(size) / max(im.size)) # gain
31
+ im = im.resize((int(x * g) for x in im.size), Image.LANCZOS) # resize with antialiasing
32
+
33
+ model = YOLODetect(modelo_yolo)
34
+ results = model.predecir(source=im, imgsz=int(size), conf=conf, iou=iou)
35
+
36
+ objects_detected = results[0].boxes.cls.tolist() # Clases detectadas.
37
+ objects_conf = results[0].boxes.conf.tolist() # Probabilidad de detecci贸n por clase detectada.
38
+
39
+ objects_nested_list = pd.DataFrame({'Clase': objects_detected, 'Probabilidad': objects_conf})
40
+
41
+ result_img = model.render()
42
+ return result_img, objects_nested_list
43
+
44
+ # Streamlit app layout
45
+ st.title('YOLOv8 Detecci贸n de figuras LEGO')
46
+
47
+ # Input
48
+ col1, col2 = st.columns(2)
49
+ with col1:
50
+ iou_threshold = st.slider("NMS IoU Threshold (0.0 - 1.0)", 0.0, 1.0, 0.8, key="iou")
51
+ conf_threshold = st.slider("Umbral o threshold (0.0 - 1.0)", 0.0, 1.0, 0.9, key="conf")
52
+ with col2:
53
+ size = st.selectbox("Tama帽o de la imagen", options=["640", "1280"], key="size")
54
+ uploaded_image = st.file_uploader("Cargar imagen", type=["jpg", "jpeg", "png"], key="image")
55
+
56
+ # Process uploaded image
57
+ if uploaded_image is not None:
58
+ image = Image.open(uploaded_image)
59
+ result_image, objects_nested_list = detect_objects(size=int(size), iou=iou_threshold, conf=conf_threshold, im=image)
60
+ object_count = len(objects_nested_list)
61
+
62
+ if result_image is not None:
63
+ col1, col2 = st.columns(2)
64
+ with col1:
65
+ st.image(image, caption="Imagen original", use_column_width=True)
66
+ with col2:
67
+ st.image(result_image, caption="Resultado", use_column_width=True)
68
+
69
+ with st.form("my_form", clear_on_submit=True):
70
+ st.title("Formulario para feedback")
71
+ st.write(f'Cantidad detectados: {object_count}')
72
+ st.table(objects_nested_list)
73
+ check_status = st.checkbox("驴El resultado contiene la cantidad correcta de figuras detectadas?", value=False)
74
+ user_text = st.text_input("Ingrese el nombre del usuario que realiz贸 la prueba (m谩ximo 50 caracteres)", max_chars=50)
75
+
76
+ else:
77
+ st.warning("Error procesando la imagen. Volver a probar.")
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:380f9383305dce76f36c8f552ce94e2518f3e7ab1b6aafbe4754935f55a2aeeb
3
+ size 136704041
requirements.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.33.0
2
+ ultralytics
3
+ ultralyticsplus
4
+ gradio
5
+ IPython
6
+ matplotlib>=3.2.2
7
+ numpy>=1.18.5
8
+ opencv-python-headless
9
+ pillow
10
+ psutil
11
+ PyYAML>=5.3.1
12
+ scipy>=1.4.1
13
+ torch>=1.7.0
14
+ torchvision>=0.8.1
15
+ tqdm>=4.41.0
16
+ pandas
17
+ thop # FLOPs computation
18
+ cython==0.29.35