Spaces:
Build error
Build error
commit
Browse files- yolov6/models/efficientrep.py +102 -0
yolov6/models/efficientrep.py
CHANGED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from torch import nn
|
2 |
+
from yolov6.layers.common import RepVGGBlock, RepBlock, SimSPPF
|
3 |
+
|
4 |
+
|
5 |
+
class EfficientRep(nn.Module):
|
6 |
+
'''EfficientRep Backbone
|
7 |
+
EfficientRep is handcrafted by hardware-aware neural network design.
|
8 |
+
With rep-style struct, EfficientRep is friendly to high-computation hardware(e.g. GPU).
|
9 |
+
'''
|
10 |
+
|
11 |
+
def __init__(
|
12 |
+
self,
|
13 |
+
in_channels=3,
|
14 |
+
channels_list=None,
|
15 |
+
num_repeats=None,
|
16 |
+
):
|
17 |
+
super().__init__()
|
18 |
+
|
19 |
+
assert channels_list is not None
|
20 |
+
assert num_repeats is not None
|
21 |
+
|
22 |
+
self.stem = RepVGGBlock(
|
23 |
+
in_channels=in_channels,
|
24 |
+
out_channels=channels_list[0],
|
25 |
+
kernel_size=3,
|
26 |
+
stride=2
|
27 |
+
)
|
28 |
+
|
29 |
+
self.ERBlock_2 = nn.Sequential(
|
30 |
+
RepVGGBlock(
|
31 |
+
in_channels=channels_list[0],
|
32 |
+
out_channels=channels_list[1],
|
33 |
+
kernel_size=3,
|
34 |
+
stride=2
|
35 |
+
),
|
36 |
+
RepBlock(
|
37 |
+
in_channels=channels_list[1],
|
38 |
+
out_channels=channels_list[1],
|
39 |
+
n=num_repeats[1]
|
40 |
+
)
|
41 |
+
)
|
42 |
+
|
43 |
+
self.ERBlock_3 = nn.Sequential(
|
44 |
+
RepVGGBlock(
|
45 |
+
in_channels=channels_list[1],
|
46 |
+
out_channels=channels_list[2],
|
47 |
+
kernel_size=3,
|
48 |
+
stride=2
|
49 |
+
),
|
50 |
+
RepBlock(
|
51 |
+
in_channels=channels_list[2],
|
52 |
+
out_channels=channels_list[2],
|
53 |
+
n=num_repeats[2]
|
54 |
+
)
|
55 |
+
)
|
56 |
+
|
57 |
+
self.ERBlock_4 = nn.Sequential(
|
58 |
+
RepVGGBlock(
|
59 |
+
in_channels=channels_list[2],
|
60 |
+
out_channels=channels_list[3],
|
61 |
+
kernel_size=3,
|
62 |
+
stride=2
|
63 |
+
),
|
64 |
+
RepBlock(
|
65 |
+
in_channels=channels_list[3],
|
66 |
+
out_channels=channels_list[3],
|
67 |
+
n=num_repeats[3]
|
68 |
+
)
|
69 |
+
)
|
70 |
+
|
71 |
+
self.ERBlock_5 = nn.Sequential(
|
72 |
+
RepVGGBlock(
|
73 |
+
in_channels=channels_list[3],
|
74 |
+
out_channels=channels_list[4],
|
75 |
+
kernel_size=3,
|
76 |
+
stride=2,
|
77 |
+
),
|
78 |
+
RepBlock(
|
79 |
+
in_channels=channels_list[4],
|
80 |
+
out_channels=channels_list[4],
|
81 |
+
n=num_repeats[4]
|
82 |
+
),
|
83 |
+
SimSPPF(
|
84 |
+
in_channels=channels_list[4],
|
85 |
+
out_channels=channels_list[4],
|
86 |
+
kernel_size=5
|
87 |
+
)
|
88 |
+
)
|
89 |
+
|
90 |
+
def forward(self, x):
|
91 |
+
|
92 |
+
outputs = []
|
93 |
+
x = self.stem(x)
|
94 |
+
x = self.ERBlock_2(x)
|
95 |
+
x = self.ERBlock_3(x)
|
96 |
+
outputs.append(x)
|
97 |
+
x = self.ERBlock_4(x)
|
98 |
+
outputs.append(x)
|
99 |
+
x = self.ERBlock_5(x)
|
100 |
+
outputs.append(x)
|
101 |
+
|
102 |
+
return tuple(outputs)
|