def train(self, epoch):
    self.model.train()
    average_loss = 0
    for (i, (inputs, gts)) in tqdm(enumerate(self.train_loader), total=len(self.train_loader)):
        (b, cv, t_len) = inputs[list(inputs.keys())[0]].shape
        if (b == 1):
            continue
        self.global_step = ((((epoch - 1) * len(self.train_loader)) + i) + 1)
        for k in inputs:
            inputs[k] = inputs[k].float().cuda(non_blocking=True, device=self.cfg.device)
            gts[k] = gts[k].float().cuda(non_blocking=True, device=self.cfg.device)
        outputs = self.model(inputs)
        losses = None
        for k in outputs:
            outputs[k] = ((outputs[k] + 1) / 2)
            outputs[k] = ((outputs[k] * (self.global_max - self.global_min)) + self.global_min)
            outputs[k] = reverse_dct_torch(outputs[k], self.i_dct_m, self.cfg.seq_len)
            loss_curr = L2NormLoss_train(gts[k], outputs[k])
            if (losses is None):
                losses = loss_curr
            else:
                losses = (losses + loss_curr)
            self.summary.add_scalar(f'Loss/{k}', loss_curr, self.global_step)
        self.optimizer.zero_grad()
        losses.backward()
        self.optimizer.step()
        average_loss += losses.cpu().data.numpy()
    average_loss /= (i + 1)
    return average_loss
def train(self, epoch):
    self.model.train()
    average_loss = 0
    for (i, (inputs, gts)) in tqdm(enumerate(self.train_loader), total=len(self.train_loader)):
        (b, cv, t_len) = inputs[list(inputs.keys())[0]].shape
        if (b == 1):
            continue
        self.global_step = ((((epoch - 1) * len(self.train_loader)) + i) + 1)
        for k in inputs:
            inputs[k] = inputs[k].float().cuda(non_blocking=True, device=self.cfg.device)
            gts[k] = gts[k].float().cuda(non_blocking=True, device=self.cfg.device)
        outputs = self.model(inputs)
        losses = None
        for k in outputs:
            outputs[k] = ((outputs[k] + 1) / 2)
            outputs[k] = ((outputs[k] * (self.global_max - self.global_min)) + self.global_min)
            outputs[k] = reverse_dct_torch(outputs[k], self.i_dct_m, self.cfg.seq_len)
            loss_curr = L2NormLoss_train(gts[k], outputs[k])
            if (losses is None):
                losses = loss_curr
            else:
                losses = (losses + loss_curr)
            self.summary.add_scalar(f'Loss/{k}', loss_curr, self.global_step)
        self.optimizer.zero_grad()
        losses.backward()
        self.optimizer.step()
        average_loss += losses.cpu().data.numpy()
    average_loss /= (i + 1)
    return average_loss