code: def _generate_data():
      """Generate random data for testing the Sun397 dataset builder."""
  
      names_file = tfds.core.tfds_path(
          os.path.join("image", "sun397_labels.txt")
      )
      label_names = tfds.features.ClassLabel(
          names_file=names_file
      ).names
  
      def _generate_image_to_tar(image_format, channels, tar):
          """Generate a random image and add it to the given tar file."""
          label = random.choice(label_names)
          image = _get_random_picture(channels=channels)
          # Regardless of the actual format, always write with .jpg extension.
          fobj = tempfile.NamedTemporaryFile(
              delete=False, suffix=".jpg"
          )
          _encode_image(image, image_format, fobj=fobj)
          filename = "SUN397/%s/sun_%s.jpg" % (
              label,
              md5.new(fobj.read()).hexdigest(),
          )
          fobj.seek(0)
          fobj.close()
          tar.add(fobj.name, arcname=filename)
  
      tar = tarfile.open(
          os.path.join(_output_dir(), "SUN397.tar.gz"), mode="w:gz"
      )
      _generate_image_to_tar(image_format="JPEG", channels=1, tar=tar)
      _generate_image_to_tar(image_format="JPEG", channels=3, tar=tar)
      _generate_image_to_tar(image_format="GIF", channels=3, tar=tar)
      _generate_image_to_tar(image_format="BMP", channels=1, tar=tar)
      _generate_image_to_tar(image_format="BMP", channels=3, tar=tar)
      _generate_image_to_tar(image_format="PNG", channels=1, tar=tar)
      _generate_image_to_tar(image_format="PNG", channels=3, tar=tar)
      _generate_image_to_tar(image_format="PNG", channels=4, tar=tar)
      tar.close()
  
file_path: datasets/tensorflow_datasets/testing/fake_data_generation/sun397.py
imports: import io
  import os
  import random
  import tarfile
  import tempfile
  from absl import app
  from absl import flags
  import md5
  import numpy
  from tensorflow_datasets.core import utils
  import tensorflow_datasets.public_api
label_desc: Use image node_id 4 for calling a global function with example usage: _generate_data() without return types