Skip to content

Commit aa686b5

Browse files
committed
Fix segmentation mask from inference
1 parent 9e4d33b commit aa686b5

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

abraia/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'model': 'multiple/tomato/yolov8n_v6.onnx',
1919
'src': '10179855-hd_1280_720_30fps.mp4',
2020
'labels': ['tomato'],
21-
'counter': [(1440, 0), (1440, 1080)],
21+
'counter': [(960, 0), (960, 720)],
2222
'dest': 'tomato_onnx.mp4'
2323
},
2424
'apple': {

abraia/inference/detect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def prepare_input(img, shape):
4747

4848
def get_mask(row, box, size):
4949
"""Extracts the segmentation mask for an object (box) in a row."""
50-
shape = round(math.sqrt(row.shape[0]))
51-
mask = (sigmoid(row.reshape(shape, shape)) > 0.5).astype(np.uint8)
5250
x, y, w, h = box
51+
shape = round(math.sqrt(row.shape[0]))
52+
mask = sigmoid(row.reshape(shape, shape))
5353
mask_x1, mask_y1 = round(x / size[0] * shape), round(y / size[1] * shape)
5454
mask_x2, mask_y2 = round((x + w) / size[0] * shape), round((y + h) / size[1] * shape)
5555
mask = mask[mask_y1:mask_y2, mask_x1:mask_x2]
5656
mask = cv2.resize(mask, (round(w), round(h)), cv2.INTER_NEAREST)
57-
return mask
57+
return (mask > 0.5).astype(np.uint8)
5858

5959

6060
def process_output(outputs, size, shape, classes, conf_threshold=0.25, iou_threshold=0.7, approx=0.001, labels=None):

0 commit comments

Comments
 (0)