code: def CNN_run(args, model):
      (
          data_iterator_train,
          data_iterator_valid,
          num_class,
      ) = get_data_iterator_and_num_class(args)
  
      channels, image_height, image_width = 3, args.height, args.width
      batch_size = args.batch_size
      initial_model_lr = args.model_lr
  
      one_epoch = data_iterator_train.size // batch_size
      max_iter = args.epoch * one_epoch
      val_iter = data_iterator_valid.size // batch_size
  
      # Create monitor.
      monitor = Monitor(args.monitor_path)
      monitor_loss = MonitorSeries(
          "Training loss", monitor, interval=100
      )
      monitor_err = MonitorSeries(
          "Training error", monitor, interval=100
      )
      monitor_vloss = MonitorSeries("Test loss", monitor, interval=100)
      monitor_verr = MonitorSeries("Test error", monitor, interval=100)
  
      # prepare variables and graph used for test
      image_valid = nn.Variable(
          (batch_size, channels, image_height, image_width)
      )
      label_valid = nn.Variable((batch_size, 1))
      input_image_valid = {"image": image_valid, "label": label_valid}
  
      pred_valid = construct_networks(
          args, image_valid, model, num_class, test=True
      )
      pred_valid.persistent = True
      loss_valid = loss_function(pred_valid, label_valid)
      top_1e_valid = F.mean(F.top_n_error(pred_valid, label_valid))
  
      # prepare variables and graph used for training
      image_train = nn.Variable(
          (batch_size, channels, image_height, image_width)
      )
      label_train = nn.Variable((batch_size, 1))
      input_image_train = {"image": image_train, "label": label_train}
  
      pred_train = construct_networks(
          args, image_train, model, num_class, test=False
      )
      loss_train = loss_function(pred_train, label_train)
      top_1e_train = F.mean(F.top_n_error(pred_train, label_train))
  
      # prepare solvers
      solver = S.Momentum(initial_model_lr)
      solver.set_parameters(nn.get_parameters())
  
      # Training-loop
      for i in range(max_iter):
          image, label = data_iterator_train.next()
          input_image_train["image"].d = image
          input_image_train["label"].d = label
          nn.forward_all(
              [loss_train, top_1e_train], clear_no_need_grad=True
          )
  
          monitor_loss.add(i, loss_train.d.copy())
          monitor_err.add(i, top_1e_train.d.copy())
  
          if args.lr_control_model:
              new_lr = learning_rate_scheduler(
                  i, max_iter, initial_model_lr, 0
              )
              solver.set_learning_rate(new_lr)
  
          solver.zero_grad()
          loss_train.backward(clear_buffer=True)
  
          if args.with_grad_clip_model:
              for k, v in nn.get_parameters().items():
                  v.grad.copy_from(
                      F.clip_by_norm(v.grad, args.grad_clip_value_model)
                  )
  
          # update parameters
          solver.weight_decay(args.weight_decay_model)
          solver.update()
  
          if i % args.model_save_interval == 0:
              # Validation during training.
              ve = 0.0
              vloss = 0.0
              for j in range(val_iter):
                  v_image, v_label = data_iterator_valid.next()
                  input_image_valid["image"].d = v_image
                  input_image_valid["label"].d = v_label
                  nn.forward_all(
                      [loss_valid, top_1e_valid], clear_buffer=True
                  )
                  vloss += loss_valid.d.copy()
                  ve += top_1e_valid.d.copy()
  
              ve /= val_iter
              vloss /= val_iter
              monitor_vloss.add(i, vloss)
              monitor_verr.add(i, ve)
  
              nn.save_parameters(
                  os.path.join(
                      args.model_save_path, "params_{}.h5".format(i)
                  )
              )
  
      ve = 0.0
      vloss = 0.0
      for j in range(val_iter):
          v_image, v_label = data_iterator_valid.next()
          input_image_valid["image"].d = v_image
          input_image_valid["label"].d = v_label
          nn.forward_all([loss_valid, top_1e_valid], clear_buffer=True)
          vloss += loss_valid.d.copy()
          ve += top_1e_valid.d.copy()
  
      ve /= val_iter
      vloss /= val_iter
      monitor_vloss.add(i, vloss)
      monitor_verr.add(i, ve)
  
      nn.save_parameters(
          os.path.join(args.model_save_path, "params_{}.h5".format(i))
      )
  
      return
  
file_path: nnabla/tutorial/finetuning.py
imports: import os
  import importlib
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  import nnabla.solvers
  import numpy
  from nnabla.ext_utils import get_extension_context
  from nnabla.monitor import Monitor, MonitorSeries, MonitorTimeElapsed
  from nnabla.utils.nnp_graph import NnpLoader, NnpNetworkPass
  from nnabla.utils.image_utils import imread
  from nnabla.utils.data_iterator import data_iterator_simple
  import argparse
label_desc: Use image node_id 5 for calling a global function with example usage: CNN_run(args, model) without return types