Spaces:
Running
Running
Update pages/Entorno de Ejecución.py
Browse files- pages/Entorno de Ejecución.py +46 -30
pages/Entorno de Ejecución.py
CHANGED
@@ -70,23 +70,23 @@ with cnn:
|
|
70 |
model_name = 'Patacotrón ' + model_dir.split(common_root)[-1].split(common_end)[0]
|
71 |
model_dict[model_name] = model_dir
|
72 |
#ultraversions = ['Patacotrón 1.5', 'Patacotrón 1.7', 'Patacotrón 1.8', 'Patacotrón 1.12', 'Patacotrón 1.12.2', 'Patacotrón 1.12.3']
|
73 |
-
ultraversions = ['Patacotrón 1.5', 'Patacotrón 1.6', 'Patacotrón 1.12.2', 'Patacotrón 1.8', 'Patacotrón 1.12']#, 'Patacotrón 1.13.20', 'Patacotrón 1.13.38']
|
74 |
#['Patacotrón 1.5', 'Patacotrón 1.6', 'Patacotrón 1.7', 'Patacotrón 1.12'] #
|
75 |
-
ultra_button = st.checkbox('Ultra-Patacotrón (en construcción, no es la mejor versión)')
|
76 |
-
ultra_flag = False
|
77 |
weight_list = []
|
78 |
|
79 |
-
if ultra_button:
|
80 |
-
|
81 |
#weight_list = [3, 1, 4.5, 1, .8, 1] [.5, 1.75, 4, .5, 2]
|
82 |
-
|
83 |
#[1, 2, 3, 2.5]
|
84 |
-
|
85 |
|
86 |
# Create a dropdown menu to select the model
|
87 |
model_choice = st.multiselect("Seleccione uno o varios modelos de clasificación", model_dict.keys())
|
88 |
|
89 |
-
threshold = st.slider('¿Cuál va a ser el límite donde se considere patacón? (el valor recomendado
|
90 |
|
91 |
selected_models = []
|
92 |
|
@@ -100,24 +100,25 @@ with cnn:
|
|
100 |
uploaded_file = st.file_uploader(key = 'convnet_upload', label = 'Sube la imagen a clasificar',type= ['jpg','png', 'jpeg', 'jfif', 'webp', 'heic'])
|
101 |
|
102 |
if st.button(key = 'convnet_button', label ='¿Hay un patacón en la imagen?'):
|
103 |
-
if
|
104 |
-
|
|
|
105 |
|
106 |
elif uploaded_file is not None:
|
107 |
img = preprocess(uploaded_file)
|
108 |
-
if ultra_flag:
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
-
else:
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
|
122 |
if round(float(y_gorrito*100)) >= threshold:
|
123 |
st.success("¡Patacón Detectado!")
|
@@ -155,20 +156,35 @@ with vit:
|
|
155 |
with col_b:
|
156 |
|
157 |
if st.button(key = 'ViT_button', label ='¿Hay un patacón en la imagen?'):
|
158 |
-
if len(model_choice)
|
159 |
-
print('Recuerda seleccionar un
|
160 |
elif uploaded_file is not None:
|
161 |
with st.spinner('Cargando predicción...'):
|
162 |
-
|
|
|
|
|
|
|
163 |
img = preprocess(uploaded_file, module = 'pil')
|
164 |
-
|
165 |
-
classifier = classifier(img)
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
#y_gorrito = classifier[0]["score"]
|
|
|
|
|
|
|
172 |
if round(float(y_gorrito*100)) >= threshold:
|
173 |
st.success("¡Patacón Detectado!")
|
174 |
else:
|
|
|
70 |
model_name = 'Patacotrón ' + model_dir.split(common_root)[-1].split(common_end)[0]
|
71 |
model_dict[model_name] = model_dir
|
72 |
#ultraversions = ['Patacotrón 1.5', 'Patacotrón 1.7', 'Patacotrón 1.8', 'Patacotrón 1.12', 'Patacotrón 1.12.2', 'Patacotrón 1.12.3']
|
73 |
+
#ultraversions = ['Patacotrón 1.5', 'Patacotrón 1.6', 'Patacotrón 1.12.2', 'Patacotrón 1.8', 'Patacotrón 1.12']#, 'Patacotrón 1.13.20', 'Patacotrón 1.13.38']
|
74 |
#['Patacotrón 1.5', 'Patacotrón 1.6', 'Patacotrón 1.7', 'Patacotrón 1.12'] #
|
75 |
+
#ultra_button = st.checkbox('Ultra-Patacotrón (en construcción, no es la mejor versión)')
|
76 |
+
#ultra_flag = False
|
77 |
weight_list = []
|
78 |
|
79 |
+
#if ultra_button:
|
80 |
+
# ultra_flag = True
|
81 |
#weight_list = [3, 1, 4.5, 1, .8, 1] [.5, 1.75, 4, .5, 2]
|
82 |
+
# weight_list = [2.5, 1.8, 1.5, 3.14, 2.2] #.2, 2]
|
83 |
#[1, 2, 3, 2.5]
|
84 |
+
# st.caption('Para Ultra-Patacotrón, este porcentaje no representa una a priori una probabilidad, sino la combinación ponderada de modelos con sesgos positivos y negativos, lo importante es que identifique correctamente el objeto.')
|
85 |
|
86 |
# Create a dropdown menu to select the model
|
87 |
model_choice = st.multiselect("Seleccione uno o varios modelos de clasificación", model_dict.keys())
|
88 |
|
89 |
+
threshold = st.slider('¿Cuál va a ser el límite donde se considere patacón? (el valor recomendado es de 75%-80%)', 0, 100, 50, key = 'threshold_convnet')
|
90 |
|
91 |
selected_models = []
|
92 |
|
|
|
100 |
uploaded_file = st.file_uploader(key = 'convnet_upload', label = 'Sube la imagen a clasificar',type= ['jpg','png', 'jpeg', 'jfif', 'webp', 'heic'])
|
101 |
|
102 |
if st.button(key = 'convnet_button', label ='¿Hay un patacón en la imagen?'):
|
103 |
+
if len(model_choice) < 1:
|
104 |
+
#if (len(model_choice) > 0 and ultra_flag) or (len(model_choice) == 0 and ultra_flag is None):
|
105 |
+
st.write('Debe elegir como mínimo un modelo.')
|
106 |
|
107 |
elif uploaded_file is not None:
|
108 |
img = preprocess(uploaded_file)
|
109 |
+
#if ultra_flag:
|
110 |
+
# with st.spinner('Cargando ultra-predicción...'):
|
111 |
+
# if not executed:
|
112 |
+
# ultraptctrn = [load_model(model_dict[model]) for model in ultraversions]
|
113 |
+
# executed = True
|
114 |
+
# final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(ultraptctrn))]
|
115 |
+
# y_gorrito, raw_img = predict(ultraptctrn, final_weights, img)
|
116 |
|
117 |
+
#else:
|
118 |
+
with st.spinner('Cargando predicción...'):
|
119 |
+
selected_models = [load_model(model_dict[model]) for model in model_choice if model not in selected_models]
|
120 |
+
final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(selected_models))]
|
121 |
+
y_gorrito, raw_img = predict(selected_models, final_weights, img)
|
122 |
|
123 |
if round(float(y_gorrito*100)) >= threshold:
|
124 |
st.success("¡Patacón Detectado!")
|
|
|
156 |
with col_b:
|
157 |
|
158 |
if st.button(key = 'ViT_button', label ='¿Hay un patacón en la imagen?'):
|
159 |
+
if len(model_choice) < 1:
|
160 |
+
print('Recuerda seleccionar al menos un modelo de clasificación')
|
161 |
elif uploaded_file is not None:
|
162 |
with st.spinner('Cargando predicción...'):
|
163 |
+
|
164 |
+
classifiers = [pipeline("image-classification", model= model_dict[model_choice[i]]) for i in range(len(model_choice))]
|
165 |
+
|
166 |
+
#classifier = pipeline("image-classification", model= model_dict[model_choice[0]])
|
167 |
img = preprocess(uploaded_file, module = 'pil')
|
|
|
|
|
168 |
|
169 |
+
|
170 |
+
def vit_ensemble(classifier_list, img):
|
171 |
+
for classifier in classifier_list:
|
172 |
+
classifier = classifier(img)
|
173 |
+
for clase in classifier:
|
174 |
+
if clase['label'] == 'Patacon-True':
|
175 |
+
y_gorrito += clase["score"]
|
176 |
+
return y_gorrito / len(classifier_list)
|
177 |
+
|
178 |
+
#classifier = classifier(img)
|
179 |
+
|
180 |
+
#for clase in classifier:
|
181 |
+
# if clase['label'] == 'Patacon-True':
|
182 |
+
# y_gorrito = clase["score"]
|
183 |
|
184 |
#y_gorrito = classifier[0]["score"]
|
185 |
+
|
186 |
+
y_gorrito = vit_ensemble(classifiers, img)
|
187 |
+
|
188 |
if round(float(y_gorrito*100)) >= threshold:
|
189 |
st.success("¡Patacón Detectado!")
|
190 |
else:
|