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

Fix empty batch #106

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions dreem/datasets/base_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def create_chunks(self) -> None:

self.label_idx = [self.label_idx[i] for i in sample_idx]

# check for batch with only a single element that correpsonds to the last frame of the video
remove_idx = None
for i, frame_chunk in enumerate(self.chunked_frame_idx):
if len(frame_chunk) == 1 and frame_chunk[0] % self.clip_length == 0:
print(
"Warning: Single frame batch; removing to avoid empty batch possibility with failed frame loading"
)
remove_idx = i
break
if remove_idx is not None:
self.chunked_frame_idx.pop(remove_idx)
self.label_idx.pop(remove_idx)

else:
self.chunked_frame_idx = self.frame_idx
self.label_idx = [i for i in range(len(self.labels))]
Expand All @@ -131,6 +144,7 @@ def no_batching_fn(self, batch: list[Frame]) -> list[Frame]:
Returns:
The batch
"""

return batch

def __getitem__(self, idx: int) -> list[Frame]:
Expand Down
3 changes: 2 additions & 1 deletion dreem/inference/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
valid = dist.squeeze() < max_center_dist # n_k x n_nonk
# handle case where id_inds and valid is a single value
# handle this better
if valid.ndim == 0: valid = valid.unsqueeze(0)
if valid.ndim == 0:
valid = valid.unsqueeze(0)

Check warning on line 164 in dreem/inference/post_processing.py

View check run for this annotation

Codecov / codecov/patch

dreem/inference/post_processing.py#L164

Added line #L164 was not covered by tests
if valid.ndim == 1:
if id_inds.shape[0] == 1:
valid_mult = valid.float().unsqueeze(-1)
Expand Down
Loading