Meta Byte Track
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  4. import importlib
  5. import os
  6. import sys
  7. def get_exp_by_file(exp_file):
  8. try:
  9. sys.path.append(os.path.dirname(exp_file))
  10. current_exp = importlib.import_module(os.path.basename(exp_file).split(".")[0])
  11. exp = current_exp.Exp()
  12. except Exception:
  13. raise ImportError("{} doesn't contains class named 'Exp'".format(exp_file))
  14. return exp
  15. def get_exp_by_name(exp_name):
  16. import yolox
  17. yolox_path = os.path.dirname(os.path.dirname(yolox.__file__))
  18. filedict = {
  19. "yolox-s": "yolox_s.py",
  20. "yolox-m": "yolox_m.py",
  21. "yolox-l": "yolox_l.py",
  22. "yolox-x": "yolox_x.py",
  23. "yolox-tiny": "yolox_tiny.py",
  24. "yolox-nano": "nano.py",
  25. "yolov3": "yolov3.py",
  26. }
  27. filename = filedict[exp_name]
  28. exp_path = os.path.join(yolox_path, "exps", "default", filename)
  29. return get_exp_by_file(exp_path)
  30. def get_exp(exp_file, exp_name):
  31. """
  32. get Exp object by file or name. If exp_file and exp_name
  33. are both provided, get Exp by exp_file.
  34. Args:
  35. exp_file (str): file path of experiment.
  36. exp_name (str): name of experiment. "yolo-s",
  37. """
  38. assert (
  39. exp_file is not None or exp_name is not None
  40. ), "plz provide exp file or exp name."
  41. if exp_file is not None:
  42. return get_exp_by_file(exp_file)
  43. else:
  44. return get_exp_by_name(exp_name)