code: def get_data_iterator_and_num_class(args):
      """
      Get Data_iterator for training and test data set.
      Also, obtain class / category information from data.
      """
      if args.train_csv:
          from nnabla.utils.data_iterator import (
              data_iterator_csv_dataset,
          )
  
          data_iterator = data_iterator_csv_dataset
  
          if args.test_csv:
              assert os.path.isfile(
                  args.test_csv
              ), "csv file for test not found."
  
              # check the number of the classes / categories
              with open(args.train_csv, "r") as f:
                  csv_data_train = f.readlines()[
                      1:
                  ]  # line 1:"x:image,y:label"
              classes_train = {
                  line.split(",")[-1].strip() for line in csv_data_train
              }
  
              with open(args.test_csv, "r") as f:
                  # first line:"x:image,y:label"
                  csv_data_test = f.readlines()[1:]
              classes_test = {
                  line.split(",")[-1].strip() for line in csv_data_test
              }
              classes_train.update(classes_test)
  
              num_class = len(classes_train)
  
              data_iterator_train = data_iterator_csv_dataset(
                  args.train_csv,
                  args.batch_size,
                  args.shuffle,
                  normalize=False,
              )
  
              data_iterator_valid = data_iterator_csv_dataset(
                  args.test_csv,
                  args.batch_size,
                  args.shuffle,
                  normalize=False,
              )
          else:
              print(
                  "No csv file for test given. So split the training data"
              )
              assert isintance(
                  args.ratio, float
              ), "ratio must be in (0.0, 1.0)"
  
              # check the number of the classes / categories
              with open(args.train_csv, "r") as f:
                  # first line is "x:image,y:label"
                  csv_data_train = f.readlines()[1:]
              all_classes = {
                  line.split(",")[-1].strip() for line in csv_data_train
              }
              num_class = len(all_classes)
              all_data = data_iterator_csv_dataset(
                  args.train_csv,
                  args.batch_size,
                  args.shuffle,
                  normalize=False,
              )
  
              num_samples = all_data.size
              num_train_samples = int(args.ratio * num_samples)
  
              data_iterator_train = all_data.slice(
                  rng=None, slice_start=0, slice_end=num_train_samples
              )
  
              data_iterator_valid = all_data.slice(
                  rng=None,
                  slice_start=num_train_samples,
                  slice_end=num_samples,
              )
  
      else:
          # use caltech101 data like tutorial
          from caltech101_data import data_iterator_caltech101
  
          assert isintance(
              args.ratio, float
          ), "ratio must be in (0.0, 1.0)"
          data_iterator = data_iterator_caltech101
          num_class = 101  # pre-defined (excluding background class)
          all_data = data_iterator(
              args.batch_size, width=args.width, height=args.height
          )
  
          num_samples = all_data.size
          num_train_samples = int(args.ratio * num_samples)
  
          data_iterator_train = all_data.slice(
              rng=None, slice_start=0, slice_end=num_train_samples
          )
  
          data_iterator_valid = all_data.slice(
              rng=None,
              slice_start=num_train_samples,
              slice_end=num_samples,
          )
  
      print("training images: {}".format(data_iterator_train.size))
      print("validation images: {}".format(data_iterator_valid.size))
      print("{} categories included.".format(num_class))
  
      return data_iterator_train, data_iterator_valid, num_class
  
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 1 for calling a global function with example usage: get_data_iterator_and_num_class(args) and returns: data_iterator_train,  data_iterator_valid,  num_class