code: def write_metrics(data_loader, command_args, metrics, output_file):
      print(metrics)
      assert "tput_images_per_s" in metrics
      row = {key: val for key, val in metrics.items() if key in FIELDS}
      row["data_loader"] = data_loader
      for field in FIELDS:
          val = getattr(command_args, field, None)
          if val is not None:
              row[field] = val
  
      for field in FIELDS:
          print(f"{field}: {row[field]}")
  
      write_header = not os.path.exists(output_file)
      with open(output_file, "a+", newline="") as csvfile:
          writer = csv.DictWriter(csvfile, fieldnames=FIELDS)
          if write_header:
              writer.writeheader()
          writer.writerow(row)
  
      test_output_json_envvar = "TEST_OUTPUT_JSON"
      test_output_json_path = os.environ.get(test_output_json_envvar)
      if not test_output_json_path:
          print(
              "Env var {env_var} not set, will not write test output json.".format(
                  env_var=test_output_json_envvar
              )
          )
      else:
          print(
              "Env var {env_var} set to '{path}'. Will write test output json.".format(
                  env_var=test_output_json_envvar,
                  path=test_output_json_path,
              )
          )
          append_to_test_output_json(test_output_json_path, row)
  
imports: from collections import defaultdict
  import tensorflow
  import numpy
  import os
  import pandas
  import time
  import logging
  import csv
  import json
  import torchvision
  import torch
  import ray
  from ray.train.tensorflow import prepare_dataset_shard, TensorflowTrainer
  from ray.train import DataConfig, ScalingConfig
  from ray import train, tune
  from ray.tune import Tuner
  from ray.data.datasource.partitioning import Partitioning
  from tf_utils import DEFAULT_IMAGE_SIZE, NUM_CHANNELS, preprocess_image, build_tf_dataset
  from metric_utils import determine_if_memory_monitor_is_enabled_in_latest_session, get_ray_spilled_and_restored_mb, MaxMemoryUtilizationTracker
label_desc: Use image node_id 10 for calling a global function with example usage: write_metrics(data_loader, command_args, metrics, output_file) without return types