epoch_loss = (epoch_loss / len(data_loader)).item()
epoch_acc = (epoch_acc / len(data_loader.dataset)) * 100
data_loader is a class that conveniently loads data in batches so how is that taking .item()
from the math done inside the (())
?
epoch_loss = (epoch_loss / len(data_loader)).item()
epoch_acc = (epoch_acc / len(data_loader.dataset)) * 100
data_loader is a class that conveniently loads data in batches so how is that taking .item()
from the math done inside the (())
?
Hey,
.item()
returns the value of a (single valued) tensor as a python object.
In the first line, it’s just taking the average of the losses from all the batches in a single epoch to get the epoch_loss
.
Similarly, epoch_acc
is the average accuracy in the second line.