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

Refactor image preprocessing iterators to subclass Sequence. #7853

Merged
merged 2 commits into from
Sep 8, 2017

Conversation

fchollet
Copy link
Member

@fchollet fchollet commented Sep 8, 2017

Copy link
Contributor

@Dref360 Dref360 left a comment

Choose a reason for hiding this comment

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

Quick review, will wait for Travis to finish to look at coverage.

batch_x = np.zeros(tuple([current_batch_size] + list(self.x.shape)[1:]), dtype=K.floatx())
def _get_batches_of_transformed_samples(self, index_array):
batch_x = np.zeros(tuple([len(index_array)] + list(self.x.shape)[1:]),
dtype=K.floatx())
for i, j in enumerate(index_array):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not need the enumerate here. i is not used.

for i, j in enumerate(index_array):
x = self.x[j]
x = self.image_data_generator.random_transform(x.astype(K.floatx()))
x = self.image_data_generator.standardize(x)
batch_x[i] = x
if self.save_to_dir:
for i in range(current_batch_size):
for i, j in enumerate(index_array):
Copy link
Contributor

Choose a reason for hiding this comment

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

enumerate is not needed here. i is not used

Copy link
Member Author

Choose a reason for hiding this comment

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

i is used below to retrieve sample of index i in the batch, batch_x[i]

j is the index of the same sample in the original array, which we use in the filename

@@ -1037,10 +1057,10 @@ def next(self):
batch_x[i] = x
# optionally save augmented images to disk for debugging purposes
if self.save_to_dir:
for i in range(current_batch_size):
for i, j in enumerate(index_array):
Copy link
Contributor

Choose a reason for hiding this comment

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

same

break

# Test `flow` behavior as Sequence
seq = generator.flow(images, np.arange(images.shape[0]),
shuffle=True, save_to_dir=str(tmpdir),
Copy link
Contributor

@Dref360 Dref360 Sep 8, 2017

Choose a reason for hiding this comment

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

Need a test to validate that shuffle works and on_epoch_end works

Copy link
Member Author

Choose a reason for hiding this comment

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

Added tests for shuffling and reshuffling upon on_epoch_end

@fchollet fchollet merged commit ebd0f08 into master Sep 8, 2017
@fchollet fchollet deleted the sequence-iterators branch December 25, 2017 09:12
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