Update app.py
Browse files
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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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)
|