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

split_data_target issue #140

Open
jfulem opened this issue Jan 18, 2023 · 4 comments
Open

split_data_target issue #140

jfulem opened this issue Jan 18, 2023 · 4 comments
Labels
new feature Feature request to work on

Comments

@jfulem
Copy link

jfulem commented Jan 18, 2023

Hi, I'm using a Dataset class (extending torch.utils.data.Dataset) which contains this method:

def __getitem__(self, idx) -> tuple[list[torch.Tensor], torch.Tensor]

Unfortunately, the split_data_target in torchensemble.utils.io can't handle that.

    
   if len(element) == 2:
        # Dataloader with one input and one target
        data, target = element[0], element[1]
        return [data.to(device)], target.to(device)  

maybe this modification would be useful:

    if len(element) == 2:
        # Dataloader with one input and one target
        data, target = element[0], element[1]
        if isinstance(data, list) or isinstance(data, tuple):
            return [d.to(device) for d in data], target.to(device)
        return [data.to(device)], target.to(device)# tensor -> list
@xuyxu
Copy link
Member

xuyxu commented Jan 20, 2023

def getitem(self, idx) -> tuple[list[torch.Tensor], torch.Tensor]

Hi @jfulem, is this specification of dataset generally used? Will appreciate your suggestions very much.

@jfulem
Copy link
Author

jfulem commented Jan 20, 2023

Yes, getting this tuple[list[torch.Tensor], torch.Tensor] as the dataset item is very common.

@xuyxu xuyxu added the new feature Feature request to work on label Jan 27, 2023
@xuyxu
Copy link
Member

xuyxu commented Jan 27, 2023

Marked as a new feature, are you willing to work on this @jfulem ?

@jfulem
Copy link
Author

jfulem commented Jan 27, 2023

@xuyxu, sure I can make the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Feature request to work on
Projects
None yet
Development

No branches or pull requests

2 participants