Reputation: 127
I'm a newbie in Machine Learning. I want to build a keras model which will be used for facial recognition. I am currently using the model at:
model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same',
input_shape=x_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))
# initiate RMSprop optimizer
opt = keras.optimizers.rmsprop(lr=0.0001, decay=1e-6)
# Let's train the model using RMSprop
model.compile(loss='categorical_crossentropy',
optimizer=opt,
metrics=['accuracy'])
I trained with the same data and parameters the same, but the training results are very different.There are 100% results or 28% results. What made that difference?
Upvotes: 2
Views: 932
Reputation: 16966
Setting the seed, when training the model will solve the problem. This will give you the repeatability.
np.random.seed(10)
tf.set_random_seed(10)
Also make sure train and test split also does not change ever instance. Hence, you can set the seed for data splitting also.
Upvotes: 3