code: def train(epoch):
      random.shuffle(train_data)
      i = 0
      epoch_start = time.time()
      while i < len(train_data):
          dy.renew_cg()
          lbls = []
          imgs = []
          for lbl, img in train_data[i : i + args.batch_size]:
              lbls.append(lbl)
              imgs.append(img)
          losses = network.create_network_return_loss(
              imgs, lbls, dropout=True
          )
          loss = dy.mean_batches(losses)
          if (int(i / args.batch_size)) % args.log_interval == 0:
              print(
                  "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}".format(
                      epoch,
                      i,
                      len(train_data),
                      100.0 * i / len(train_data),
                      loss.value(),
                  )
              )
          loss.backward()
          trainer.update()
          i += args.batch_size
      epoch_end = time.time()
      print("{} s per epoch".format(epoch_end - epoch_start))
  
file_path: dynet/examples/mnist/basic-mnist-benchmarks/mnist_dynet_minibatch.py
imports: from __future__ import division
  import os
  import struct
  import argparse
  import random
  import time
  import numpy
  import dynet
label_desc: Use image node_id 2 for calling a global function with example usage: train(epoch) without return types