SondosM commited on
Commit
55cd337
ยท
verified ยท
1 Parent(s): 26f8a14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -205,18 +205,18 @@ def _align_features(model, features: np.ndarray) -> np.ndarray:
205
  vec[:limit] = features[:limit]
206
  return vec.reshape(1, -1)
207
 
208
-
209
  def run_two_stage(features: np.ndarray, crop_rgb: np.ndarray) -> dict:
210
- # Stage 1: router_model.keras ูŠุญุฏุฏ ุญุฑู (0) ุฃูˆ ุฑู‚ู… (1)
211
- img_resized = cv2.resize(crop_rgb, (IMG_SIZE, IMG_SIZE))
212
- img_array = np.expand_dims(img_resized, axis=0).astype("float32") / 255.0
 
213
 
214
- prob = float(router_model_keras.predict(img_array, verbose=0)[0][0])
215
- cls_idx = 1 if prob >= 0.5 else 0
216
  category = CLASSES[cls_idx]
217
  cat_conf = prob if cls_idx == 1 else 1.0 - prob
218
 
219
- # Stage 2: ุงุฎุชุงุฑ ุงู„ู…ูˆุฏูŠู„ ุงู„ุตุญ ุจู†ุงุกู‹ ุนู„ู‰ ุงู„ู†ุชูŠุฌุฉ
220
  model = mlp_letters if category == "letter" else mlp_numbers
221
  feat_df = _align_features(model, features)
222
  label = str(model.predict(feat_df)[0])
@@ -229,7 +229,6 @@ def run_two_stage(features: np.ndarray, crop_rgb: np.ndarray) -> dict:
229
  "category_confidence": round(cat_conf, 4),
230
  }
231
 
232
-
233
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
234
  # Routes
235
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 
205
  vec[:limit] = features[:limit]
206
  return vec.reshape(1, -1)
207
 
 
208
  def run_two_stage(features: np.ndarray, crop_rgb: np.ndarray) -> dict:
209
+ img_gray = cv2.cvtColor(crop_rgb, cv2.COLOR_RGB2GRAY)
210
+ img_resized = cv2.resize(img_gray, (IMG_SIZE, IMG_SIZE))
211
+ img_array = np.expand_dims(img_resized, axis=(0, -1)).astype("float32") / 255.0
212
+ # shape: (1, 64, 64, 1) โœ…
213
 
214
+ prob = float(router_model_keras.predict(img_array, verbose=0)[0][0])
215
+ cls_idx = 1 if prob >= 0.5 else 0
216
  category = CLASSES[cls_idx]
217
  cat_conf = prob if cls_idx == 1 else 1.0 - prob
218
 
219
+ # Stage 2: ุงุฎุชุงุฑ ุงู„ู…ูˆุฏูŠู„ ุงู„ุตุญ
220
  model = mlp_letters if category == "letter" else mlp_numbers
221
  feat_df = _align_features(model, features)
222
  label = str(model.predict(feat_df)[0])
 
229
  "category_confidence": round(cat_conf, 4),
230
  }
231
 
 
232
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
233
  # Routes
234
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€