code: def train(use_cuda, train_program, params_dirname):
      # 批处理大小
      BATCH_SIZE = 128
      # 训练轮数
      EPOCH_NUM = 10
  
      train_reader = paddle.batch(
          paddle.reader.shuffle(
              paddle.dataset.cifar.train10(), buf_size=50000
          ),
          batch_size=BATCH_SIZE,
      )
  
      test_reader = paddle.batch(
          paddle.dataset.cifar.test10(), batch_size=BATCH_SIZE
      )
  
      def event_handler(event):
          if isinstance(event, fluid.EndStepEvent):
              # 每训练100个批次打印一次状态
              if event.step % 100 == 0:
                  print(
                      "\nStep %d, Epoch %d, Cost %f, Acc %f"
                      % (
                          event.step,
                          event.epoch,
                          event.metrics[0],
                          event.metrics[1],
                      )
                  )
              else:
                  sys.stdout.write(".")
                  sys.stdout.flush()
  
          if isinstance(event, fluid.EndEpochEvent):
              avg_cost, accuracy = trainer.test(
                  reader=test_reader, feed_order=["pixel", "label"]
              )
  
              print(
                  "\nTest with Epoch {0}, Loss {1:2.2}, Acc {2:2.2}".format(
                      event.epoch, avg_cost, accuracy
                  )
              )
              if params_dirname is not None:
                  trainer.save_params(params_dirname)
  
      # 根据配置选择使用CPU资源还是GPU资源
      place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
  
      trainer = fluid.Trainer(
          train_func=train_program,
          optimizer_func=optimizer_program,
          place=place,
      )
  
      trainer.train(
          reader=train_reader,
          num_epochs=EPOCH_NUM,
          event_handler=event_handler,
          feed_order=["pixel", "label"],
      )
  
file_path: AdvBox/tutorials/cifar10_model.py
imports: from __future__ import print_function
  from __future__ import absolute_import
  import paddle
  import paddle.fluid
  import numpy
  import sys
  import os
  from .image_classification.resnet import resnet_cifar10
label_desc: Use image node_id 4 for calling a global function with example usage: train(use_cuda, train_program, params_dirname) without return types