code: def fit_datagens(
      train_datagen,
      test_datagen,
      train_array=None,
      train_directory=None,
      target_size=None,
      color_mode="rgb",
      flat_dir=False,
  ):
      """
      ```
      computes stats of images for normalization
      ```
      """
      if not datagen_needs_fit(train_datagen):
          return
      if bool(train_array is not None) == bool(train_directory):
          raise ValueError(
              "only one of train_array or train_directory is required."
          )
      if train_array is not None:
          train_datagen.fit(train_array)
          test_datagen.fit(train_array)
      else:
          if target_size is None:
              raise ValueError(
                  "target_size is required when train_directory is supplied"
              )
          fit_samples = sample_image_folder(
              train_directory,
              target_size,
              color_mode=color_mode,
              flat_dir=flat_dir,
          )
          train_datagen.fit(fit_samples)
          test_datagen.fit(fit_samples)
      return
  
imports: from ..None import utils
  from ..imports import *
  from .preprocessor import ImagePreprocessor
label_desc: Use image node_id 8 for calling a global function with example usage: fit_datagens(train_datagen, test_datagen, train_array, train_directory, target_size, color_mode, flat_dir) without return types