2

I need to create a neural network (with keras) that has as last layer a single neuron that contains the index of the neuron with the maximum value prediction in the precedent softmax layer.

For example my softmax layer gives as result this:

[0.1, 0.1, 0.7, 0.0, 0.05, 0.05]

And I want that the single neuron layer (after the softmax layer) gives as result 2 (considering a 0 based valutation).

How can I do that?

Francesco Scala
  • 201
  • 3
  • 15

1 Answers1

0

Using the idea FROM @Eric Platon:

import keras.backend as K
K.argmax(x, axis=-1)

But I'm not sure, if you can use a backend function as a layer. It may be necessary to wrap this in a lambda layer:

from keras.layers import Lambda
model.add(Lambda(lambda x: K.argmax(x, axis=-1)))
dennis-w
  • 2,166
  • 1
  • 13
  • 23