frncscp commited on
Commit
1e394de
1 Parent(s): c4715bf

Update pages/Entorno de Ejecución.py

Browse files
Files changed (1) hide show
  1. pages/Entorno de Ejecución.py +27 -15
pages/Entorno de Ejecución.py CHANGED
@@ -32,24 +32,36 @@ classic_ml_root = "/home/user/app/classicML"
32
  def load_pca():
33
  return joblib.load(os.path.join(classic_ml_root, "pca_model.pkl"))
34
 
35
- def _predict(_model_list, _weights, _img):
36
  y_gorrito = 0
37
  raw_img = cv2.cvtColor(_img, cv2.COLOR_BGR2RGB)
38
  img = cv2.resize(_img, (IMAGE_WIDTH, IMAGE_HEIGHT))
39
- for model, weight in zip(_model_list, _weights):
40
- y_gorrito += tf.cast(model(tf.expand_dims(img/255., 0)), dtype=tf.float32)*weight
41
- return [y_gorrito / sum(_weights), raw_img]
42
 
43
- def _pca_predict(models, _img):
44
- y_gorrito = 0
45
- raw_img = cv2.cvtColor(_img, cv2.COLOR_BGR2RGB)
46
- img = cv2.resize(_img, (IMAGE_WIDTH, IMAGE_HEIGHT))
47
- fl_img =[img.flatten()]
48
- data = pca.transform(fl_img)
49
- for model in models:
50
- prediction = model.predict_proba(data)
51
- y_gorrito += prediction[0][Categories.index("Patacon-True")]
52
- return [y_gorrito / len(models), raw_img]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  #def classic_ml_prediction(clfs, _img):
55
  # y_gorrito = 0
@@ -328,7 +340,7 @@ with classic_ml:
328
 
329
  img = preprocess(uploaded_file)
330
  selected_models = [joblib.load(model_dict[model_name]) for model_name in model_choice]
331
- y_gorrito, raw_img = _pca_predict(selected_models, img)
332
 
333
  if round(float(y_gorrito*100)) >= threshold:
334
  st.success("¡Patacón Detectado!")
 
32
  def load_pca():
33
  return joblib.load(os.path.join(classic_ml_root, "pca_model.pkl"))
34
 
35
+ def _predict(_model_list, _img, sklearn = False):
36
  y_gorrito = 0
37
  raw_img = cv2.cvtColor(_img, cv2.COLOR_BGR2RGB)
38
  img = cv2.resize(_img, (IMAGE_WIDTH, IMAGE_HEIGHT))
 
 
 
39
 
40
+ if sklearn:
41
+ fl_img =[img.flatten()]
42
+ data = pca.transform(fl_img)
43
+ for model in _model_list:
44
+ prediction = model.predict_proba(data)
45
+ y_gorrito += prediction[0][Categories.index("Patacon-True")]
46
+
47
+ else:
48
+ for model in _model_list:
49
+ y_gorrito += tf.cast(model(tf.expand_dims(img/255., 0)), dtype=tf.float32)*weight
50
+
51
+ return [y_gorrito / len(_model_list), raw_img]
52
+
53
+
54
+ #def _pca_predict(models, _img):
55
+ # y_gorrito = 0
56
+ # raw_img = cv2.cvtColor(_img, cv2.COLOR_BGR2RGB)
57
+ # img = cv2.resize(_img, (IMAGE_WIDTH, IMAGE_HEIGHT))
58
+ # fl_img =[img.flatten()]
59
+ # data = pca.transform(fl_img)
60
+ # for model in models:
61
+ # prediction = model.predict_proba(data)
62
+ # y_gorrito += prediction[0][Categories.index("Patacon-True")]
63
+ # return [y_gorrito / len(models), raw_img]
64
+
65
 
66
  #def classic_ml_prediction(clfs, _img):
67
  # y_gorrito = 0
 
340
 
341
  img = preprocess(uploaded_file)
342
  selected_models = [joblib.load(model_dict[model_name]) for model_name in model_choice]
343
+ y_gorrito, raw_img = _predict(selected_models, img, sklearn = True)
344
 
345
  if round(float(y_gorrito*100)) >= threshold:
346
  st.success("¡Patacón Detectado!")