代码之家  ›  专栏  ›  技术社区  ›  user239457

在keras的不同培训课程中不同的验证精度[副本]

  •  0
  • user239457  · 技术社区  · 6 年前

    我在Mnist上训练了keras模型,使训练和模型超参数保持一致。培训和验证数据完全相同。在不同的训练中,我得到了五种不同的准确度-0.71,0.62,0.59,0.52,0.46。模型每次从零开始训练8个时期

    代码如下:

    def train():
        model = Sequential()
        model.add(Dense(32, input_dim=784))
        model.add(Dense(10, activation="softmax"))
        model.compile(loss='categorical_crossentropy',
                      optimizer='adam',
                      metrics=['accuracy'])
    
        model.fit(x_train, y_train, batch_size=32, epochs=8, verbose=0)
        results = model.evaluate(x_test, y_test, verbose=0)
        print(results[1])
    
    
    for i in range(5):
        print(i)
        train()
    

    结果:

    0
    2019-01-23 13:26:54.475110: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    0.7192
    1
    0.6223
    2
    0.5976
    3
    0.5223
    4
    0.4624
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Shubham Panchal    6 年前

    这可能只是因为模型的权重每次都是随机生成的。假设,我训练了两个具有相同数据和超参数的模型。由于它们最初有不同的权重,因此它们的损失和精度会有所不同。但是,经过一定数量的历元之后,它们都会收敛到同一点,在这个点上,两个模型的精度和损失似乎相等。这一点可能是关于损失的最小值,因为数据是相同的。否则,这可能是两个模型获得相同收敛路径的点。

    在你的例子中,也许训练更多的时代会给所有的模型带来相同的损失和精确度。