-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Conversation
There was a problem hiding this 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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
CC @Dref360