class balancing

914 views
Skip to first unread message

Klaymen

unread,
Feb 2, 2016, 4:06:01 AM2/2/16
to Keras-users

Hello,

I'm trying to add weights to the classes during training right before the final softmax layer, the output shape of the layer is (batch_size, length, nb_class) with one-hot-label of the same size, and I'm using categorical_crossentropy loss here.

I've tried to use class_weight in fit and send class weight as dictionary: {0:w1, 1:w2, ...}, but got the error: Exception: class_weight not supported for 3+ dimensional targets.

Is there any way to do this? Any suggestions will be greatly appreciated!



Sander Stepanov

unread,
Mar 27, 2016, 12:52:27 PM3/27/16
to Keras-users
good question

Isaac Gerg

unread,
Mar 28, 2016, 4:59:38 PM3/28/16
to Keras-users
I'm using class_weight for a 2 class problem with no issues.

Can you post some code?


On Tuesday, February 2, 2016 at 4:06:01 AM UTC-5, Klaymen wrote:

Alex

unread,
Feb 18, 2017, 4:47:11 PM2/18/17
to Keras-users

I am getting the same error with just 2 class weights. See details here: https://github.com/fchollet/keras/issues/5437  Any suggestions?

al...@goodman.io

unread,
Feb 19, 2017, 6:33:07 PM2/19/17
to Keras-users
You should implement a custom loss objective, e.g.

Alex

unread,
Feb 22, 2017, 2:37:36 PM2/22/17
to Keras-users, al...@goodman.io
Thanks for the reply! The thread you pointed out should help. I was expecting that Keras would have integrated the class balancing in `class_weight`.
Reply all
Reply to author
Forward
0 new messages