Skip to content

Commit 92c7e65

Browse files
authored
Add files via upload
Signed-off-by: Bubbles The Dev <[email protected]>
1 parent feaa396 commit 92c7e65

37 files changed

+4370
-0
lines changed

butter-scotch-cookies.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# engine
2+
3+
python .\export.py --weights ./"your_model_path.pt" --include engine --half --imgsz 320 320 --device 0
4+
5+
6+
# onnx
7+
8+
python .\export.py --weights ./"your_model_path.pt" --include onnx --half --imgsz 320 320 --device 0

export.py

Lines changed: 863 additions & 0 deletions
Large diffs are not rendered by default.

models/__init__.py

Whitespace-only changes.

models/common.py

Lines changed: 883 additions & 0 deletions
Large diffs are not rendered by default.

models/experimental.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
"""
3+
Experimental modules
4+
"""
5+
import math
6+
7+
import numpy as np
8+
import torch
9+
import torch.nn as nn
10+
11+
from utils.downloads import attempt_download
12+
13+
14+
class Sum(nn.Module):
15+
# Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070
16+
def __init__(self, n, weight=False): # n: number of inputs
17+
super().__init__()
18+
self.weight = weight # apply weights boolean
19+
self.iter = range(n - 1) # iter object
20+
if weight:
21+
self.w = nn.Parameter(-torch.arange(1.0, n) / 2, requires_grad=True) # layer weights
22+
23+
def forward(self, x):
24+
y = x[0] # no weight
25+
if self.weight:
26+
w = torch.sigmoid(self.w) * 2
27+
for i in self.iter:
28+
y = y + x[i + 1] * w[i]
29+
else:
30+
for i in self.iter:
31+
y = y + x[i + 1]
32+
return y
33+
34+
35+
class MixConv2d(nn.Module):
36+
# Mixed Depth-wise Conv https://arxiv.org/abs/1907.09595
37+
def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True): # ch_in, ch_out, kernel, stride, ch_strategy
38+
super().__init__()
39+
n = len(k) # number of convolutions
40+
if equal_ch: # equal c_ per group
41+
i = torch.linspace(0, n - 1E-6, c2).floor() # c2 indices
42+
c_ = [(i == g).sum() for g in range(n)] # intermediate channels
43+
else: # equal weight.numel() per group
44+
b = [c2] + [0] * n
45+
a = np.eye(n + 1, n, k=-1)
46+
a -= np.roll(a, 1, axis=1)
47+
a *= np.array(k) ** 2
48+
a[0] = 1
49+
c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b
50+
51+
self.m = nn.ModuleList([
52+
nn.Conv2d(c1, int(c_), k, s, k // 2, groups=math.gcd(c1, int(c_)), bias=False) for k, c_ in zip(k, c_)])
53+
self.bn = nn.BatchNorm2d(c2)
54+
self.act = nn.SiLU()
55+
56+
def forward(self, x):
57+
return self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))
58+
59+
60+
class Ensemble(nn.ModuleList):
61+
# Ensemble of models
62+
def __init__(self):
63+
super().__init__()
64+
65+
def forward(self, x, augment=False, profile=False, visualize=False):
66+
y = [module(x, augment, profile, visualize)[0] for module in self]
67+
# y = torch.stack(y).max(0)[0] # max ensemble
68+
# y = torch.stack(y).mean(0) # mean ensemble
69+
y = torch.cat(y, 1) # nms ensemble
70+
return y, None # inference, train output
71+
72+
73+
def attempt_load(weights, device=None, inplace=True, fuse=True):
74+
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
75+
from models.yolo import Detect, Model
76+
77+
model = Ensemble()
78+
for w in weights if isinstance(weights, list) else [weights]:
79+
ckpt = torch.load(attempt_download(w), map_location='cpu') # load
80+
ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model
81+
82+
# Model compatibility updates
83+
if not hasattr(ckpt, 'stride'):
84+
ckpt.stride = torch.tensor([32.])
85+
if hasattr(ckpt, 'names') and isinstance(ckpt.names, (list, tuple)):
86+
ckpt.names = dict(enumerate(ckpt.names)) # convert to dict
87+
88+
model.append(ckpt.fuse().eval() if fuse and hasattr(ckpt, 'fuse') else ckpt.eval()) # model in eval mode
89+
90+
# Module updates
91+
for m in model.modules():
92+
t = type(m)
93+
if t in (nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model):
94+
m.inplace = inplace
95+
if t is Detect and not isinstance(m.anchor_grid, list):
96+
delattr(m, 'anchor_grid')
97+
setattr(m, 'anchor_grid', [torch.zeros(1)] * m.nl)
98+
elif t is nn.Upsample and not hasattr(m, 'recompute_scale_factor'):
99+
m.recompute_scale_factor = None # torch 1.11.0 compatibility
100+
101+
# Return model
102+
if len(model) == 1:
103+
return model[-1]
104+
105+
# Return detection ensemble
106+
print(f'Ensemble created with {weights}\n')
107+
for k in 'names', 'nc', 'yaml':
108+
setattr(model, k, getattr(model[0], k))
109+
model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride
110+
assert all(model[0].nc == m.nc for m in model), f'Models have different class counts: {[m.nc for m in model]}'
111+
return model

models/hub/anchors.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
# Default anchors for COCO data
3+
4+
5+
# P5 -------------------------------------------------------------------------------------------------------------------
6+
# P5-640:
7+
anchors_p5_640:
8+
- [10,13, 16,30, 33,23] # P3/8
9+
- [30,61, 62,45, 59,119] # P4/16
10+
- [116,90, 156,198, 373,326] # P5/32
11+
12+
13+
# P6 -------------------------------------------------------------------------------------------------------------------
14+
# P6-640: thr=0.25: 0.9964 BPR, 5.54 anchors past thr, n=12, img_size=640, metric_all=0.281/0.716-mean/best, past_thr=0.469-mean: 9,11, 21,19, 17,41, 43,32, 39,70, 86,64, 65,131, 134,130, 120,265, 282,180, 247,354, 512,387
15+
anchors_p6_640:
16+
- [9,11, 21,19, 17,41] # P3/8
17+
- [43,32, 39,70, 86,64] # P4/16
18+
- [65,131, 134,130, 120,265] # P5/32
19+
- [282,180, 247,354, 512,387] # P6/64
20+
21+
# P6-1280: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792
22+
anchors_p6_1280:
23+
- [19,27, 44,40, 38,94] # P3/8
24+
- [96,68, 86,152, 180,137] # P4/16
25+
- [140,301, 303,264, 238,542] # P5/32
26+
- [436,615, 739,380, 925,792] # P6/64
27+
28+
# P6-1920: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1920, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 28,41, 67,59, 57,141, 144,103, 129,227, 270,205, 209,452, 455,396, 358,812, 653,922, 1109,570, 1387,1187
29+
anchors_p6_1920:
30+
- [28,41, 67,59, 57,141] # P3/8
31+
- [144,103, 129,227, 270,205] # P4/16
32+
- [209,452, 455,396, 358,812] # P5/32
33+
- [653,922, 1109,570, 1387,1187] # P6/64
34+
35+
36+
# P7 -------------------------------------------------------------------------------------------------------------------
37+
# P7-640: thr=0.25: 0.9962 BPR, 6.76 anchors past thr, n=15, img_size=640, metric_all=0.275/0.733-mean/best, past_thr=0.466-mean: 11,11, 13,30, 29,20, 30,46, 61,38, 39,92, 78,80, 146,66, 79,163, 149,150, 321,143, 157,303, 257,402, 359,290, 524,372
38+
anchors_p7_640:
39+
- [11,11, 13,30, 29,20] # P3/8
40+
- [30,46, 61,38, 39,92] # P4/16
41+
- [78,80, 146,66, 79,163] # P5/32
42+
- [149,150, 321,143, 157,303] # P6/64
43+
- [257,402, 359,290, 524,372] # P7/128
44+
45+
# P7-1280: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1280, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 19,22, 54,36, 32,77, 70,83, 138,71, 75,173, 165,159, 148,334, 375,151, 334,317, 251,626, 499,474, 750,326, 534,814, 1079,818
46+
anchors_p7_1280:
47+
- [19,22, 54,36, 32,77] # P3/8
48+
- [70,83, 138,71, 75,173] # P4/16
49+
- [165,159, 148,334, 375,151] # P5/32
50+
- [334,317, 251,626, 499,474] # P6/64
51+
- [750,326, 534,814, 1079,818] # P7/128
52+
53+
# P7-1920: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1920, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 29,34, 81,55, 47,115, 105,124, 207,107, 113,259, 247,238, 222,500, 563,227, 501,476, 376,939, 749,711, 1126,489, 801,1222, 1618,1227
54+
anchors_p7_1920:
55+
- [29,34, 81,55, 47,115] # P3/8
56+
- [105,124, 207,107, 113,259] # P4/16
57+
- [247,238, 222,500, 563,227] # P5/32
58+
- [501,476, 376,939, 749,711] # P6/64
59+
- [1126,489, 801,1222, 1618,1227] # P7/128

models/hub/yolov3-spp.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
3+
# Parameters
4+
nc: 80 # number of classes
5+
depth_multiple: 1.0 # model depth multiple
6+
width_multiple: 1.0 # layer channel multiple
7+
anchors:
8+
- [10,13, 16,30, 33,23] # P3/8
9+
- [30,61, 62,45, 59,119] # P4/16
10+
- [116,90, 156,198, 373,326] # P5/32
11+
12+
# darknet53 backbone
13+
backbone:
14+
# [from, number, module, args]
15+
[[-1, 1, Conv, [32, 3, 1]], # 0
16+
[-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17+
[-1, 1, Bottleneck, [64]],
18+
[-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19+
[-1, 2, Bottleneck, [128]],
20+
[-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21+
[-1, 8, Bottleneck, [256]],
22+
[-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23+
[-1, 8, Bottleneck, [512]],
24+
[-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25+
[-1, 4, Bottleneck, [1024]], # 10
26+
]
27+
28+
# YOLOv3-SPP head
29+
head:
30+
[[-1, 1, Bottleneck, [1024, False]],
31+
[-1, 1, SPP, [512, [5, 9, 13]]],
32+
[-1, 1, Conv, [1024, 3, 1]],
33+
[-1, 1, Conv, [512, 1, 1]],
34+
[-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
35+
36+
[-2, 1, Conv, [256, 1, 1]],
37+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
38+
[[-1, 8], 1, Concat, [1]], # cat backbone P4
39+
[-1, 1, Bottleneck, [512, False]],
40+
[-1, 1, Bottleneck, [512, False]],
41+
[-1, 1, Conv, [256, 1, 1]],
42+
[-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
43+
44+
[-2, 1, Conv, [128, 1, 1]],
45+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
46+
[[-1, 6], 1, Concat, [1]], # cat backbone P3
47+
[-1, 1, Bottleneck, [256, False]],
48+
[-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
49+
50+
[[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
51+
]

models/hub/yolov3-tiny.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
3+
# Parameters
4+
nc: 80 # number of classes
5+
depth_multiple: 1.0 # model depth multiple
6+
width_multiple: 1.0 # layer channel multiple
7+
anchors:
8+
- [10,14, 23,27, 37,58] # P4/16
9+
- [81,82, 135,169, 344,319] # P5/32
10+
11+
# YOLOv3-tiny backbone
12+
backbone:
13+
# [from, number, module, args]
14+
[[-1, 1, Conv, [16, 3, 1]], # 0
15+
[-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2
16+
[-1, 1, Conv, [32, 3, 1]],
17+
[-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4
18+
[-1, 1, Conv, [64, 3, 1]],
19+
[-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8
20+
[-1, 1, Conv, [128, 3, 1]],
21+
[-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16
22+
[-1, 1, Conv, [256, 3, 1]],
23+
[-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32
24+
[-1, 1, Conv, [512, 3, 1]],
25+
[-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11
26+
[-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12
27+
]
28+
29+
# YOLOv3-tiny head
30+
head:
31+
[[-1, 1, Conv, [1024, 3, 1]],
32+
[-1, 1, Conv, [256, 1, 1]],
33+
[-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large)
34+
35+
[-2, 1, Conv, [128, 1, 1]],
36+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
37+
[[-1, 8], 1, Concat, [1]], # cat backbone P4
38+
[-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium)
39+
40+
[[19, 15], 1, Detect, [nc, anchors]], # Detect(P4, P5)
41+
]

models/hub/yolov3.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
3+
# Parameters
4+
nc: 80 # number of classes
5+
depth_multiple: 1.0 # model depth multiple
6+
width_multiple: 1.0 # layer channel multiple
7+
anchors:
8+
- [10,13, 16,30, 33,23] # P3/8
9+
- [30,61, 62,45, 59,119] # P4/16
10+
- [116,90, 156,198, 373,326] # P5/32
11+
12+
# darknet53 backbone
13+
backbone:
14+
# [from, number, module, args]
15+
[[-1, 1, Conv, [32, 3, 1]], # 0
16+
[-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17+
[-1, 1, Bottleneck, [64]],
18+
[-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19+
[-1, 2, Bottleneck, [128]],
20+
[-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21+
[-1, 8, Bottleneck, [256]],
22+
[-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23+
[-1, 8, Bottleneck, [512]],
24+
[-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25+
[-1, 4, Bottleneck, [1024]], # 10
26+
]
27+
28+
# YOLOv3 head
29+
head:
30+
[[-1, 1, Bottleneck, [1024, False]],
31+
[-1, 1, Conv, [512, 1, 1]],
32+
[-1, 1, Conv, [1024, 3, 1]],
33+
[-1, 1, Conv, [512, 1, 1]],
34+
[-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
35+
36+
[-2, 1, Conv, [256, 1, 1]],
37+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
38+
[[-1, 8], 1, Concat, [1]], # cat backbone P4
39+
[-1, 1, Bottleneck, [512, False]],
40+
[-1, 1, Bottleneck, [512, False]],
41+
[-1, 1, Conv, [256, 1, 1]],
42+
[-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
43+
44+
[-2, 1, Conv, [128, 1, 1]],
45+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
46+
[[-1, 6], 1, Concat, [1]], # cat backbone P3
47+
[-1, 1, Bottleneck, [256, False]],
48+
[-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
49+
50+
[[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
51+
]

models/hub/yolov5-bifpn.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2+
3+
# Parameters
4+
nc: 80 # number of classes
5+
depth_multiple: 1.0 # model depth multiple
6+
width_multiple: 1.0 # layer channel multiple
7+
anchors:
8+
- [10,13, 16,30, 33,23] # P3/8
9+
- [30,61, 62,45, 59,119] # P4/16
10+
- [116,90, 156,198, 373,326] # P5/32
11+
12+
# YOLOv5 v6.0 backbone
13+
backbone:
14+
# [from, number, module, args]
15+
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16+
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17+
[-1, 3, C3, [128]],
18+
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19+
[-1, 6, C3, [256]],
20+
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21+
[-1, 9, C3, [512]],
22+
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23+
[-1, 3, C3, [1024]],
24+
[-1, 1, SPPF, [1024, 5]], # 9
25+
]
26+
27+
# YOLOv5 v6.0 BiFPN head
28+
head:
29+
[[-1, 1, Conv, [512, 1, 1]],
30+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
31+
[[-1, 6], 1, Concat, [1]], # cat backbone P4
32+
[-1, 3, C3, [512, False]], # 13
33+
34+
[-1, 1, Conv, [256, 1, 1]],
35+
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
36+
[[-1, 4], 1, Concat, [1]], # cat backbone P3
37+
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
38+
39+
[-1, 1, Conv, [256, 3, 2]],
40+
[[-1, 14, 6], 1, Concat, [1]], # cat P4 <--- BiFPN change
41+
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42+
43+
[-1, 1, Conv, [512, 3, 2]],
44+
[[-1, 10], 1, Concat, [1]], # cat head P5
45+
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46+
47+
[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48+
]

0 commit comments

Comments
 (0)