When I have an image , I can standardize the image channel-wise as follows :
image[:, :, 0] = ((image[:, :, 0]-mean_1))/std_1
image[:, :, 1] = ((image[:, :, 1]-mean_2))/std_2
image[:, :, 2] = ((image[:, :, 2]-mean_3))/std_3
Where mean_1 and std_1 are the first channel mean and standard deviation . Same for mean_2, std_2 ,mean_3 and std_3. But right now the image is a tensor and has the following info :
(460, 700, 3) <dtype: 'float32'>
<class 'tensorflow.python.framework.ops.Tensor'>
I am new to tensorflow and I don't know how to convert the above formulas to a code that perform the same task on the tensor image
?
Edit : The means and the stds are calculated over all the dataset images by me. So I have their values.
Update 1 : I have tried to solve this problem using tf.keras.layers.Normalization impeded into my model :
inputs = keras.Input(shape=(460,700,3))
norm_layer = Normalization(mean=[200.827,160.252,195.008],
variance=[np.square(33.154),
np.square(45.877),
np.square(29.523)])
inputs=norm_layer(inputs)
This raises new two questions :
Does tf.keras.layers.Normalization and the above code normalizes the inputs per channel as I need ?
Using the above code , does tf.keras.layers.Normalization will work on test and validation data or training data only ? I need it to work on all the datasets.
Please help me guys :( I am so confused .