in Education by
When you run a Keras neural network model you might see something like this in the console: Epoch 1/3 6/1000 [..............................] - ETA: 7994s - loss: 5111.7661 As time goes on the loss hopefully improves. I want to log these losses to a file over time so that I can learn from them. I have tried: logging.basicConfig(filename='example.log', filemode='w', level=logging.DEBUG) but this doesn't work. I am not sure what level of logging I need in this situation. I have also tried using a callback like in: def generate_train_batch(): while 1: for i in xrange(0,dset_X.shape[0],3): yield dset_X[i:i+3,:,:,:],dset_y[i:i+3,:,:] class LossHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.losses = [] def on_batch_end(self, batch, logs={}): self.losses.append(logs.get('loss')) logloss=LossHistory() colorize.fit_generator(generate_train_batch(),samples_per_epoch=1000,nb_epoch=3,callbacks=['logloss']) but obviously, this isn't writing to a file. Whatever the method, through a callback or the logging module or anything else, I would love to hear your solutions for logging loss of a keras neural network to a file. Thanks! Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can simply use CSVLogger function in the callbacks class of keras. A callback is a set of functions to be applied at given stages of the training procedure. You can use callbacks to get a view on internal states and statistics of the model during training For example: from keras.callbacks import CSVLogger csv_logger = CSVLogger('log.csv', append=True, separator=';') model.fit(X_train, Y_train, callbacks=[csv_logger]) Hope this answer helps.

Related questions

0 votes
    How to load a model from an HDF5 file in Keras? What I tried: model = Sequential() model.add(Dense(64, ... list index out of range Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am training on 970 samples and validating on 243 samples. How big should batch size and number of epochs be ... on data input size? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I don't understand which accuracy in the output to use to compare my 2 Keras models to see which one is better. ... - val_acc: 0.7531 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am using autoencoders to do anomaly detection. So, I have finished training my model and now I want to ... y _true and y_pred Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I have just built my first model using Keras and this is the output. It looks like the standard output you get ... - loss: 0.1928 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have trained a binary classification model with CNN, and here is my code model = Sequential() model.add(Convolution2D ... I do that? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    The classifiers in machine learning packages like liblinear and nltk offer a method show_most_informative_features(), which ... lot! Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am learning programming (Python and algorithms) and was trying to work on a project that I find interesting. ... is impossible). Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I have an image with horizontal and vertical lines. In fact, this image is the BBC website converted to ... rectangle. Thanks! Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I try to learn and implement a simple genetic algorithm library for my project. At this time, evolution, ... Gaussian distribution?.) Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I'm working on some Artificial Intelligence project and I want to predict the bitcoin trend but while using the ... Thanks in advance! Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    If I want to use the BatchNormalization function in Keras, then do I need to call it once only at the ... much of a difference. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I have a simple NN model for detecting hand-written digits from a 28x28px image written in python using Keras: ... that actually means? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I'm trying to read an image from electrocardiography and detect each one of the main waves in it (P wave, QRS ... some ideas? Thanks! Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...