code: def run(
      self,
      pure=True,
      restore=False,
      test=False,
      valid=False,
      valid_size=-1,
  ):
      if not restore:
          _clear_files = ["logs", "checkpoint", "snapshot", "output"]
          for file in _clear_files:
              subprocess.run(
                  ["rm", "-rf", os.path.join(self.expdir, file)]
              )
      init = self.load_init()
      dataset = "C10+" if init is None else init.get("dataset", "C10+")
      run_config = self.load_run_config(
          print_info=(not pure), dataset=dataset
      )
      run_config.renew_logs = False
      if valid_size > 0:
          run_config.validation_size = valid_size
  
      data_provider = get_data_provider_by_name(
          run_config.dataset, run_config.get_config()
      )
      net_config, model_name = self.load_net_config(
          init, print_info=(not pure)
      )
      model = get_model_by_name(model_name)(
          self.expdir, data_provider, run_config, net_config, pure=pure
      )
      start_epoch = 1
      if restore:
          model.load_model()
          epoch_info_file = "%s/checkpoint/epoch.info" % self.expdir
          if os.path.isfile(epoch_info_file):
              start_epoch = json.load(open(epoch_info_file, "r"))[
                  "epoch"
              ]
              if not pure:
                  print("start epoch: %d" % start_epoch)
      if test:
          print("Testing...")
          loss, accuracy = model.test(
              data_provider.test, batch_size=200
          )
          print(
              "mean cross_entropy: %f, mean accuracy: %f"
              % (loss, accuracy)
          )
          json.dump(
              {"test_loss": "%s" % loss, "test_acc": "%s" % accuracy},
              open(self.output, "w"),
          )
      elif valid:
          print("validating...")
          loss, accuracy = model.test(
              data_provider.validation, batch_size=200
          )
          print(
              "mean cross_entropy: %f, mean accuracy: %f"
              % (loss, accuracy)
          )
          json.dump(
              {"valid_loss": "%s" % loss, "valid_acc": "%s" % accuracy},
              open(self.output, "w"),
          )
      elif pure:
          model.pure_train()
          loss, accuracy = model.test(
              data_provider.validation, batch_size=200
          )
          json.dump(
              {"valid_loss": "%s" % loss, "valid_acc": "%s" % accuracy},
              open(self.output, "w"),
          )
          model.save_init(self.snapshot, print_info=(not pure))
          model.save_config(self.expdir, print_info=(not pure))
      else:
          # train the model
          print(
              "Data provider train images: ",
              data_provider.train.num_examples,
          )
          model.train_all_epochs(start_epoch)
          print(
              "Data provider test images: ",
              data_provider.test.num_examples,
          )
          print("Testing...")
          loss, accuracy = model.test(
              data_provider.test, batch_size=200
          )
          print(
              "mean cross_entropy: %f, mean accuracy: %f"
              % (loss, accuracy)
          )
          json.dump(
              {"test_loss": "%s" % loss, "test_acc": "%s" % accuracy},
              open(self.output, "w"),
          )
          model.save_init(self.snapshot, print_info=(not pure))
          model.save_config(self.expdir, print_info=(not pure))
      return accuracy
  
file_path: auptimizer/src/aup/Proposer/eas/expdir_monitor/expdir_monitor.py
imports: import json
  import os
  import subprocess
  from ..models.utils import RunConfig, get_model_config_by_name, get_model_by_name
  from ..data_providers.utils import get_data_provider_by_name
  import pickle
label_desc: Use image node_id 12 for calling the ExpdirMonitor obj's underlying member method code with example usage: obj.run(pure, restore, test, valid, valid_size) and returns: accuracy