How to return history of validation loss in Keras

后端 未结 10 908
忘掉有多难
忘掉有多难 2020-12-02 16:37

Using Anaconda Python 2.7 Windows 10.

I am training a language model using the Keras exmaple:

print(\'Build model...\')
model = Sequential()
model.ad         


        
10条回答
  •  渐次进展
    2020-12-02 17:16

    Actually, you can also do it with the iteration method. Because sometimes we might need to use the iteration method instead of the built-in epochs method to visualize the training results after each iteration.

    history = [] #Creating a empty list for holding the loss later
    for iteration in range(1, 3):
        print()
        print('-' * 50)
        print('Iteration', iteration)
        result = model.fit(X, y, batch_size=128, nb_epoch=1) #Obtaining the loss after each training
        history.append(result.history['loss']) #Now append the loss after the training to the list.
        start_index = random.randint(0, len(text) - maxlen - 1)
    print(history)
    

    This way allows you to get the loss you want while maintaining your iteration method.

提交回复
热议问题