I want to perform a simple linear transformation on a layer x, so the output of the transformation is y = a*x + b. I am working with images, so x is 3-dimensional (height * width * channels). Then a is a scale vector of size c, where c is the number of channels, and it has a single scale parameter for each channel dimension of x. Similarly, b is a shift vector of size and it has a single shift parameter for each channel dimension of x. This is a simple variation of normalization without normalizing the batch statistics.
Here is an example:
# TODO: learn gamma and beta parameters
x = tf.keras.layers.Conv2D(filters=num_filters_e1,
kernel_size=5,
strides=2,
padding='same')(input)
x = tf.keras.layers.Multiply()([x, gamma]) # scale by gamma along channel dim
x = tf.keras.layers.Add()([x, beta]) # shift with beta along channel dim
y = tf.keras.layers.ReLU()(x) # apply activation after transformation
I'm not sure about how to obtain gamma and beta. These are supposed to be parameters learned by the model during training, but I'm not sure how to construct or specify them. Typically I just specify layers (either convolutional or dense) to learn weights, but I'm not sure what layer to use here and what the layer should take in as input. Do I have to somehow initialize a vector of ones and then learn the weights to transform those into gamma and beta?
Even if it is possible to do this with TensorFlow's batchnorm layer (which is still useful to know), I would like to learn how to implement this scaling/shifting from scratch. Thank you!