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 a directory iterator option to allow to work easily with autoencoders (issue #4260) #6510

Merged

Conversation

rodgzilla
Copy link
Contributor

This patch adds a new class_mode to keras.preprocessing.image.ImageDataGenerator.flow_from_directory method.

This new class_mode is 'identical' and it allows to generate minibatches where the target values are identical to input values. It makes working with autoencoders trivial. This issue has been described in #4260. The patch also contains tests that ensure that the input images are not the same numpy array as target images.

@@ -972,7 +975,9 @@ def next(self):
format=self.save_format)
img.save(os.path.join(self.save_to_dir, fname))
# build batch of labels
if self.class_mode == 'sparse':
if self.class_mode == 'identical':
batch_y = batch_x.copy()
Copy link
Member

Choose a reason for hiding this comment

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

Is the copy absolutely necessary? Wondering.

@@ -838,6 +838,7 @@ class DirectoryIterator(Iterator):
`"binary"`: binary targets (if there are only two classes),
`"categorical"`: categorical targets,
`"sparse"`: integer targets,
`"identical"`: image targets identical to input images,
Copy link
Member

Choose a reason for hiding this comment

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

What would be some other keyword options? identity, input, autoregression?

Additionally, the explanation can be made clearer.

@rodgzilla
Copy link
Contributor Author

I like input as keyword, I will make this change.

About the copy, I think that not doing it can lead to pretty subtle bug to find in the code. I can imagine a usecase where someone uses flow_from_directory to read images from the disk, makes operations on the image and try to compare the original one and modified one. If the copy is not made, the changes made to the image will also affect the original.

@fchollet
Copy link
Member

fchollet commented May 5, 2017

LGTM

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.

None yet

2 participants