code: def additional_augmentations(
      ds_factory,
      augmentation_params,
      crop_size,
      num_frames,
      zero_centering,
      rgb_feature_name=None,
  ):
      """Apply additional data augmentations in the DMVR pre-processsing graph."""
  
      if not rgb_feature_name:
          rgb_feature_name = builders.IMAGE_FEATURE_NAME
  
      do_simclr_crop_resize = augmentation_params.get(
          "do_simclr_crop_resize", False
      )
      do_simclr_style_augmentations = augmentation_params.get(
          "do_simclr_style_augmentations", False
      )
      do_rand_augment = augmentation_params.get(
          "do_rand_augment", False
      )
      do_color_augment = augmentation_params.get(
          "do_color_augment", False
      )
      do_jitter_scale = augmentation_params.get(
          "do_jitter_scale", False
      )
      do_random_erasing = augmentation_params.get(
          "do_random_erasing", False
      )
  
      if do_simclr_crop_resize and do_jitter_scale:
          logging.warning(
              "Only doing simclr_crop_resize."
              "Not compatible with jitter_scale"
          )
  
      if do_simclr_crop_resize:
          area_range = (
              augmentation_params.get("simclr_area_lower_bound", 0.5),
              1,
          )
          aspect_ratio = augmentation_params.get(
              "aspect_ratio_crop", (0.5, 2.0)
          )
  
          # Remove resize_smallest and Replace random_crop with crop_resize
          ds_factory.preprocessor_builder.remove_fn(
              f"{rgb_feature_name}_resize_smallest"
          )
          # To replace random_crop with the crop_resize we need to find out which
          # function comes next, as not all datasets have the same list of
          # preprocessing functions (e.g. SSv2 doesn't have a random_flip)
          randcrop_fn_name = f"{rgb_feature_name}_random_crop"
          fns_list = ds_factory.preprocessor_builder.get_summary()
          idx = [
              i
              for i, fd in enumerate(fns_list)
              if fd.fn_name == randcrop_fn_name
          ]
          if not idx:
              raise ValueError(
                  f"No {randcrop_fn_name} in Preprocessing Builder."
              )
          next_fn_name = fns_list[idx[0] + 1].fn_name
          ds_factory.preprocessor_builder.remove_fn(randcrop_fn_name)
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  crop_resize,
                  num_frames=num_frames,
                  output_h=crop_size,
                  output_w=crop_size,
                  num_channels=3,
                  area_range=area_range,
                  aspect_ratio=aspect_ratio,
              ),
              feature_name=rgb_feature_name,
              fn_name=f"{rgb_feature_name}_crop_resize",
              add_before_fn_name=next_fn_name,
          )
  
      elif do_jitter_scale:
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  dmvr_processors.scale_jitter_augm,
                  min_scale_factor=augmentation_params.scale_min_factor,
                  max_scale_factor=augmentation_params.scale_max_factor,
                  prob=augmentation_params.prob_scale_jitter,
              ),
              feature_name=rgb_feature_name,
              fn_name=f"{rgb_feature_name}_jitter_scale",
              add_before_fn_name=f"{rgb_feature_name}_random_crop",
          )
  
      if do_simclr_style_augmentations and do_color_augment:
          logging.warning(
              "Only doing simclr_style_augmentations as it includes"
              "color augmentations"
          )
  
      if (
          sum(
              [
                  do_rand_augment,
                  do_simclr_style_augmentations,
                  do_color_augment,
              ]
          )
          > 1
      ):
          logging.warning(
              "Priority for different augmentation functions is:"
              "1) rand_augment. 2) simclr_style_augment."
              "3) colour_augment. Only one is performed."
          )
  
      if do_rand_augment:
          logging.info("Adding rand_augment")
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  distort_image_with_randaugment,
                  num_layers=augmentation_params.rand_augment_num_layers,
                  magnitude=augmentation_params.rand_augment_magnitude,
              ),
              feature_name=rgb_feature_name,
              fn_name=f"{rgb_feature_name}_rand_augment",
              add_before_fn_name=f"{rgb_feature_name}_normalize",
          )
      elif do_simclr_style_augmentations:
          # Add additional augmentations at the end
          logging.info("Adding simclr_style augmentation")
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  simclr_style_augmentation,
                  height=crop_size,
                  width=crop_size,
                  zero_centre=zero_centering,
              ),
              rgb_feature_name,
          )
      elif do_color_augment:
          logging.info("Adding color_augment")
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  dmvr_processors.color_default_augm,
                  zero_centering_image=zero_centering,
                  prob_color_augment=augmentation_params.prob_color_augment,
                  prob_color_drop=augmentation_params.prob_color_drop,
              ),
              rgb_feature_name,
          )
  
      if do_random_erasing:
          logging.info("Adding random erasing")
          random_erasing_prob = augmentation_params.get(
              "random_erasing_prob", 0.25
          )
          ds_factory.preprocessor_builder.add_fn(
              functools.partial(
                  random_erasing, probability=random_erasing_prob
              ),
              rgb_feature_name,
          )
  
      return ds_factory
  
imports: import functools
  import math
  from typing import Optional
  from absl import logging
  from dmvr import builders
  from dmvr import processors
  import simclr.tf2.data_util
  import tensorflow
  from official.vision.image_classification import augment
label_desc: Use image node_id 12 for calling a global function with example usage: additional_augmentations(ds_factory, augmentation_params, crop_size, num_frames, zero_centering, rgb_feature_name) and returns: ds_factory