trainer.py
def _train_epoch(self, epoch: int):
        """Trains the model for one epoch"""
        total_loss = utils.AveTracker()
        top1_acc = utils.AveTracker()
        top5_acc = utils.AveTracker()
        self.model.train()

        for step, (x, y) in enumerate(self.train_loader):
            x = x.to(self.device, non_blocking=True)
            y = y.to(self.device, non_blocking=True)

            self.optimizer.zero_grad()
            logits = self.model(x)
            loss = self.criterion(logits, y)
            loss.backward()
            self.optimizer.step()

            prec1, prec5 = utils.accuracy(logits, y, topk=(1, 5))
            n = x.size(0)
            total_loss.update(loss.item(), n)
            top1_acc.update(prec1.item(), n)
            top5_acc.update(prec5.item(), n)

            self.scheduler.step()

            if step % 100 == 0:
                self.logger.info('train %d %e %f %f', step,
                                 total_loss.average, top1_acc.average, top5_acc.average)

        return top1_acc.average, top5_acc.average, total_loss.average
Trains the model for one epoch
Trains the model for one epoch
Trains the model for one epoch
def _train_epoch(self, epoch: int):
        total_loss = utils.AveTracker()
        top1_acc = utils.AveTracker()
        top5_acc = utils.AveTracker()
        self.model.train()
        for step, (x, y) in enumerate(self.train_loader):
            x = x.to(self.device, non_blocking=True)
            y = y.to(self.device, non_blocking=True)
            self.optimizer.zero_grad()
            logits = self.model(x)
            loss = self.criterion(logits, y)
            loss.backward()
            self.optimizer.step()
            prec1, prec5 = utils.accuracy(logits, y, topk=(1, 5))
            n = x.size(0)
            total_loss.update(loss.item(), n)
            top1_acc.update(prec1.item(), n)
            top5_acc.update(prec5.item(), n)
            self.scheduler.step()
            if step % 100 == 0:
                self.logger.info('train %d %e %f %f', step,
                                 total_loss.average, top1_acc.average, top5_acc.average)
        return top1_acc.average, top5_acc.average, total_loss.average
def _train_epoch ( self , epoch : int ) : total_loss = utils . AveTracker ( ) top1_acc = utils . AveTracker ( ) top5_acc = utils . AveTracker ( ) self . model . train ( ) for step , ( x , y ) in enumerate ( self . train_loader ) : x = x . to ( self . device , non_blocking = True ) y = y . to ( self . device , non_blocking = True ) self . optimizer . zero_grad ( ) logits = self . model ( x ) loss = self . criterion ( logits , y ) loss . backward ( ) self . optimizer . step ( ) prec1 , prec5 = utils . accuracy ( logits , y , topk = ( 1 , 5 ) ) n = x . size ( 0 ) total_loss . update ( loss . item ( ) , n ) top1_acc . update ( prec1 . item ( ) , n ) top5_acc . update ( prec5 . item ( ) , n ) self . scheduler . step ( ) if step % 100 == 0 : self . logger . info ( 'train %d %e %f %f' , step , total_loss . average , top1_acc . average , top5_acc . average ) return top1_acc . average , top5_acc . average , total_loss . average
Trains the model for one epoch
Trains the model for one epoch
"""Trains the model for one epoch"""
self
epoch
int