Keras multi-label

1.4k views Asked by At

The particular model I am working on has 34 outputs. What I want to do is multi-label classification (I think)

model = Sequential()
model.add(Dense(39, activation='relu', input_shape=(None,39)))
model.add(Dropout(0.1))
model.add(Dense(80, activation='relu'))
model.add(Dropout(0.1))
model.add(Dense(80, activation='relu'))
model.add(Dense(34, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='Adam', metrics=["accuracy"])
preds = model.predict(inputVal)
preds = numpy.round(preds)

This is the basic structure I have opted for, and have trained it for all single cases of the output.

eg: [1 0 0 0], [ 0 1 0 0 ], [0 0 1 0],[ 0 0 0 1]

And from that I wanted it to be able to predict cases with multiple output labels true

eg: [0 0 1 1], [ 0 1 0 1], [1 0 0 1], [0 1 1 0], [1 0 1 0], [1 1 1 1], [1 1 0 1], etc

Obviously since I've trained it, it works well for the trained data (single output), but not doesn't seem to work at all when i go for giving data which should result in two of the outputs being 1.

Any ideas?

The inputs are numbers between -1 and 1.

An example of a correct input and output (from the training data):

Input:

[[[-0.12758331 -0.06901649 -0.15094464 -0.17489645 -0.15544203 -0.14380834
   -0.18091092 -0.18897641 -0.17389235 -0.10287826 -0.11684579 -0.11721818
   -0.11573362 -0.14598145 -0.1626517  -0.14156958 -0.16716516 -0.16869128
   -0.05066699 -0.0681744  -0.09898532 -0.02063701 -0.02412137 -0.13948624
   -0.02347892  0.03032054 -0.21435449  0.09052061  0.1380952  -0.02646382
    0.          0.03725522  0.04055786  0.02249375  0.06630866  0.11343291
    0.09429274  0.26084685 -0.1625745 ]]]

Output:

[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.  0.]
0

There are 0 answers