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.

nano.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. # Copyright (c) Megvii, Inc. and its affiliates.
  4. import os
  5. import torch.nn as nn
  6. from yolox.exp import Exp as MyExp
  7. class Exp(MyExp):
  8. def __init__(self):
  9. super(Exp, self).__init__()
  10. self.depth = 0.33
  11. self.width = 0.25
  12. self.scale = (0.5, 1.5)
  13. self.random_size = (10, 20)
  14. self.test_size = (416, 416)
  15. self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
  16. self.enable_mixup = False
  17. def get_model(self, sublinear=False):
  18. def init_yolo(M):
  19. for m in M.modules():
  20. if isinstance(m, nn.BatchNorm2d):
  21. m.eps = 1e-3
  22. m.momentum = 0.03
  23. if "model" not in self.__dict__:
  24. from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
  25. in_channels = [256, 512, 1024]
  26. # NANO model use depthwise = True, which is main difference.
  27. backbone = YOLOPAFPN(self.depth, self.width, in_channels=in_channels, depthwise=True)
  28. head = YOLOXHead(self.num_classes, self.width, in_channels=in_channels, depthwise=True)
  29. self.model = YOLOX(backbone, head)
  30. self.model.apply(init_yolo)
  31. self.model.head.initialize_biases(1e-2)
  32. return self.model