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

Does flow_from_dataframe() support multilabel outputs? #135

Closed
scott-zockoll opened this Issue Jan 9, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@scott-zockoll
Copy link

scott-zockoll commented Jan 9, 2019

I have previously been able to train a CNN to have multi-class and multi-label output using flow(), but I am having trouble getting it to train where the labels are vectors of binary values. I am not sure what class_mode I should be using? @Vijayabhaskar96 is this supported with flow_from_dataframe()?

@rragundez

This comment has been minimized.

Copy link
Collaborator

rragundez commented Jan 11, 2019

@scott-zockoll working on it today :)

@rragundez rragundez referenced this issue Jan 11, 2019

Merged

Multi label #136

@rragundez

This comment has been minimized.

Copy link
Collaborator

rragundez commented Jan 11, 2019

there you go #136
Hopefully it will get merge soon. A +1 is always appreciated in the PR.

@Vijayabhaskar96

This comment has been minimized.

Copy link
Contributor

Vijayabhaskar96 commented Jan 11, 2019

@scott-zockoll Sorry I was busy didn't notice the issue.
I have yet to see @rragundez 's PR. Anyway, You could change the multiple classes into one-hot vectors and split each column into separate columns such that the dataframe looks like this:

|filenames|class1|class2|class3|
|1.png|0|1|1|
|2.png|0|1|0|
|3.png|1|1|1|
...

You can perform this easily with Sklearn's MultiLabelBinarizer

You can now pass the x_col="filenames" , y_col=["class1","class2","class3"] and class_mode="other"
but this method only allows you to use a single Dense layer with 3 (no. of classes) neurons in the last layer with single loss.
If you want to use multiple loss functions you may want to write a python generator function that loops through the output of flow_from_dataframe and yields the reshaped array, this generator can be used now to fit the model with multiple losses.

@rragundez

This comment has been minimized.

Copy link
Collaborator

rragundez commented Jan 11, 2019

@Vijayabhaskar96 indeed I think that would work. Just something I wanted to point out:

By using the MultiLabelBinarizer or basically expanding the tools you impact the memory footprint of the algorithm without necessity, not only during the expansion process but also the class it self DataFrameIterator will have to keep in memory the full expanded matrix or dataframe of values for each observation and class. In many realistic scenarios this is actually quite a lot since many times you have tens or hundreds of classes and thousand examples easily. In the PR this is optimize by keeping the minimum information necessary.

An option would be to support SparseDataFrame BTW, perhaps too far fetch.

I think what you propose with multiple columns should be the way for multi-output, then we would have a very nice consistent API for DataFrameIterator :).

@scott-zockoll

This comment has been minimized.

Copy link
Author

scott-zockoll commented Jan 12, 2019

@rragundez Great. I will check our your PR.

@Vijayabhaskar96 I see thank you. To make a quick fix I made some changes similar to this fork (but updated for the current keras implementation): tholor/keras@29ceafc

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