priority.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. # Copyright (c) Alibaba, Inc. and its affiliates.
  3. from enum import Enum
  4. from typing import Union
  5. class Priority(Enum):
  6. """Hook priority levels.
  7. +--------------+------------+
  8. | Level | Value |
  9. +==============+============+
  10. | HIGHEST | 0 |
  11. +--------------+------------+
  12. | VERY_HIGH | 10 |
  13. +--------------+------------+
  14. | HIGH | 30 |
  15. +--------------+------------+
  16. | ABOVE_NORMAL | 40 |
  17. +--------------+------------+
  18. | NORMAL | 50 |
  19. +--------------+------------+
  20. | BELOW_NORMAL | 60 |
  21. +--------------+------------+
  22. | LOW | 70 |
  23. +--------------+------------+
  24. | VERY_LOW | 90 |
  25. +--------------+------------+
  26. | LOWEST | 100 |
  27. +--------------+------------+
  28. """
  29. HIGHEST = 0
  30. VERY_HIGH = 10
  31. HIGH = 30
  32. ABOVE_NORMAL = 40
  33. NORMAL = 50
  34. BELOW_NORMAL = 60
  35. LOW = 70
  36. VERY_LOW = 90
  37. LOWEST = 100
  38. def get_priority(priority: Union[int, str, Priority]) -> int:
  39. """Get priority value.
  40. Args:
  41. priority (int or str or :obj:`Priority`): Priority.
  42. Returns:
  43. int: The priority value.
  44. """
  45. if isinstance(priority, int):
  46. if priority < 0 or priority > 100:
  47. raise ValueError('priority must be between 0 and 100')
  48. return priority
  49. elif isinstance(priority, Priority):
  50. return priority.value
  51. elif isinstance(priority, str):
  52. return Priority[priority.upper()].value
  53. else:
  54. raise TypeError('priority must be an integer or Priority enum value')