Skip to content

Handle index in SphericalSWEDataset::__getitem__ correctly. #328

@pascal-mueller

Description

@pascal-mueller

The SphericalSWEDataset class currently implements the __getitem__ as follows:

   def __getitem__(self, index):

        with torch.inference_mode():
            with torch.no_grad():
                inp, tar = self._get_sample()

                if self.normalize:
                    inp = (inp - self.inp_mean) / torch.sqrt(self.inp_var)
                    tar = (tar - self.inp_mean) / torch.sqrt(self.inp_var)

        return {'x': inp.clone(), 'y': tar.clone()}

which ignores the index completely. This allows to access the dataset with any arbritary key:

dataset = test_loader.dataset
dataset['foo'] # returns a sample
dataset['anotherkey'] # returns another sample

Expected behaviour is: Just not be able to use keys alltogether or receive a KeyError or something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions