code: def build_train_valid_datasets(
      model_cfg,
      consumed_samples,
  ):
      data_cfg = model_cfg.data
  
      # This function maps data that are tuples to dictionary.
      def tuple_to_dict(inp):
          for input in inp:
              out_dict = dict()
              out_dict["images"] = input[0].permute(1, 2, 0)
              out_dict["captions"] = input[1]
              out_dict["hint"] = input[2].permute(1, 2, 0)
              yield out_dict
  
      def transform_fn(sample):
          image, text, hint = (
              sample["jpg"],
              sample["txt"],
              sample["png"],
          )
          # TODO : If no agumentations just return the image ?
          img_transform = construct_image_augmentations(
              data_cfg.train.get("augmentations", None)
          )
          text_transform = identical_transform
          return (
              img_transform(image),
              text_transform(text),
              img_transform(hint),
          )
  
      if data_cfg.get("synthetic_data", False):
          H, W = data_cfg.train.augmentations.center_crop_h_w.split(",")
          train_data = ControlNetSyntheticDataset(
              int(H),
              int(W),
              image_key=model_cfg.first_stage_key,
              txt_key=model_cfg.cond_stage_key,
              control_key=model_cfg.control_key,
              context_dim=model_cfg.unet_config.context_dim,
              fake_len=data_cfg.synthetic_data_length,
          )
      else:
          train_data = WebDatasetCommon(
              dataset_cfg=data_cfg,
              consumed_samples=consumed_samples,
              map_fn=transform_fn,
              compose_fn=tuple_to_dict,
              is_train=True,
          )
  
      val_data = None
      if data_cfg.get(
          "validation"
      ) is not None and data_cfg.validation.get("data_path"):
          val_data = WebDatasetCommon(
              dataset_cfg=data_cfg,
              consumed_samples=consumed_samples,
              map_fn=transform_fn,
              compose_fn=tuple_to_dict,
              is_train=False,
          )
      return train_data, val_data
  
file_path: NeMo/nemo/collections/multimodal/data/controlnet/controlnet_dataset.py
imports: import torch
  from nemo.collections.multimodal.data.common.webdataset import WebDatasetCommon
  from nemo.collections.multimodal.data.stable_diffusion.augmentation.augmentations import construct_image_augmentations, identical_transform
  from nemo.core.classes import Dataset
label_desc: Use image node_id 1 for calling a global function with example usage: build_train_valid_datasets(model_cfg, consumed_samples) and returns: train_data,  val_data, img_transform,  text_transform,  img_transform