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

Add TileDataset #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

alexanderwerning
Copy link
Contributor

TileDataset should be more efficient than concatenating the input dataset for large repetitions (in my case in the 1000s)

iterable = self.input_dataset.__iter__(with_key=True)
else:
iterable = self.input_dataset
for example in iterable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use yield from?

item = item + len(self)
if item < 0:
raise IndexError(_item)
if item > self.repetitions * len(self.input_dataset):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use len(self)?

@boeddeker
Copy link
Member

Does the following code works?

import lazy_dataset
ds = lazy_dataset.new([1, 2, 3])
ds = ds.shuffle(reshuffle=True)
ds = ds.tile(4).catch()
list(ds)

We have to handle the combination of non-ordered (e.g. reshuffle), tile, copy(freeze) and indexing.
We use copy(freeze) and indexing too often to introduce a breaking change (e.g. prefetch).
It should be the same as non-ordered (e.g. reshuffle), tile and iter.

I see two solutions:

  • Use TileDataset only, when the input is ordered.
  • Convert a TileDataset to the old type (multiple datasets with concat)
    • In this case, we should modify the repr/str that the user recognizes this.

"""
if isinstance(item, str):
return self.input_dataset[item]
elif isinstance(item, numbers.Integral):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, whether this code will have an effect in the performance.

How about changing the code to the follwing?

input_len = len(self.input_dataset)
if not (-self.repetitions <= item // input_len < self.repetitions):
    raise IndexError(_item)
return self.input_dataset[item % input_len]


"""

def __init__(self, input_dataset, repetitions):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename repetitions to reps?
I prefer to have names close to numpy. (We don't want to do the same as pytorch, where you have to learn the new names for arguments, because they differ to numpy)

datasets = [ds.shuffle() for ds in datasets]
return self.__class__.concatenate(*datasets)
else:
return TileDataset(self, reps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize overhead: Could your return self, when reps is one? concatenate does this already.

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

Successfully merging this pull request may close these issues.

2 participants