experiment.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ''' Incremental-Classifier Learning
  2. Authors : Khurram Javed, Muhammad Talha Paracha
  3. Maintainer : Khurram Javed
  4. Lab : TUKL-SEECS R&D Lab
  5. Email : 14besekjaved@seecs.edu.pk '''
  6. import json
  7. import os
  8. import subprocess
  9. class experiment:
  10. '''
  11. Class to store results of any experiment
  12. '''
  13. def __init__(self, name, args, output_dir="../"):
  14. self.gitHash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode("utf-8")
  15. print(self.gitHash)
  16. if not args is None:
  17. self.name = name
  18. self.params = vars(args)
  19. self.results = {}
  20. self.dir = output_dir
  21. import datetime
  22. now = datetime.datetime.now()
  23. rootFolder = str(now.day) + str(now.month) + str(now.year)
  24. if not os.path.exists(output_dir + rootFolder):
  25. os.makedirs(output_dir + rootFolder)
  26. self.name = rootFolder + "/" + self.name
  27. ver = 0
  28. while os.path.exists(output_dir + self.name + "_" + str(ver)):
  29. ver += 1
  30. os.makedirs(output_dir + self.name + "_" + str(ver))
  31. self.path = output_dir + self.name + "_" + str(ver) + "/" + name
  32. self.results["Temp Results"] = [[1, 2, 3, 4], [5, 6, 2, 6]]
  33. def store_json(self):
  34. with open(self.path + "JSONDump.txt", 'w') as outfile:
  35. json.dump(json.dumps(self.__dict__), outfile)
  36. import argparse
  37. if __name__ == "__main__":
  38. parser = argparse.ArgumentParser(description='iCarl2.0')
  39. args = parser.parse_args()
  40. e = experiment("TestExperiment", args)
  41. e.store_json()