Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter instances while generating indices #138

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions sleap_nn/data/custom_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ def _fill_cache(self):
lf = self.labels[lf_idx]
video_idx = self._get_video_idx(lf)

# Filter to user instances
if self.data_config.user_instances_only:
if lf.user_instances is not None and len(lf.user_instances) > 0:
lf.instances = lf.user_instances

if lf_idx == self.cache_lf[0]:
img = self.cache_lf[1]
else:
Expand All @@ -362,8 +357,7 @@ def _fill_cache(self):

instances = []
for inst in lf:
if not inst.is_empty:
instances.append(inst.numpy())
instances.append(inst.numpy())
instances = np.stack(instances, axis=0)

# Add singleton time dimension for single frames.
Expand Down Expand Up @@ -443,8 +437,13 @@ def _get_instance_idx_list(self) -> List[Tuple[int]]:
"""Return list of tuples with indices of labelled frames and instances."""
instance_idx_list = []
for lf_idx, lf in enumerate(self.labels):
for inst_idx, _ in enumerate(lf.instances):
instance_idx_list.append((lf_idx, inst_idx))
# Filter to user instances
if self.data_config.user_instances_only:
if lf.user_instances is not None and len(lf.user_instances) > 0:
lf.instances = lf.user_instances
for inst_idx, inst in enumerate(lf.instances):
if not inst.is_empty: # filter all NaN instances.
instance_idx_list.append((lf_idx, inst_idx))
return instance_idx_list

def __len__(self) -> int:
Expand Down