code: def convert_imagenet_to_tf_records(
      raw_data_dir: str, output_dir: str
  ) -> Tuple[List[str], List[str]]:
      """Converts the Imagenet dataset into TF-Record dumps."""
  
      # Shuffle training records to ensure we are distributing classes
      # across the batches.
      random.seed(0)
  
      def make_shuffle_idx(n):
          order = list(range(n))
          random.shuffle(order)
          return order
  
      # Glob all the training files
      training_files = tf.gfile.Glob(
          os.path.join(raw_data_dir, TRAINING_DIRECTORY, "*", "*.JPEG")
      )
  
      # Get training file synset labels from the directory name
      training_synsets = [
          os.path.basename(os.path.dirname(f)) for f in training_files
      ]
      training_synsets = list(
          map(lambda x: bytes(x, "utf-8"), training_synsets)
      )
  
      training_shuffle_idx = make_shuffle_idx(len(training_files))
      training_files = [training_files[i] for i in training_shuffle_idx]
      training_synsets = [
          training_synsets[i] for i in training_shuffle_idx
      ]
  
      # Glob all the validation files
      validation_files = sorted(
          tf.gfile.Glob(
              os.path.join(raw_data_dir, VALIDATION_DIRECTORY, "*.JPEG")
          )
      )
  
      # Get validation file synset labels from labels.txt
      validation_synsets = (
          tf.gfile.FastGFile(
              os.path.join(raw_data_dir, VALIDATION_LABELS), "rb"
          )
          .read()
          .splitlines()
      )
  
      # Create unique ids for all synsets
      labels = {
          v: k + 1
          for k, v in enumerate(
              sorted(set(validation_synsets + training_synsets))
          )
      }
  
      # Create training data
      print("Processing the training data.")
      _process_dataset(
          training_files,
          training_synsets,
          labels,
          os.path.join(output_dir, TRAINING_DIRECTORY),
          TRAINING_DIRECTORY,
          TRAINING_SHARDS,
      )
  
      # Create validation data
      print("Processing the validation data.")
      _process_dataset(
          validation_files,
          validation_synsets,
          labels,
          os.path.join(output_dir, VALIDATION_DIRECTORY),
          VALIDATION_DIRECTORY,
          VALIDATION_SHARDS,
      )
  
imports: from datetime import datetime
  import math
  import os
  import random
  from typing import Iterable, List, Mapping, Union, Tuple
  import sys
  import threading
  import numpy
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: convert_imagenet_to_tf_records(raw_data_dir, output_dir) and returns: order