I am using CNN for multi-class image classification, but accuracy is not very good. I assume I need to normalize training data with channel means and standard deviation so it might contribute to better accuracy. I came out one way for doing this, but it is not very efficient because I just put random value for means and standard deviation for normalization. I am not sure how to find channel means and its standard deviation. I was wondering is there any way of doing this. can anyone point me out how to achieve this? Any possible thoughts?
my current attempt:
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, Flatten, Input
from keras.datasets import cifar10
from keras.utils import to_categorical
(X_train, y_train), (X_test, y_test)= cifar10.load_data()
output_class = np.unique(y_train)
n_class = len(output_class)
input_shape = (32, 32, 3)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
y_train_one_hot = to_categorical(y_train)
y_test_one_hot = to_categorical(y_test)
x = tf.keras.Input(shape=(32, 32, 3))
conv = Conv2D(128, (3, 3), activation='relu',input_shape=(32, 32, 3))(x)
conv = MaxPooling2D(pool_size=(2,2))(conv)
conv = Conv2D(64, (2,2))(conv)
conv = MaxPooling2D(pool_size=(2,2))(conv)
conv = Flatten()(conv)
conv = Dense(64, activation='relu')(conv)
conv = Dense(10, activation='softmax')(conv)
model = Model(inputs = x, outputs = conv)
my attempt for normalization:
here is my way of normalization, where I just assigned random value to means and standard deviation:
mean = [125.307, 122.95, 113.865] ## random value
std = [62.9932, 62.0887, 66.7048] ## random value
for i in range(3):
X_train[:,:,:,i] = (X_train[:,:,:,i] - mean[i]) / std[i]
X_test[:,:,:,i] = (X_test[:,:,:,i] - mean[i]) / std[i]
I am wondering is there any way programmatically find channel means and its standard deviation so we could do normalization. Any better idea of doing this? what else possibly do for increasing accuracy of my sample model? How can I find channel means and its standard deviation? any possible strategy or coding attempt?