简体   繁体   English

每个训练keras模型后的结果都不同

[英]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.

相关问题 在Google Cloud上训练不同的Keras模型的结果 - Results of training a Keras model different on Google Cloud 每次重复后,keras 模型的训练变慢 - Training of keras model get's slower after each repetition 每次训练通过后重新初始化keras模型权重 - reinitializing keras model weights after each training pass Keras 模型分类为每个模型重新编译返回不同的结果 - Keras Model classifying returning different results for each model recompiling 培训和评估的准确性在keras LSTM模型中不同:为什么评估产生的结果与培训期间不同? - Training and evaluating accuracies different in keras LSTM model: why does evaluation not produce same results as during training? 不同的model.fit输出(加载模型无训练后)和keras中的model.predict - different output of model.fit (after loading model no training) and model.predict in keras 在Keras中对同一批次的培训和评估结果不同 - Different results in training and evaluation of the same batch in Keras 相同输入 Keras 的不同训练和验证结果 - Different training and validation results with same input Keras 将损失乘以标量后,为什么在训练Keras模型时得到不同的结果? - Why do I get different results when training a Keras model when I multiply the loss by a scalar? 在 keras 中针对不同批次大小训练 model - training model for different batch sizes in keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM