code: def train_one_epoch(
      model, optimizer, data_loader, device, epoch, lr_scheduler
  ):
      model.train()
      loss_function = torch.nn.CrossEntropyLoss()
      accu_loss = torch.zeros(1).to(device)  # 累计损失
      accu_num = torch.zeros(1).to(device)  # 累计预测正确的样本数
      optimizer.zero_grad()
  
      sample_num = 0
      data_loader = tqdm(data_loader, file=sys.stdout)
      for step, data in enumerate(data_loader):
          images, labels = data
          sample_num += images.shape[0]
  
          pred = model(images.to(device))
          pred_classes = torch.max(pred, dim=1)[1]
          accu_num += torch.eq(pred_classes, labels.to(device)).sum()
  
          loss = loss_function(pred, labels.to(device))
          loss.backward()
          accu_loss += loss.detach()
  
          data_loader.desc = "[train epoch {}] loss: {:.3f}, acc: {:.3f}, lr: {:.5f}".format(
              epoch,
              accu_loss.item() / (step + 1),
              accu_num.item() / sample_num,
              optimizer.param_groups[0]["lr"],
          )
  
          if not torch.isfinite(loss):
              print("WARNING: non-finite loss, ending training ", loss)
              sys.exit(1)
  
          optimizer.step()
          optimizer.zero_grad()
          # update lr
          lr_scheduler.step()
  
      return accu_loss.item() / (step + 1), accu_num.item() / sample_num
  
file_path: deep-learning-for-image-processing/pytorch_classification/ConvNeXt/utils.py
imports: import os
  import sys
  import json
  import pickle
  import random
  import math
  import torch
  from tqdm import tqdm
  import matplotlib.pyplot
label_desc: Use image node_id 5 for calling a global function with example usage: train_one_epoch(model, optimizer, data_loader, device, epoch, lr_scheduler) and returns: unknown,  unknown