code: def write_from_directory(
      directory: str,
      label_map: Dict[str, int],
      output_path: str,
      shuffle: bool = True,
      **kwargs,
  ) -> None:
      labels = os.listdir(directory)
      valid_labels = [label for label in labels if label in label_map]
      generator = []
      for label in valid_labels:
          label_path = os.path.join(directory, label)
          images = os.listdir(label_path)
          for image in images:
              image_path = os.path.join(label_path, image)
              generator.append(
                  {
                      "image": image_path,
                      "label": label_map[label],
                      "image_id": image_path,
                      "label_str": label,
                  }
              )
      if shuffle:
          random.shuffle(generator)
  
      schema = {
          "image": SchemaField(
              feature_type=FeatureType.IMAGE,
              dtype=DType.FLOAT32,
              shape=(),
          ),
          "label": SchemaField(
              feature_type=FeatureType.SCALAR,
              dtype=DType.INT32,
              shape=(),
          ),
          "image_id": SchemaField(
              feature_type=FeatureType.SCALAR,
              dtype=DType.STRING,
              shape=(),
          ),
          "label_str": SchemaField(
              feature_type=FeatureType.SCALAR,
              dtype=DType.STRING,
              shape=(),
          ),
      }
  
      ParquetDataset.write(output_path, generator, schema, **kwargs)
  
imports: from pyspark import SparkContext
  from pyspark.sql import SparkSession
  from bigdl.dllib.nncontext import init_nncontext
  from bigdl.orca.data import SparkXShards
  from bigdl.orca.data.file import open_text, write_text
  from bigdl.orca.data.image.utils import chunks, dict_to_row, row_to_dict, encode_schema, decode_schema, SchemaField, FeatureType, DType, ndarray_dtype_to_dtype, decode_feature_type_ndarray, pa_fs
  from bigdl.orca.data.image.voc_dataset import VOCDatasets
  from bigdl.dllib.utils.common import get_node_and_core_number
  import os
  import numpy
  import random
  import io
  import math
  from bigdl.dllib.utils.log4Error import invalidInputError
  from numpy import ndarray, uint32
  from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union, Any
label_desc: Use image node_id 4 for calling a global function with example usage: write_from_directory(directory, label_map, output_path, shuffle) without return types