WARAJA commited on
Commit
2c8e36c
·
verified ·
1 Parent(s): 44676db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -221,17 +221,22 @@ def segment_lines_eynollah(img_input):
221
  infer = model.signatures.get("serving_default") or model
222
  raw_out = infer(input_1=inp)
223
 
224
- # -- CRITICAL FIX: Safe Dict extraction --
225
  if isinstance(raw_out, dict):
226
  key = list(raw_out.keys())[0]
227
  prob = raw_out[key].numpy()[0]
228
  else:
229
  prob = raw_out.numpy()[0]
230
 
 
231
  if prob.ndim == 3:
232
- prob = prob[..., 0] if prob.shape[-1] == 1 else prob.max(axis=-1)
 
 
 
233
 
234
  mask = (prob > 0.5).astype(np.uint8) * 255
 
235
  mask_full = cv2.resize(mask, (orig_w, orig_h), interpolation=cv2.INTER_NEAREST)
236
 
237
  num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(mask_full, connectivity=8)
 
221
  infer = model.signatures.get("serving_default") or model
222
  raw_out = infer(input_1=inp)
223
 
224
+ # -- CRITICAL FIX: Safe Dict extraction --
225
  if isinstance(raw_out, dict):
226
  key = list(raw_out.keys())[0]
227
  prob = raw_out[key].numpy()[0]
228
  else:
229
  prob = raw_out.numpy()[0]
230
 
231
+ # Grab the 'Text Line' channel explicitly (Channel 1)
232
  if prob.ndim == 3:
233
+ if prob.shape[-1] >= 2:
234
+ prob = prob[..., 1]
235
+ else:
236
+ prob = prob[..., 0]
237
 
238
  mask = (prob > 0.5).astype(np.uint8) * 255
239
+
240
  mask_full = cv2.resize(mask, (orig_w, orig_h), interpolation=cv2.INTER_NEAREST)
241
 
242
  num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(mask_full, connectivity=8)