code: def write_csv(datas, args):
      num = 0
      fail_num = 0
      none_exist_num = 0
      fail = []
      none_exist = []
      latest_time = 0
      with open("scripts/labels_names.json") as f:
          label = json.load(f)
      for dataset in sorted(os.listdir(datas)):
          print(f"\ndataset={dataset}, index={num}")
          num += 1
          with open(
              os.path.join(
                  datas, dataset, "train/_annotations.coco.json"
              ),
              "r",
          ) as f:
              image = json.load(f)
              num_train = len(
                  image["images"]
              )  # get number of train images
          with open(
              os.path.join(
                  datas, dataset, "valid/_annotations.coco.json"
              ),
              "r",
          ) as f:
              image = json.load(f)
              num_valid = len(
                  image["images"]
              )  # get number of valid images
          for index in label:
              if index["name"] == dataset:
                  category = index[
                      "category"
                  ]  # get category of dataset
                  class_num = len(index["classes"].keys())
  
          # determine whether the dataset directory exists
          try:
              dirs = [
                  os.path.join(args.work_dirs, dataset, d)
                  for d in os.listdir(
                      os.path.join(args.work_dirs, dataset)
                  )
                  if os.path.isdir(
                      os.path.join(args.work_dirs, dataset, d)
                  )
              ]
              dirs.sort(key=os.path.getmtime)
  
              latest_dir = dirs[-1]
              latest_log_name = latest_dir.split("/")[-1]
              if int(latest_log_name) > int(latest_time):
                  latest_time = latest_log_name
              print("time=" + latest_log_name)
              latest_log = latest_dir + f"/{latest_log_name}.log"
              with open(latest_log, "r") as f:
                  log = f.read()
              print(latest_log)
  
              complete_flag = re.findall(
                  r"Epoch\(val\) \[{}\]\[\d+/\d+\]".format(args.epoch),
                  log,
              )  # find log of args.epoch's validating process
  
              # Check whether the training is complete
              if not complete_flag:
                  fail_num += 1
                  fail.append(dataset)
                  print("-------------------------------------")
                  print(f"{dataset} train failed!")
                  print(f"{fail_num} dataset failed!")
                  print("-------------------------------------")
                  key_value = [
                      dataset,
                      category,
                      class_num,
                      num_train,
                      num_valid,
                      "",
                      "",
                      "",
                      "",
                      "",
                  ]
              else:
                  """match result."""
                  match_all = re.findall(
                      r"The best checkpoint with ([\d.]+) "
                      r"coco/bbox_mAP at ([\d.]+) epoch",
                      log,
                  )
                  if match_all:
                      match = match_all[-1]
                      best_epoch = match[-1]
                      print(f"best_epoch={best_epoch}")
                      # find best result
                      match_AP = re.findall(
                          r"\[{}\]\[\d+/\d+\]    coco/bbox_mAP: (-?\d+\.?\d*)  coco/bbox_mAP_50: (-?\d+\.?\d*)  coco/bbox_mAP_75: -?\d+\.?\d*  coco/bbox_mAP_s: (-?\d+\.?\d*)  coco/bbox_mAP_m: (-?\d+\.?\d*)  coco/bbox_mAP_l: (-?\d+\.?\d*)".format(  # noqa
                              best_epoch
                          ),
                          log,
                      )
                      print(f"match_AP={match_AP}")
  
                      key_value = [
                          dataset,
                          category,
                          class_num,
                          num_train,
                          num_valid,
                      ]
                      key_value.extend(match_AP[0])
                  else:
                      print(
                          "----------------- --------------------------"
                      )
                      print("log has no result!")
                      print(
                          "----------------------------------------------"
                      )
                      key_value = [
                          dataset,
                          category,
                          class_num,
                          num_train,
                          num_valid,
                          "",
                          "",
                          "",
                          "",
                          "",
                      ]
          except RuntimeError:
              print(f"{dataset} directory doesn't exist!")
              none_exist_num += 1
              none_exist.append(dataset)
              key_value = [
                  dataset,
                  category,
                  num_train,
                  num_valid,
                  "",
                  "",
                  "",
                  "",
                  "",
              ]
  
          if num == 1:  # generate headers
              result_csv = os.path.join(
                  args.work_dirs, f"{latest_log_name}_eval.csv"
              )
              print(result_csv)
              with open(result_csv, mode="w") as f:
                  writer = csv.writer(f)
                  header1 = [
                      "Dataset",
                      "Category",
                      "Classes",
                      "Images",
                      "Images",
                      args.method,
                      args.method,
                      args.method,
                      args.method,
                      args.method,
                  ]
                  writer.writerow(header1)
              with open(result_csv, mode="a") as f:
                  writer = csv.writer(f)
                  header2 = [
                      "Dataset",
                      "Category",
                      "Classes",
                      "train",
                      "valid",
                      "mAP",
                      "mAP50",
                      "mAP_s",
                      "mAP_m",
                      "mAP_l",
                  ]
                  writer.writerow(header2)
                  writer.writerow(key_value)
  
          else:
              with open(result_csv, mode="a") as f:
                  writer = csv.writer(f)
                  writer.writerow(key_value)
  
      return (
          result_csv,
          fail,
          fail_num,
          none_exist,
          none_exist_num,
          os.path.join(args.work_dirs, latest_time[4:]),
      )
  
file_path: mmdetection/projects/RF100-Benchmark/scripts/log_extract.py
imports: import argparse
  import csv
  import json
  import os
  import re
  import numpy
  import pandas
  from openpyxl import load_workbook
  from openpyxl.styles import Alignment
label_desc: Use image node_id 2 for calling a global function with example usage: write_csv(datas, args) and returns: result_csv,  fail,  fail_num,  none_exist,  none_exist_num,  os