What is the use of verbose in Keras while validating the model?

204,060

Solution 1

Check documentation for model.fit here.

By setting verbose 0, 1 or 2 you just say how do you want to 'see' the training progress for each epoch.

verbose=0 will show you nothing (silent)

verbose=1 will show you an animated progress bar like this:

progres_bar

verbose=2 will just mention the number of epoch like this:

enter image description here

Solution 2

verbose: Integer. 0, 1, or 2. Verbosity mode.

Verbose=0 (silent)

Verbose=1 (progress bar)

Train on 186219 samples, validate on 20691 samples
Epoch 1/2
186219/186219 [==============================] - 85s 455us/step - loss: 0.5815 - acc: 
0.7728 - val_loss: 0.4917 - val_acc: 0.8029
Train on 186219 samples, validate on 20691 samples
Epoch 2/2
186219/186219 [==============================] - 84s 451us/step - loss: 0.4921 - acc: 
0.8071 - val_loss: 0.4617 - val_acc: 0.8168

Verbose=2 (one line per epoch)

Train on 186219 samples, validate on 20691 samples
Epoch 1/1
 - 88s - loss: 0.5746 - acc: 0.7753 - val_loss: 0.4816 - val_acc: 0.8075
Train on 186219 samples, validate on 20691 samples
Epoch 1/1
 - 88s - loss: 0.4880 - acc: 0.8076 - val_loss: 0.5199 - val_acc: 0.8046

Solution 3

For verbose > 0, fit method logs:

  • loss: value of loss function for your training data
  • acc: accuracy value for your training data.

Note: If regularization mechanisms are used, they are turned on to avoid overfitting.

if validation_data or validation_split arguments are not empty, fit method logs:

  • val_loss: value of loss function for your validation data
  • val_acc: accuracy value for your validation data

Note: Regularization mechanisms are turned off at testing time because we are using all the capabilities of the network.

For example, using verbose while training the model helps to detect overfitting which occurs if your acc keeps improving while your val_acc gets worse.

Solution 4

verbose is the choice that how you want to see the output of your Nural Network while it's training. If you set verbose = 0, It will show nothing

If you set verbose = 1, It will show the output like this Epoch 1/200 55/55[==============================] - 10s 307ms/step - loss: 0.56 - accuracy: 0.4949

If you set verbose = 2, The output will be like Epoch 1/200 Epoch 2/200 Epoch 3/200

Solution 5

By default verbose = 1,

verbose = 1, which includes both progress bar and one line per epoch

verbose = 0, means silent

verbose = 2, one line per epoch i.e. epoch no./total no. of epochs

Share:
204,060
rakesh
Author by

rakesh

Updated on July 08, 2022

Comments

  • rakesh
    rakesh almost 2 years

    I'm running the LSTM model for the first time. Here is my model:

    opt = Adam(0.002)
    inp = Input(...)
    print(inp)
    x = Embedding(....)(inp)
    x = LSTM(...)(x)
    x = BatchNormalization()(x)
    pred = Dense(5,activation='softmax')(x)
    
    model = Model(inp,pred)
    model.compile(....)
    
    idx = np.random.permutation(X_train.shape[0])
    model.fit(X_train[idx], y_train[idx], nb_epoch=1, batch_size=128, verbose=1)
    

    What is the use of verbose while training the model?

  • rakesh
    rakesh over 6 years
    verbose: Integer. 0, 1, or 2. Verbosity mode. 0 = silent, 1 = progress bar, 2 = one line per epoch. Thanks @ank you rock..
  • Chrisji
    Chrisji over 5 years
    What relevance is regularisation to the verbosity parameter?!
  • Hugo Bevilacqua
    Hugo Bevilacqua over 5 years
    Verbose parameter has no impact on regularisation mechanisms. I'm just adding information about what is displayed if verbose is enabled (to reply to the initial question "What is the use of verbose while training the model?" => ex: avoiding overfitting by comparing acc and val_acc).
  • Konstantin Sekeresh
    Konstantin Sekeresh over 5 years
    This comment is the best answer to the question, even better than the answer being commented. Note this and try to avoid words just to make the answer longer. @rakesh, you rock.
  • Dr Nisha Arora
    Dr Nisha Arora almost 5 years
    Can you explain why am I not getting the expected output for differnt vakues of verbose. I'm getting same [silent] output for verbose = 0 and 2 for my file? And for verbose = 1, I'm getting progress bar only at the end of epochs like Epoch 10/10 - 21s - loss: 0.2354 - acc: 0.9286 - val_loss: 0.2206 - val_acc: 0.9344 [==============================] Accuracy: 0.9344 Error: 6.560000000000002
  • Bobs Burgers
    Bobs Burgers almost 4 years
    great answer, helped me out. Valid for tensorflow 2.2
  • akshit bhatia
    akshit bhatia about 2 years
    the last message in your answer is the best one, i would say.