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

Multi label #136

Merged
merged 21 commits into from Jan 20, 2019

Conversation

Projects
None yet
3 participants
@rragundez
Copy link
Collaborator

rragundez commented Jan 11, 2019

Summary

At the moment there is no support for multi-label. This PR adds multi-label support.
Minimal example:

import numpy as np
import scipy.misc
import pandas as pd
import random
from keras_preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt

pixel_val = 1
filenames = []
for i in range(30):
    filename = '/tmp/{}.jpg'.format(i)
    plt.imsave(filename, pixel_val * np.ones((3, 3, 3)))
    filenames.append(filename)

classes = ['dog', 'cat', ['dog', 'cat']] * 10
df = pd.DataFrame({'filename': filenames, 'class': classes}).sample(frac=1).reset_index(drop=True)

generator = ImageDataGenerator(rescale=1/255).flow_from_dataframe(
    df,
    batch_size=3,
    target_size=(3, 3),
    shuffle = False,
    classes=['non-existent', 'dog', 'cat'],
    class_mode='categorical',
)
assert next(generator)[1].shape == (3, 3)

The way to use it integrates seemingly to the current way of using it. The user can still use the categorical class mode but instead send several classes per observation in a form of a list or tuple. It will just work.

There is indeed some additional boiler plate for checking inputs and parameters, there were already some before but now they have moved to the top of the function and to a separate method logic.

Related Issues

#135

PR Overview

  • [ y] This PR requires new unit tests [y/n] (make sure tests are included)
  • [ y] This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • [ y] This PR is backwards compatible [y/n]
  • [ n] This PR changes the current API [y/n] (all API changes need to be approved by fchollet)
@Vijayabhaskar96

This comment has been minimized.

Copy link
Contributor

Vijayabhaskar96 commented Jan 13, 2019

@Dref360 PR Looks good to me. @rragundez Thanks! Tested and works fine.

@rragundez

This comment has been minimized.

Copy link
Collaborator Author

rragundez commented Jan 13, 2019

I'll update the documentation a bit more and then merge it, thanks!

@rragundez rragundez added the image label Jan 13, 2019

Show resolved Hide resolved keras_preprocessing/image/dataframe_iterator.py
Show resolved Hide resolved tests/image_test.py

@rragundez rragundez force-pushed the rragundez:multi-label branch 2 times, most recently from c9c1eaa to 611f605 Jan 20, 2019

@rragundez

This comment has been minimized.

Copy link
Collaborator Author

rragundez commented Jan 20, 2019

I think documentation is much clearer now. Can you give it a look?

I've also addressed the comments.

@rragundez rragundez force-pushed the rragundez:multi-label branch from c2c560b to bd34594 Jan 20, 2019

@Vijayabhaskar96

This comment has been minimized.

Copy link
Contributor

Vijayabhaskar96 commented Jan 20, 2019

Looks good! @rragundez Thanks! @Dref360

@rragundez rragundez force-pushed the rragundez:multi-label branch from fa7e597 to 5c34e5f Jan 20, 2019

@Dref360
Copy link
Member

Dref360 left a comment

Good PR, please see comments and fix conflicts

Show resolved Hide resolved keras_preprocessing/image/dataframe_iterator.py Outdated
@Dref360
Copy link
Member

Dref360 left a comment

LGTM once CI passes Thanks

@rragundez rragundez merged commit 281090d into keras-team:master Jan 20, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@rragundez rragundez deleted the rragundez:multi-label branch Jan 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment