muk42 commited on
Commit
00fbc1e
·
1 Parent(s): a8e42c9

handle tiles with no labels

Browse files
Files changed (1) hide show
  1. inference_tab/inference_logic.py +16 -0
inference_tab/inference_logic.py CHANGED
@@ -80,6 +80,14 @@ def run_inference(tile_dict, gcp_path,user_crs, city_name, score_th, hist_th, hi
80
  else:
81
  log += msg + "\n"
82
  yield log, None
 
 
 
 
 
 
 
 
83
  for msg in extractSegments(image_path):
84
  log += msg + "\n"
85
  yield log, None
@@ -238,6 +246,11 @@ def run_tile_inference():
238
 
239
  tile_array = np.array(Image.open(tile_path))
240
 
 
 
 
 
 
241
  results = model(tile_array, bboxes=local_boxes,
242
  points=point_coords, labels=point_labels)
243
 
@@ -265,6 +278,9 @@ def getSegments(image_path,iou=0.5,c_th=0.75,edge_margin=10):
265
  yield "Run inference on tiles..."
266
  for msg in run_tile_inference():
267
  yield msg
 
 
 
268
  yield "Marge predicted masks into image..."
269
  merge_tile_masks(H,W)
270
 
 
80
  else:
81
  log += msg + "\n"
82
  yield log, None
83
+ if "No labels detected" in msg:
84
+ stop_pipeline = True
85
+ break
86
+
87
+ if stop_pipeline:
88
+ yield log + "Pipeline stopped: no text segments found.\n", None
89
+ return
90
+
91
  for msg in extractSegments(image_path):
92
  log += msg + "\n"
93
  yield log, None
 
246
 
247
  tile_array = np.array(Image.open(tile_path))
248
 
249
+ # If there are no boxes and no labels, stop execution
250
+ if not local_boxes and not point_coords and not point_labels:
251
+ yield f"Tile {tile['idx']} has no boxes or points/labels. Stopping inference."
252
+ return
253
+
254
  results = model(tile_array, bboxes=local_boxes,
255
  points=point_coords, labels=point_labels)
256
 
 
278
  yield "Run inference on tiles..."
279
  for msg in run_tile_inference():
280
  yield msg
281
+ if "Stopping inference" in msg:
282
+ yield "No labels detected – halting getSegments."
283
+ return
284
  yield "Marge predicted masks into image..."
285
  merge_tile_masks(H,W)
286