-
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
Multi-outputs & class_weight #4735
Comments
And a second situation is that: Both outputs do the classification, but we want to give each output different class_weight params. |
You should pass a dict with string keys corresponding to the names of your
outputs. Like you describe.
…On 15 December 2016 at 15:14, Ke Young ***@***.***> wrote:
And a second situation is that:
output 1 'class_1' for classification
output 2 'class_2' for classification
Both outputs do the classification, but we want to give each output
different class_weight params.
How can we do this? (I am not sure whether this situation makes sense or
not. )
Maybe Like this?:
class_weight = { 'class_1': {0: ratio 1 , 1: ratio 2} , 'class_2': {0:
ratio 3 , 1: ratio 4} }
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4735 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AArWb6wWFGIUv7e82crHb9ggQ4M2oyAnks5rIcnJgaJpZM4LOrKk>
.
|
Thanks for your quick response. |
No, use integers. 0 and 1.
…On 15 December 2016 at 15:31, Ke Young ***@***.***> wrote:
Thanks for your quick response.
If we use the one-hot code.
For the two classes classification, should the class_weight like this? :
class_weight = {10: weight 1, 11: weight 2}
10 and 11 repesent the one hot codes of the two classes
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4735 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AArWb98elmzifptTjsU3SK1SYX-_wIT3ks5rIc23gaJpZM4LOrKk>
.
|
@fchollet what is the right way to set weights given multi-class, one-hot encoded outputs? e.g. y = [0, 1, 1, 1, 0] |
Yup. Same issue |
@olix20 did you find a solution ? |
For a multi output model how can I change class_weights during training ie after each step according to a batch. |
In 2020 / TF 2.3.0 this does not work: |
this discussion should be reopened as of Dec 11, 2020 as this issue is still not resolved. and this discussion is related to discussion 1 and discussion 2. |
Agreed. This is really needed. |
@fchollet Can we get this re-opened? We are dealing an inherently asymmetric target set with the need for multiple outputs. |
Any progress? |
I think class weights can always be implemented via sample weights (see sklearn.utils.class_weight.compute_sample_weight). It seems like Keras does support sample weights for each output, so maybe using |
@adriangb Ostensibly, Keras does support class weights with multiple outputs, but the implementation is broken, as noted by the error message shown in this thread. Its unclear to me if sklearn can be used in a tensorflow/keras training pipeline. I find adding outside frameworks can be troublesome when exporting models to TF Serving. But I may not have enough knowledge here. |
I'm not sure either. I'm just offering it as an alternative, but obviously it would still be nice if it got fixed. |
Did anyone have any luck with this issue here? The nested dictionary approach as suggested by @fchollet for class_weight earlier seems to be supported for TF <= 2.1.0 only. |
Keras is going somewhere :( ... Not even a response from https://github.com/fchollet :( |
Thanks @adriangb from sklearn.utils.class_weight import compute_sample_weight Would be nice if Keras would accept the class_weight directly, but until then... |
|
Assume our model have two outputs :
output 1 'class' for classification
output 2 'location' for regression
Now we have the imbalance dataset(eg. binary classification, class '0': 98 percent, class '1': 2 percent), so we need set the class_weight params in model.fit() function, but for output 2 'location' regression task, we do not need class_weight.
How can we set the class_weight in this situation?
Does "class_weight = {0: ratio 1 , 1: ratio 2} is applied the classification task and ignore the regression task by default?
The text was updated successfully, but these errors were encountered: