Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

yolox_nano.py 1.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  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.input_size = (416, 416)
  13. self.random_size = (10, 20)
  14. self.mosaic_scale = (0.5, 1.5)
  15. self.test_size = (416, 416)
  16. self.mosaic_prob = 0.5
  17. self.enable_mixup = False
  18. self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
  19. def get_model(self, sublinear=False):
  20. def init_yolo(M):
  21. for m in M.modules():
  22. if isinstance(m, nn.BatchNorm2d):
  23. m.eps = 1e-3
  24. m.momentum = 0.03
  25. if "model" not in self.__dict__:
  26. from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
  27. in_channels = [256, 512, 1024]
  28. # NANO model use depthwise = True, which is main difference.
  29. backbone = YOLOPAFPN(
  30. self.depth, self.width, in_channels=in_channels,
  31. act=self.act, depthwise=True,
  32. )
  33. head = YOLOXHead(
  34. self.num_classes, self.width, in_channels=in_channels,
  35. act=self.act, depthwise=True
  36. )
  37. self.model = YOLOX(backbone, head)
  38. self.model.apply(init_yolo)
  39. self.model.head.initialize_biases(1e-2)
  40. return self.model
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...