code: def load_scene_directory(
      scene_dir, target_size, layers=DEFAULT_LAYERS
  ):
      scene_dir = as_path(scene_dir)
      example_key = f"{scene_dir.name}"
  
      with tf.io.gfile.GFile(
          str(scene_dir / "data_ranges.json"), "r"
      ) as fp:
          data_ranges = json.load(fp)
  
      with tf.io.gfile.GFile(
          str(scene_dir / "metadata.json"), "r"
      ) as fp:
          metadata = json.load(fp)
  
      with tf.io.gfile.GFile(str(scene_dir / "events.json"), "r") as fp:
          events = json.load(fp)
  
      num_frames = metadata["metadata"]["num_frames"]
  
      result = {
          "metadata": {
              "video_name": example_key,
              "width": target_size[1],
              "height": target_size[0],
              "num_frames": num_frames,
              "num_instances": metadata["metadata"]["num_instances"],
          },
          "instances": [
              format_instance_information(obj)
              for obj in metadata["instances"]
          ],
          "camera": format_camera_information(metadata),
          "events": format_events_information(events),
      }
  
      resolution = metadata["metadata"]["resolution"]
  
      assert (
          resolution[1] / target_size[0]
          == resolution[0] / target_size[1]
      )
      scale = resolution[1] / target_size[0]
      assert scale == resolution[1] // target_size[0]
  
      paths = {
          key: [
              scene_dir / f"{key}_{f:05d}.png"
              for f in range(num_frames)
          ]
          for key in layers
          if key != "depth"
      }
  
      if "depth" in layers:
          depth_paths = [
              scene_dir / f"depth_{f:05d}.tiff"
              for f in range(num_frames)
          ]
          depth_frames = np.array(
              [
                  subsample_nearest_neighbor(
                      read_tiff(frame_path), target_size
                  )
                  for frame_path in depth_paths
              ]
          )
          depth_min, depth_max = np.min(depth_frames), np.max(
              depth_frames
          )
          result["depth"] = convert_float_to_uint16(
              depth_frames, depth_min, depth_max
          )
          result["metadata"]["depth_range"] = [depth_min, depth_max]
  
      if "forward_flow" in layers:
          result["metadata"]["forward_flow_range"] = [
              data_ranges["forward_flow"]["min"] / scale,
              data_ranges["forward_flow"]["max"] / scale,
          ]
          result["forward_flow"] = [
              subsample_nearest_neighbor(
                  read_png(frame_path)[..., :2], target_size
              )
              for frame_path in paths["forward_flow"]
          ]
  
      if "backward_flow" in layers:
          result["metadata"]["backward_flow_range"] = [
              data_ranges["backward_flow"]["min"] / scale,
              data_ranges["backward_flow"]["max"] / scale,
          ]
          result["backward_flow"] = [
              subsample_nearest_neighbor(
                  read_png(frame_path)[..., :2], target_size
              )
              for frame_path in paths["backward_flow"]
          ]
  
      for key in ["normal", "object_coordinates", "uv"]:
          if key in layers:
              result[key] = [
                  subsample_nearest_neighbor(
                      read_png(frame_path), target_size
                  )
                  for frame_path in paths[key]
              ]
  
      if "segmentation" in layers:
          # somehow we ended up calling this "segmentations" in TFDS and
          # "segmentation" in kubric. So we have to treat it separately.
          result["segmentations"] = [
              subsample_nearest_neighbor(
                  read_png(frame_path), target_size
              )
              for frame_path in paths["segmentation"]
          ]
  
      if "rgba" in layers:
          result["video"] = [
              subsample_avg(read_png(frame_path), target_size)[..., :3]
              for frame_path in paths["rgba"]
          ]
  
      return example_key, result, metadata
  
imports: import dataclasses
  import json
  import logging
  import imageio
  import numpy
  import png
  import tensorflow
  import tensorflow_datasets.public_api
  from typing import List, Dict, Union
label_desc: Use image node_id 1 for calling a global function with example usage: load_scene_directory(scene_dir, target_size, layers) and returns: example_key,  result,  metadata