TensorFlow.NET icon indicating copy to clipboard operation
TensorFlow.NET copied to clipboard

[BUG Report]: Model.fit verbose is always set to 1.

Open AdrienDeverin opened this issue 1 year ago • 2 comments

Description

Dear community, During the fit of a model, logs are shown even if verbose == 0. For exemple the code below :

// IModel cnn,  NDArray x_train, NDArray y_train, List<ICallback>? callbacks, int verbose = 0
        
cnn.fit(x_train, y_train,
        batch_size: this.test_batchsize,
        epochs: this.test_epoch,
        validation_split: (1 - this.test_valid_split),
        callbacks: callbacks,
        verbose: verbose);
            

Print this inside the console :

Epoch: 001/020
0003/0003 [===================>.........] - 15ms/step - loss: 0,132586 - accuracy: 0,566667 - val_loss: 0,103679 - val_accuracy: 0,500000
Epoch: 002/020
0003/0003 [===================>.........] - 15ms/step - loss: 0,101685 - accuracy: 0,600000 - val_loss: 0,065386 - val_accuracy: 0,500000
Epoch: 003/020
0003/0003 [===================>.........] - 16ms/step - loss: 0,079935 - accuracy: 0,666667 - val_loss: 0,070092 - val_accuracy: 0,375000
Epoch: 004/020
0003/0003 [===================>.........] - 17ms/step - loss: 0,079053 - accuracy: 0,600000 - val_loss: 0,067726 - val_accuracy: 0,500000
...

It's a problem to me, because it flood the console (even if verbose is set to 0 or below). How can we fixe it ?

Reproduction Steps

Any exemple of a cnn run with verbose set to 0.

Known Workarounds

No response

Configuration and Other Information

No response

AdrienDeverin avatar Feb 08 '24 13:02 AdrienDeverin

I think the identification of the problem is here :

in FitInternal() function is writed

CallbackList callbackList2 = new CallbackList(new CallbackParams
            {
                Model = this,
                Verbose = verbose,
                Epochs = epochs,
                Steps = data_handler.Inferredsteps
            });

In this case, it correspond to 2 callbacks (why forcing them ? ) :

public CallbackList(CallbackParams parameters)
        {
            callbacks.Add(new History(parameters));
            callbacks.Add(new ProgbarLogger(parameters));
        }

and when we see the History ICallback :

public class History : ICallback
    { ...
     public void on_epoch_end(int epoch, Dictionary<string, float> epoch_logs)
        {
            epochs.Add(epoch);
            foreach (KeyValuePair<string, float> epoch_log in epoch_logs)
            {
                if (!history.ContainsKey(epoch_log.Key))
                {
                    history[epoch_log.Key] = new List<float>();
                }

                history[epoch_log.Key].Add(epoch_log.Value);
            }
        }
     }

verbose is never take in acount ...

AdrienDeverin avatar Feb 08 '24 14:02 AdrienDeverin

Thanks for pointing this out, we would love to merge it if you could PR the patch.

Oceania2018 avatar Feb 09 '24 01:02 Oceania2018