code: def create_dataset_stats(data_path, output_path=None, verbose=False):
      """
      Generates statistics for the given dataset and writes them to a JSON file. Expects the data to be in the following dir structure:
      dataroot
       | - Class Dir
           | - image 1
           | - image 2
           | - image N
  
      :param data_path: string - path to dataroot
      :param output_path: - path/filename to write the stats to (default: None - will output stats.json file in the dataroot)
  
      :return: None
      """
  
      stats = {}
      if output_path is None:
          output_path = os.path.join(data_path, "stats.json")
  
      dataset = FolderDataset(
          root=data_path,
          class_mode="label",
          default_loader=rgb_image_loader,
      )
  
      stats["num_items"] = len(dataset)
      mean, std = get_dataset_mean_std(dataset=dataset, img_size=256)
      stats["mean"], stats["std"] = (
          mean.tolist(),
          std.tolist(),
      )  # convert from numpy array to python
  
      if verbose:
          print("------- Dataset Stats --------")
          print(stats)
          print("Written to: ", output_path)
          print("------ End Dataset Stats ------")
  
      with open(output_path, "a") as statsfile:
          json.dump(stats, statsfile)
  
      return stats
  
file_path: pywick/pywick/data_stats.py
imports: import json
  import os
  import os.path
  import argparse
  import numpy
  from tqdm import tqdm
  from pywick.datasets.FolderDataset import FolderDataset, rgb_image_loader
label_desc: Use image node_id 2 for calling a global function with example usage: create_dataset_stats(data_path, output_path, verbose) and returns: stats