frncscp commited on
Commit
c669577
1 Parent(s): e85880e

Update pages/Entorno de Ejecución.py

Browse files
Files changed (1) hide show
  1. pages/Entorno de Ejecución.py +8 -23
pages/Entorno de Ejecución.py CHANGED
@@ -60,16 +60,7 @@ with cnn:
60
 
61
  selected_models = []
62
 
63
- @tf.function
64
- def tf_predict(model_list, weights, img): #faster, but for few formats
65
- y_gorrito = 0
66
- raw_img = tf.image.decode_image(img, channels=3)
67
- img = tf.image.resize(raw_img,(IMAGE_WIDTH, IMAGE_HEIGHT))
68
- for model, weight in zip(model_list, weights):
69
- y_gorrito += tf.cast(model(tf.expand_dims(img/255., 0)), dtype=tf.float32)*weight
70
- return [y_gorrito / sum(weights), raw_img.numpy()]
71
-
72
- def basic_predict(model_list, weights, img): #for non-supported formats
73
  y_gorrito = 0
74
  raw_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
75
  img = cv2.resize(img, (IMAGE_WIDTH, IMAGE_HEIGHT))
@@ -93,7 +84,7 @@ with cnn:
93
 
94
  if st.button('¿Hay un patacón en la imagen?'):
95
  if len(model_choice) > 0 and ultra_flag:
96
- st.write('Debe elegir un solo método: Ultra-Patacotrón o selección múltiple.')
97
 
98
  elif uploaded_file is not None:
99
  img = preprocess(uploaded_file)
@@ -103,27 +94,21 @@ with cnn:
103
  ultraptctrn = [load_model(model_dict[model]) for model in ultraversions]
104
  executed = True
105
  final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(ultraptctrn))]
106
- try:
107
- y_gorrito, raw_img = tf_predict(ultraptctrn, final_weights, img)
108
- except:
109
- y_gorrito, raw_img = basic_predict(ultraptctrn, final_weights, img)
110
 
111
  else:
112
  with st.spinner('Cargando predicción...'):
113
  selected_models = [load_model(model_dict[model]) for model in model_choice if model not in selected_models]
114
- final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(selected_models))]
115
- try:
116
- y_gorrito, raw_img = tf_predict(selected_models, final_weights, img)
117
- except:
118
- y_gorrito, raw_img = basic_predict(selected_models, final_weights, img)
119
-
120
  if round(float(y_gorrito*100)) >= threshold:
121
  st.success("¡Patacón Detectado!")
122
 
123
  else:
124
  st.error("No se considera que haya un patacón en la imagen")
125
-
126
- st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
127
  st.caption('Si los resultados no fueron los esperados, por favor, [haz click aquí](https://docs.google.com/forms/d/e/1FAIpQLScH0ZxAV8aSqs7TPYi86u0nkxvQG3iuHCStWNB-BoQnSW2V0g/viewform?usp=sf_link)')
128
 
129
  st.image(raw_img)
 
60
 
61
  selected_models = []
62
 
63
+ def predict(model_list, weights, img): #for non-supported formats
 
 
 
 
 
 
 
 
 
64
  y_gorrito = 0
65
  raw_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
66
  img = cv2.resize(img, (IMAGE_WIDTH, IMAGE_HEIGHT))
 
84
 
85
  if st.button('¿Hay un patacón en la imagen?'):
86
  if len(model_choice) > 0 and ultra_flag:
87
+ st.write('Debe elegir un solo método: Ultra-Patacotrón o Selección Múltiple.')
88
 
89
  elif uploaded_file is not None:
90
  img = preprocess(uploaded_file)
 
94
  ultraptctrn = [load_model(model_dict[model]) for model in ultraversions]
95
  executed = True
96
  final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(ultraptctrn))]
97
+ y_gorrito, raw_img = predict(ultraptctrn, final_weights, img)
 
 
 
98
 
99
  else:
100
  with st.spinner('Cargando predicción...'):
101
  selected_models = [load_model(model_dict[model]) for model in model_choice if model not in selected_models]
102
+ final_weights = weight_list if len(weight_list) >= 1 else [1 for i in range(len(selected_models))]
103
+ y_gorrito, raw_img = predict(selected_models, final_weights, img)
104
+
 
 
 
105
  if round(float(y_gorrito*100)) >= threshold:
106
  st.success("¡Patacón Detectado!")
107
 
108
  else:
109
  st.error("No se considera que haya un patacón en la imagen")
110
+ if not ultra_flag:
111
+ st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
112
  st.caption('Si los resultados no fueron los esperados, por favor, [haz click aquí](https://docs.google.com/forms/d/e/1FAIpQLScH0ZxAV8aSqs7TPYi86u0nkxvQG3iuHCStWNB-BoQnSW2V0g/viewform?usp=sf_link)')
113
 
114
  st.image(raw_img)