Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the SPPF code slightly to run tiny bit faster #12830

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
20f58e3
Updated the SPPF code slightly to run tiny bit faster
chinya07 Mar 20, 2024
e9a8cad
Merge branch 'master' into master
glenn-jocher Apr 9, 2024
b987b0f
Merge branch 'master' into master
UltralyticsAssistant Apr 14, 2024
038e78a
Merge branch 'master' into master
UltralyticsAssistant Apr 18, 2024
c74431b
Merge branch 'master' into master
UltralyticsAssistant Apr 27, 2024
e29923d
Merge branch 'master' into master
UltralyticsAssistant Apr 28, 2024
5e198de
Auto-format by https://ultralytics.com/actions
UltralyticsAssistant Apr 28, 2024
254ccb5
Merge branch 'master' into master
UltralyticsAssistant May 5, 2024
e30affd
Merge branch 'master' into master
UltralyticsAssistant May 12, 2024
ec5e391
Merge branch 'master' into master
UltralyticsAssistant May 12, 2024
ed7bf61
Merge branch 'master' into master
UltralyticsAssistant May 12, 2024
b2ec0a4
Merge branch 'master' into master
UltralyticsAssistant May 12, 2024
f6bcb34
Merge branch 'master' into master
UltralyticsAssistant May 13, 2024
20748f7
Merge branch 'master' into master
UltralyticsAssistant May 18, 2024
e33ba6a
Merge branch 'master' into master
UltralyticsAssistant May 24, 2024
555fa5a
Merge branch 'master' into master
UltralyticsAssistant May 28, 2024
63a0a72
Merge branch 'master' into master
UltralyticsAssistant May 29, 2024
b310bc3
Merge branch 'master' into master
UltralyticsAssistant May 29, 2024
0d8997a
Merge branch 'master' into master
UltralyticsAssistant May 30, 2024
c550871
Merge branch 'master' into master
UltralyticsAssistant Jun 8, 2024
af64781
Merge branch 'master' into master
UltralyticsAssistant Jun 8, 2024
2a77d77
Merge branch 'master' into master
UltralyticsAssistant Jun 9, 2024
6c10700
Merge branch 'master' into master
UltralyticsAssistant Jun 16, 2024
a374120
Merge branch 'master' into master
UltralyticsAssistant Jun 16, 2024
a27fc69
Merge branch 'master' into master
UltralyticsAssistant Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,33 @@ def forward(self, x):


class SPPF(nn.Module):
# Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
def __init__(self, c1, c2, k=5):
# Spatial Pyramid Pooling - Fast (SPPF) layer, optimized with an iterative loop
def __init__(self, c1, c2, k=5, levels=3):
"""
Initializes YOLOv5 SPPF layer with given channels and kernel size for YOLOv5 model, combining convolution and
max pooling.
Initializes YOLOv5 Optimized SPPF layer with given channels and kernel size for YOLOv5 model,
combining convolution and max pooling with an iterative loop.

Equivalent to SPP(k=(5, 9, 13)).
param levels: Number of max pooling levels.
"""
super().__init__()
c_ = c1 // 2 # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(c_ * 4, c2, 1, 1)
self.cv2 = Conv(c_ * (levels + 1), c2, 1, 1)
self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
self.levels = levels

def forward(self, x):
"""Processes input through a series of convolutions and max pooling operations for feature extraction."""
"""Processes input through a series of convolutions and iterative max pooling operations for feature extraction."""
x = self.cv1(x)
outputs = [x]
with warnings.catch_warnings():
warnings.simplefilter("ignore") # suppress torch 1.9.0 max_pool2d() warning
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat((x, y1, y2, self.m(y2)), 1))


for _ in range(self.levels):
x = self.m(x)
outputs.append(x)
return self.cv2(torch.cat(outputs, 1))


class Focus(nn.Module):
# Focus wh information into c-space
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):
Expand Down