Enhance WILDSSubset to support flexible data returns #156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This update modifies the WILDSSubset class to support flexible return types from its
__getitem__
method, accommodating both standard and custom dataset requirements. The enhancement allows for varied data returns, from basicx
andy
pairs to more complex structures including additional information like background labels. Importantly, this change is backward compatible, ensuring existing datasets continue to function as before.Changes
__getitem__
to dynamically handle varying numbers of returned items, enabling support for datasets that return additional data elements or those that simplify to justx
andy
.x
,y
,metadata
format datasets, while also facilitating custom datasets with expanded or reduced data structures.Motivation
The update is motivated by the need for greater flexibility in dataset handling within the WILDS library. A personal use case involved inheriting from WaterbirdsDataset and making it return
x
,y
,s
, andmetadata
. In another scenario, a user might prefer a dataset to return only the features (x
) and labels (y
), omitting the metadata for a leaner data structure. This change facilitates such customizations by allowing easy adjustments to the return types from dataset classes, without needing to alter the classes directly.Conclusion
By introducing this backward-compatible enhancement, the WILDS library becomes more adaptable and user-friendly, encouraging contributions and customizations that meet diverse research and application needs.