From ed56b36f48efc3a1ddf05ef9662a9b714cebf1f9 Mon Sep 17 00:00:00 2001 From: gitttt-1234 Date: Tue, 17 Dec 2024 10:47:48 -0800 Subject: [PATCH] Filter oob while computing crop size --- sleap/nn/data/instance_cropping.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sleap/nn/data/instance_cropping.py b/sleap/nn/data/instance_cropping.py index 1cfd5eee7..09347881e 100644 --- a/sleap/nn/data/instance_cropping.py +++ b/sleap/nn/data/instance_cropping.py @@ -41,9 +41,15 @@ def find_instance_crop_size( # Calculate crop size min_crop_size_no_pad = min_crop_size - padding + height, width, _ = labels[0].image.shape max_length = 0.0 for inst in labels.user_instances: pts = inst.points_array + + pts[pts < 0] = np.NaN + pts[:, 0][pts[:, 0] > height - 1] = np.NaN + pts[:, 1][pts[:, 1] > width - 1] = np.NaN + pts *= input_scaling max_length = np.maximum(max_length, np.nanmax(pts[:, 0]) - np.nanmin(pts[:, 0])) max_length = np.maximum(max_length, np.nanmax(pts[:, 1]) - np.nanmin(pts[:, 1]))