Method that prints out Training, Validation Loss

Which method prints out the training and validation losses after each epoch.

image

Could not find these methods by searching through the library, which is odd.
They should be related to the for loop in the fit method shown below.
But can’t figure out how.

fit method from the file model.py

def fit(model, data, epochs, opt, crit, metrics=None, callbacks=None, **kwargs):

    stepper = Stepper(model, opt, crit, **kwargs)
    metrics = metrics or []
    callbacks = callbacks or []
    avg_mom=0.98
    batch_num,avg_loss=0,0.

    for epoch in tnrange(epochs, desc='Epoch'):
        stepper.reset(True)
        t = tqdm(iter(data.trn_dl), leave=False, total=len(data.trn_dl))
        for (*x,y) in t:
            batch_num += 1
            loss = stepper.step(V(x),V(y))
            avg_loss = avg_loss * avg_mom + loss * (1-avg_mom)
            debias_loss = avg_loss / (1 - avg_mom**batch_num)
            t.set_postfix(loss=debias_loss)
            stop=False
            for cb in callbacks: stop = stop or cb.on_batch_end(debias_loss)
            if stop: return

You are right that the printing function must be in the fit function, however it is not that loop you posted, but a little below.

Here is a link to the line on github: https://github.com/fastai/fastai/blob/1f35c0259c3c5e1a9f1742c691a7d53ddd099650/fastai/model.py#L108

cheers, Johannes

2 Likes

Thanks @j.laute. That missed me completely.