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

Enhance WILDSSubset to support flexible data returns #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions wilds/datasets/wilds_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,15 @@ def __init__(self, dataset, indices, transform, do_transform_y=False):
self.do_transform_y = do_transform_y

def __getitem__(self, idx):
x, y, metadata = self.dataset[self.indices[idx]]
dataset_item = self.dataset[self.indices[idx]]

x, y, *_ = dataset_item # Unpacks the first two items; expects dataset items to have at least 2 elements
if self.transform is not None:
if self.do_transform_y:
x, y = self.transform(x, y)
else:
x = self.transform(x)
return x, y, metadata
return x, y, *dataset_item[2:] # Returns additional elements beyond x and y, if any

def __len__(self):
return len(self.indices)
Expand Down