Add docstrings and improve comments (#11229)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
ccfc1cf925
commit
d5458f27cd
16 changed files with 34 additions and 17 deletions
|
|
@ -38,12 +38,14 @@ import torch.nn as nn
|
|||
|
||||
class SPP(nn.Module):
|
||||
def __init__(self):
|
||||
"""Initializes an SPP module with three different sizes of max pooling layers."""
|
||||
super().__init__()
|
||||
self.maxpool1 = nn.MaxPool2d(5, 1, padding=2)
|
||||
self.maxpool2 = nn.MaxPool2d(9, 1, padding=4)
|
||||
self.maxpool3 = nn.MaxPool2d(13, 1, padding=6)
|
||||
|
||||
def forward(self, x):
|
||||
"""Applies three max pooling layers on input `x` and concatenates results along channel dimension."""
|
||||
o1 = self.maxpool1(x)
|
||||
o2 = self.maxpool2(x)
|
||||
o3 = self.maxpool3(x)
|
||||
|
|
@ -52,10 +54,12 @@ class SPP(nn.Module):
|
|||
|
||||
class SPPF(nn.Module):
|
||||
def __init__(self):
|
||||
"""Initializes an SPPF module with a specific configuration of MaxPool2d layer."""
|
||||
super().__init__()
|
||||
self.maxpool = nn.MaxPool2d(5, 1, padding=2)
|
||||
|
||||
def forward(self, x):
|
||||
"""Applies sequential max pooling and concatenates results with input tensor; expects input tensor x of any shape."""
|
||||
o1 = self.maxpool(x)
|
||||
o2 = self.maxpool(o1)
|
||||
o3 = self.maxpool(o2)
|
||||
|
|
@ -63,6 +67,7 @@ class SPPF(nn.Module):
|
|||
|
||||
|
||||
def main():
|
||||
"""Compares outputs and performance of SPP and SPPF on a random tensor (8, 32, 16, 16)."""
|
||||
input_tensor = torch.rand(8, 32, 16, 16)
|
||||
spp = SPP()
|
||||
sppf = SPPF()
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ Fitness is the value we seek to maximize. In YOLOv5 we define a default fitness
|
|||
|
||||
```python
|
||||
def fitness(x):
|
||||
# Model fitness as a weighted combination of metrics
|
||||
"""Evaluates model fitness by summing weighted metrics [P, R, mAP@0.5, mAP@0.5:0.95], x is a numpy array of shape (n, 4)."""
|
||||
w = [0.0, 0.0, 0.1, 0.9] # weights for [P, R, mAP@0.5, mAP@0.5:0.95]
|
||||
return (x[:, :4] * w).sum(1)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ import threading
|
|||
|
||||
|
||||
def run(model, im):
|
||||
"""Performs inference on an image using a given model and saves the output; model must support `.save()` method."""
|
||||
results = model(im)
|
||||
results.save()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue