Belkacem Thiziri
Belkacem Thiziri

Reputation: 665

How to ignore some input layer, while predicting, in a keras model trained with multiple input layers?

I'm working with neural networks and I've implemented the following architecture using keras with tensorflow backend:

enter image description here

For training, I'll give some labels in the layer labels_vector, this vector can have int32 values (ie: 0 could be a label). For the testing phase, I need to just ignore this input layer, if I set it to 0 results could be wrong since I've trained with labels that can be equal to 0 vector. Is there a way to simply ignore or disable this layer on the prediction phase? Thanks in advance.

Upvotes: 1

Views: 2121

Answers (1)

Ghilas BELHADJ
Ghilas BELHADJ

Reputation: 14096

How to ignore some input layer ?

You can't. Keras cannot just ignore an input layer as the output depends on it.

One solution to get nearly what you want is to define a custom label in your training data to be the null value. Your network will learn to ignore it if it feels that it is not an important feature.

If labels_vector is a vector of categorical labels, use one-hot encoding instead of integer encoding. integer encoding assumes that there is a natural ordered relationship between each label which is wrong.

Upvotes: 3

Related Questions