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

Use current class __next__ implementation in __init__, to avoid special handling of first batch in child classes #2363

Merged
merged 4 commits into from
Oct 16, 2020

Conversation

jantonguirao
Copy link
Contributor

Signed-off-by: Joaquin Anton janton@nvidia.com

Why we need this PR?

  • Refactoring to improve custom iterator writing.
    Currently, custom iterators that override next() function need to be aware that the first batch was produced during init, which invokes the child class next, therefore the first iteration produces a "wrapped" batch while the following don't.

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    Use current class next function in DALIGenericIterator
  • Affected modules and functionalities:
    FW iterators
  • Key points relevant for the review:
    N/A
  • Validation and testing:
    N/A
  • Documentation (including examples):
    N/A

JIRA TASK: [DALI-1635]

…d special handling of first batch when writing iterator wrapper classes

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1703801]: BUILD STARTED

@@ -230,7 +230,7 @@ def __init__(self,
with p._check_api_type_scope(types.PipelineAPIType.ITERATOR):
p.schedule_run()
self._first_batch = None
self._first_batch = self.next()
self._first_batch = DALIGenericIterator.next(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self._first_batch = DALIGenericIterator.next(self)
self._first_batch = DALIGenericIterator.__next__(self)

Because:

    def next(self):
        """
        Returns the next batch of data.
        """
        return self.__next__()

Copy link
Contributor

@JanuszL JanuszL left a comment

Choose a reason for hiding this comment

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

I think we should add a test for that after all.

@JanuszL JanuszL self-requested a review October 15, 2020 11:17
@mzient mzient self-requested a review October 15, 2020 12:30
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1703801]: BUILD FAILED

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>

pipe = Pipeline(batch_size = 16, num_threads = 1, device_id = 0)
with pipe:
data = fn.uniform(range=(-1, 1), shape=(20, 30, 3), seed=1234)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
data = fn.uniform(range=(-1, 1), shape=(20, 30, 3), seed=1234)
data = fn.uniform(range=(-1, 1), shape=(2, 2, 2), seed=1234)

I think we can make it as simple as possible

super(IteratorWrapper, self).__init__(*args, **kwargs)

def __next__(self):
assert(self._allow_next)
Copy link
Contributor

@JanuszL JanuszL Oct 16, 2020

Choose a reason for hiding this comment

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

I would add a comment why this works.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1707353]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1707353]: BUILD PASSED

@jantonguirao jantonguirao merged commit 14001d6 into NVIDIA:master Oct 16, 2020
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.

4 participants