I am performing regression learning using an Artifical neural network in keras with tensorflow backend.
My input shape is [100,3] ([no of samples,no of features]).
My output shape is [100,3] ([no of samples,no of outputs]).
I want to pass a 4 dimensional data alongside each input sample (shape of this data will be [100,4]) so that i can access it for writing a custom loss function. I don't want it to get involved in the training process.
Something like this:
def wrapper(input_tensor):
def custom_loss(y_true, y_pred):
return binary_crossentropy(y_true, y_pred) + mean(last 4 elements of the input_tensor)
return custom_loss
I researched quite a lot on functional API and how keras can be used with multiple inputs and multiple outputs for training the network. But, since i don't want it to get involved in the training phase and still needs to be passed onto the custom loss function - i don't think it will serve my purpose.
My intuition for solving this:
1. Append the 4 dimensional data to the input, mask those 4 input neurons while training the network, by passing only a part of the input layer(excluding the last 4 elements) to the next layer.
- Problem is, i don't think we can mask neurons like this.
2. Have the 4 dimensional data as additional input to the network using functional APIs.
- Problem is, i can't pass the 4 dimensional data to the custom loss function without involving it in the training process.
Can anyone please help me solve this? Please let me know, if any extra information is needed.
I think, even this question - How to use part of inputs for training but rest for loss function in Keras follows my need. But, it is not answered :(