I want to write a custom layer in Keras which modifies both input as well as the corresponding output labels of the network. Is it possible to modify the output labels?
I already wrote the custom layer which changes the input. Now, I need to modify the output labels of the network accordingly. I have no idea how to achieve this.
Here is an example of what I have/want:
from keras import layers
import numpy as np
class MyLayer(layers.Layer):
def call(self, x):
a = np.random.randint(0, 5)
new_x = x + a
new_y = y + a # <-- how can I do this?
return new_x
Is it even possible to modify the output labels during the training?
The expected result would be the following:
- Assume the following training set:
X = [[1, 2, 3], [4, 5, 6]]
Y = [1, 2]
- During training, the input and labels could be modified to be something like (with a different
ain every epoch
a = 2
X = [[3, 4, 5], [6, 7, 8]]
Y = [3, 4]