I would like to create a custom layer in Keras. The layer will take two arrays as input and will output one of the two arrays, selected at random. No other operations on the arrays are performed.

The point is to simultaneously feed two sets of data to a model. This layer will select only one of the channels. The model will be tasked to recognize from which set the data is. Because I would like to merge this model into another architecture I would like to have this layer working.

I cannot seem to make this work. I have tried several techniques but all of them require a random number to be generated (eg 0 or 1 for channel 0 or 1, respectively). But this number is only generated once when the model is compiled rather than at each data passthrough, resulting in a deterministic channel selection.

Would anyone have a hint or some idea on how to proceed?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.