code: def save_best(best_model_dir, metrics_data, iter):
      with open(
          os.path.join(best_model_dir, "best_metrics.txt"), "w"
      ) as f:
          for key, value in metrics_data.items():
              line = key + " " + str(value) + "\n"
              f.write(line)
          f.write("iter" + " " + str(iter) + "\n")
  
file_path: PaddleSeg/Matting/ppmatting/core/train.py
imports: import os
  import time
  from collections import deque, defaultdict
  import pickle
  import shutil
  import numpy
  import paddle
  import paddle.nn.functional
  from paddleseg.utils import TimeAverager, calculate_eta, resume, logger, train_profiler
  from .val import evaluate
label_desc: Use image node_id 2 for calling a global function with example usage: save_best(best_model_dir, metrics_data, iter) without return types