tensorboard.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # ### OUR CODE ###
  2. import os.path as osp
  3. import tensorboardX
  4. # create a new class inheriting from tensorboardX.SummaryWriter
  5. class SummaryWriter(tensorboardX.SummaryWriter):
  6. def __init__(self, log_dir=None, comment="", **kwargs):
  7. super().__init__(log_dir, comment, **kwargs)
  8. # create a new function that will take dictionary as input and uses built-in add_scalar() function
  9. # that function combines all plots into one subgroup by a tag
  10. def add_scalar_dict(self, dictionary, global_step, tag=None):
  11. for name, val in dictionary.items():
  12. if tag is not None:
  13. name = osp.join(tag, name)
  14. self.add_scalar(name, val.item(), global_step)
  15. # COCO labels mapping
  16. COCO_INSTANCE_CATEGORY_NAMES = [
  17. "__background__",
  18. "person",
  19. "bicycle",
  20. "car",
  21. "motorcycle",
  22. "airplane",
  23. "bus",
  24. "train",
  25. "truck",
  26. "boat",
  27. "traffic light",
  28. "fire hydrant",
  29. "N/A",
  30. "stop sign",
  31. "parking meter",
  32. "bench",
  33. "bird",
  34. "cat",
  35. "dog",
  36. "horse",
  37. "sheep",
  38. "cow",
  39. "elephant",
  40. "bear",
  41. "zebra",
  42. "giraffe",
  43. "N/A",
  44. "backpack",
  45. "umbrella",
  46. "N/A",
  47. "N/A",
  48. "handbag",
  49. "tie",
  50. "suitcase",
  51. "frisbee",
  52. "skis",
  53. "snowboard",
  54. "sports ball",
  55. "kite",
  56. "baseball bat",
  57. "baseball glove",
  58. "skateboard",
  59. "surfboard",
  60. "tennis racket",
  61. "bottle",
  62. "N/A",
  63. "wine glass",
  64. "cup",
  65. "fork",
  66. "knife",
  67. "spoon",
  68. "bowl",
  69. "banana",
  70. "apple",
  71. "sandwich",
  72. "orange",
  73. "broccoli",
  74. "carrot",
  75. "hot dog",
  76. "pizza",
  77. "donut",
  78. "cake",
  79. "chair",
  80. "couch",
  81. "potted plant",
  82. "bed",
  83. "N/A",
  84. "dining table",
  85. "N/A",
  86. "N/A",
  87. "toilet",
  88. "N/A",
  89. "tv",
  90. "laptop",
  91. "mouse",
  92. "remote",
  93. "keyboard",
  94. "cell phone",
  95. "microwave",
  96. "oven",
  97. "toaster",
  98. "sink",
  99. "refrigerator",
  100. "N/A",
  101. "book",
  102. "clock",
  103. "vase",
  104. "scissors",
  105. "teddy bear",
  106. "hair drier",
  107. "toothbrush",
  108. ]
  109. # define variables as globals to have an access everywhere
  110. args = None # will be replaced to argparse dictionary
  111. total_epochs = 0 # init total number of epochs
  112. global_iter = 0 # init total number of iterations
  113. name = "exp-000" # init experiment name
  114. log_dir = "experiments" # init path where tensorboard logs will be stored
  115. # (if log_dir is not specified writer object will automatically generate filename)
  116. # Log files will be saved in 'experiments/exp-000'
  117. # create our custom logger
  118. logger = SummaryWriter(log_dir=osp.join(log_dir, name))
  119. # ### END OF OUR CODE ###