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.

yolox_x_mot17_half.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # encoding: utf-8
  2. import os
  3. import random
  4. import torch
  5. import torch.nn as nn
  6. import torch.distributed as dist
  7. from yolox.exp import Exp as MyExp
  8. from yolox.data import get_yolox_datadir
  9. class Exp(MyExp):
  10. def __init__(self):
  11. super(Exp, self).__init__()
  12. self.num_classes = 1
  13. self.depth = 1.33
  14. self.width = 1.25
  15. self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
  16. self.train_ann = "train.json"
  17. self.val_ann = "val_half.json"
  18. self.input_size = (800, 1440)
  19. self.test_size = (800, 1440)
  20. self.random_size = (18, 32)
  21. self.max_epoch = 80
  22. self.print_interval = 20
  23. self.eval_interval = 5
  24. self.test_conf = 0.1
  25. self.nmsthre = 0.7
  26. self.no_aug_epochs = 10
  27. self.basic_lr_per_img = 0.001 / 64.0
  28. self.warmup_epochs = 1
  29. def get_data_loader(self, batch_size, is_distributed, no_aug=False):
  30. from yolox.data import (
  31. MOTDataset,
  32. TrainTransform,
  33. YoloBatchSampler,
  34. DataLoader,
  35. InfiniteSampler,
  36. MosaicDetection,
  37. )
  38. dataset = MOTDataset(
  39. data_dir=os.path.join(get_yolox_datadir(), "MOT17"),
  40. json_file=self.train_ann,
  41. name='train',
  42. img_size=self.input_size,
  43. preproc=TrainTransform(
  44. rgb_means=(0.485, 0.456, 0.406),
  45. std=(0.229, 0.224, 0.225),
  46. max_labels=500,
  47. ),
  48. )
  49. dataset = MosaicDetection(
  50. dataset,
  51. mosaic=not no_aug,
  52. img_size=self.input_size,
  53. preproc=TrainTransform(
  54. rgb_means=(0.485, 0.456, 0.406),
  55. std=(0.229, 0.224, 0.225),
  56. max_labels=1000,
  57. ),
  58. degrees=self.degrees,
  59. translate=self.translate,
  60. scale=self.scale,
  61. shear=self.shear,
  62. perspective=self.perspective,
  63. enable_mixup=self.enable_mixup,
  64. )
  65. self.dataset = dataset
  66. if is_distributed:
  67. batch_size = batch_size // dist.get_world_size()
  68. sampler = InfiniteSampler(
  69. len(self.dataset), seed=self.seed if self.seed else 0
  70. )
  71. batch_sampler = YoloBatchSampler(
  72. sampler=sampler,
  73. batch_size=batch_size,
  74. drop_last=False,
  75. input_dimension=self.input_size,
  76. mosaic=not no_aug,
  77. )
  78. dataloader_kwargs = {"num_workers": self.data_num_workers, "pin_memory": True}
  79. dataloader_kwargs["batch_sampler"] = batch_sampler
  80. train_loader = DataLoader(self.dataset, **dataloader_kwargs)
  81. return train_loader
  82. def get_eval_loader(self, batch_size, is_distributed, testdev=False):
  83. from yolox.data import MOTDataset, ValTransform
  84. valdataset = MOTDataset(
  85. data_dir=os.path.join(get_yolox_datadir(), "MOT17"),
  86. json_file=self.val_ann,
  87. img_size=self.test_size,
  88. name='train',
  89. preproc=ValTransform(
  90. rgb_means=(0.485, 0.456, 0.406),
  91. std=(0.229, 0.224, 0.225),
  92. ),
  93. )
  94. if is_distributed:
  95. batch_size = batch_size // dist.get_world_size()
  96. sampler = torch.utils.data.distributed.DistributedSampler(
  97. valdataset, shuffle=False
  98. )
  99. else:
  100. sampler = torch.utils.data.SequentialSampler(valdataset)
  101. dataloader_kwargs = {
  102. "num_workers": self.data_num_workers,
  103. "pin_memory": True,
  104. "sampler": sampler,
  105. }
  106. dataloader_kwargs["batch_size"] = batch_size
  107. val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs)
  108. return val_loader
  109. def get_evaluator(self, batch_size, is_distributed, testdev=False):
  110. from yolox.evaluators import COCOEvaluator
  111. val_loader = self.get_eval_loader(batch_size, is_distributed, testdev=testdev)
  112. evaluator = COCOEvaluator(
  113. dataloader=val_loader,
  114. img_size=self.test_size,
  115. confthre=self.test_conf,
  116. nmsthre=self.nmsthre,
  117. num_classes=self.num_classes,
  118. testdev=testdev,
  119. )
  120. return evaluator