Skip to content

Commit c649239

Browse files
committed
fix: skip Florence-2 detections with inverted bounding boxes
Florence-2 occasionally emits garbled location tokens that decode to negative width/height. Filter these at parse time and guard the annotator against any that slip through.
1 parent 9c24ff1 commit c649239

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

uitag/annotate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def render_som(
5252

5353
x1, y1 = det.x, det.y
5454
x2, y2 = det.x + det.width, det.y + det.height
55+
if x1 > x2 or y1 > y2:
56+
continue
5557
draw.rectangle([x1, y1, x2, y2], outline=color, width=2)
5658

5759
# Position marker fully outside the bounding box (above-left of corner)

uitag/florence.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,18 @@ def parse_location_tokens(
7979
x2 = int(int(match.group(4)) * image_width / 999)
8080
y2 = int(int(match.group(5)) * image_height / 999)
8181

82+
w = x2 - x1
83+
h = y2 - y1
84+
if w <= 0 or h <= 0:
85+
continue
86+
8287
results.append(
8388
{
8489
"label": label,
8590
"x": x1,
8691
"y": y1,
87-
"width": x2 - x1,
88-
"height": y2 - y1,
92+
"width": w,
93+
"height": h,
8994
}
9095
)
9196

0 commit comments

Comments
 (0)