[英]The results after each training keras model are different
I'm a newbie in Machine Learning. 我是机器学习的新手。 I want to build a keras model which will be used for facial recognition. 我想建立一个用于面部识别的keras模型。 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. 我用相同的数据和参数训练了相同的东西,但是训练的结果却大不相同,结果是100%或28%。 What made that difference? 是什么导致了差异?
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. 因此,您也可以为数据拆分设置种子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.