code: def read_voc(
      file_path: str = "VOCdevkit",
      split_names: Optional[List[Tuple[int, str]]] = None,
      classes: Optional[List[str]] = None,
      diff: bool = False,
      max_samples: int = None,
  ) -> "SparkXShards":
      """
      Read VOC images into a SparkXShards. code is ported from
      https://github.com/intel-analytics/BigDL/blob/main/python/orca/src/bigdl/orca/data/
      image/voc_dataset.py
  
      :param file_path: str. A HDFS path or local path of images.
      :param split_names: splits_names: tuple, ((year, trainval)).
      :param classes: str. A HDFS path or local path of target images.
      :param diff: boolean, False ignore voc xml difficult value.
  
      :param max_samples: int. max samples returned.
      :return: A new SparkXShards of tuple of image, target.
               target is a ndarray of [[x1, y1, x2, y2, cls, difficult]]
      """
  
      spark = OrcaContext.get_spark_session()
      anno_path = osp.join("{}", "Annotations", "{}.xml")
      image_path = osp.join("{}", "JPEGImages", "{}.jpg")
  
      split_names = split_names if split_names else [(2009, "trainval")]
      CLASSES = (
          classes
          if classes
          else [
              "aeroplane",
              "bicycle",
              "bird",
              "boat",
              "bottle",
              "bus",
              "car",
              "cat",
              "chair",
              "cow",
              "diningtable",
              "dog",
              "horse",
              "motorbike",
              "person",
              "pottedplant",
              "sheep",
              "sofa",
              "train",
              "tvmonitor",
          ]
      )
      cat2label = {cat: i for i, cat in enumerate(CLASSES)}
  
      def get_imgids(
          splits_names: List[Tuple[int, str]]
      ) -> List[Tuple[str, str]]:
          img_ids = []
          for year, txtname in splits_names:
              vocfolder = osp.join(file_path, "VOC{}".format(year))
              txtpath = osp.join(
                  vocfolder, "ImageSets", "Main", txtname + ".txt"
              )
              try:
                  with open(txtpath, "r", encoding="utf-8") as f:
                      img_ids += [
                          (vocfolder, line.strip())
                          for line in f.readlines()
                      ]
              except:
                  continue
          return img_ids
  
      def _check_label(
          label: "ndarray", width: int = 1, height: int = 1
      ) -> None:
          """Check if label is correct."""
          from bigdl.dllib.utils.log4Error import invalidInputError
  
          xmin = label[:, 0]
          ymin = label[:, 1]
          xmax = label[:, 2]
          ymax = label[:, 3]
          invalidInputError(
              ((0 <= xmin) & (xmin < width)).any(),
              "xmin must in [0, {}), given {}".format(width, xmin),
          )
          invalidInputError(
              ((0 <= ymin) & (ymin < height)).any(),
              "ymin must in [0, {}), given {}".format(height, ymin),
          )
          invalidInputError(
              ((xmin < xmax) & (xmax <= width)).any(),
              "xmax must in ({}, {}], given {}".format(
                  xmin, width, xmax
              ),
          )
          invalidInputError(
              ((ymin < ymax) & (ymax <= height)).any(),
              "ymax must in ({}, {}], given {}".format(
                  ymin, height, ymax
              ),
          )
  
      def get_img_label(f):
          image_file = image_path.format(*f)
          label_file = anno_path.format(*f)
  
          root = ET.parse(label_file).getroot()
          try:
              img = open_image(image_file)
          except FileNotFoundError as e:
              invalidOperationError(False, str(e), cause=e)
  
          width, height = img.size
  
          # load label [[x1, y1, x2, y2, cls, difficult]]
          label = []
          for obj in root.iter("object"):
              try:
                  difficult = int(obj.find("difficult").text)
              except ValueError:
                  difficult = 0
              cls_name = obj.find("name").text.strip().lower()
              if cls_name not in CLASSES:
                  logging.warning(
                      f"{cls_name} isn't included in {CLASSES}"
                  )
                  continue
              cls_id = cat2label[cls_name]
              xml_box = obj.find("bndbox")
              xmin = float(int(xml_box.find("xmin").text) / width)
              ymin = float(int(xml_box.find("ymin").text) / height)
              xmax = float(int(xml_box.find("xmax").text) / width)
              ymax = float(int(xml_box.find("ymax").text) / height)
              label.append([xmin, ymin, xmax, ymax, cls_id, difficult])
          label = np.array(label).astype(np.float32)
          if not diff:
              label = label[..., :5]
  
          try:
              _check_label(label, width, height)
          except RuntimeError as e:
              logging.warning("Invalid label at %s, %s", anno_path, e)
          return img, label
  
      img_paths = get_imgids(split_names)
      num_files = len(img_paths)
      node_num, core_num = get_node_and_core_number()
      total_cores = node_num * core_num
      num_partitions = (
          num_files if num_files < total_cores else total_cores
      )
      rdd = spark.sparkContext.parallelize(img_paths, num_partitions)
  
      def load_image(iterator):
          for f in iterator:
              img, labels = get_img_label(f)
              yield img, labels
  
      image_rdd = rdd.mapPartitions(load_image)
      if max_samples:
          image_rdd = spark.sparkContext.parallelize(
              image_rdd.take(max_samples)
          )
      return SparkXShards(image_rdd)
  
file_path: BigDL/python/orca/src/bigdl/orca/data/image/preprocessing.py
imports: from bigdl.orca import OrcaContext
  from typing import TYPE_CHECKING, Any, Tuple
  from bigdl.orca.data.file import *
  from bigdl.orca.data.utils import *
  from bigdl.orca.data import SparkXShards
  from pyspark.sql.functions import col, explode, collect_list
  from bigdl.dllib.utils.log4Error import invalidInputError
  from bigdl.dllib.utils.common import get_node_and_core_number
  import os.path
label_desc: Use image node_id 5 for calling a global function with example usage: read_voc(file_path, split_names, classes, diff, max_samples) and returns: SparkXShards, img_ids, img,  label