Please make sure that the boxes below are checked before you submit your issue. Thank you!
I'm trying to implement a custom layer in Keras and need some parameters to be passed to the call() function. These parameters depend on the specific training instance. How can I pass these parameters to the layer during training?
Recently, I'm defining a own layer, and suffer a similar question.
I want to ask your quetion. How do you get the value of x in call(x) function.
Is there a existing method or It need me to define a function?
The value x is the input to the custom layer you've defined.
from keras.layers import Input, Dense
from keras.models import Model
inputs = Input(shape=(784,))
dense = Dense(64, activation='relu')(inputs)
custom_layer = CustomLayer(32, activation='relu')(dense)
In the above example, the 'dense' variable output from the Dense layer is passed to the call(x) function of your custom layer. You just need to define the model appropriately.
I finally found a way through. Made a Lambda layer which took extra Input parameter
custom_layer = Lambda(custom_layer, output_shape=custom_layer_output_shape, arguments={'extra_parameter':extra_parameter})
where extra_parameter was an extra input to the model.
@stillbreeze This extra parameter would be constant. Is there any way we could be able to pass different parameter values based on the point that we are processing at the current time.
@KiriteeGak : Just pass it as an input to the graph in the functional API.
Most helpful comment
I finally found a way through. Made a Lambda layer which took extra Input parameter
custom_layer = Lambda(custom_layer, output_shape=custom_layer_output_shape, arguments={'extra_parameter':extra_parameter})where extra_parameter was an extra input to the model.