-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ucb-bar/yolo
ADD: add YOLO v8 example
- Loading branch information
Showing
3 changed files
with
380 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,364 @@ | ||
|
||
# YOLO v8 | ||
|
||
|
||
## Model Architecture | ||
|
||
```python | ||
YOLO( | ||
(model): DetectionModel( | ||
(model): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(3, 16, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(16, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(48, 32, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(3): Conv( | ||
(conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(4): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0-1): 2 x Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(5): Conv( | ||
(conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(6): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0-1): 2 x Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(7): Conv( | ||
(conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(8): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(9): SPPF( | ||
(cv1): Conv( | ||
(conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False) | ||
) | ||
(10): Upsample(scale_factor=2.0, mode='nearest') | ||
(11): Concat() | ||
(12): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(384, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(13): Upsample(scale_factor=2.0, mode='nearest') | ||
(14): Concat() | ||
(15): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(96, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(16): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(17): Concat() | ||
(18): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(19): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(20): Concat() | ||
(21): C2f( | ||
(cv1): Conv( | ||
(conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(m): ModuleList( | ||
(0): Bottleneck( | ||
(cv1): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(cv2): Conv( | ||
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
) | ||
) | ||
) | ||
(22): Detect( | ||
(cv2): ModuleList( | ||
(0): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
(1): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
(2): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(256, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
) | ||
(cv3): ModuleList( | ||
(0): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(64, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(80, 80, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
(1): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(128, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(80, 80, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
(2): Sequential( | ||
(0): Conv( | ||
(conv): Conv2d(256, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(1): Conv( | ||
(conv): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) | ||
(bn): BatchNorm2d(80, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) | ||
(act): SiLU(inplace=True) | ||
) | ||
(2): Conv2d(80, 80, kernel_size=(1, 1), stride=(1, 1)) | ||
) | ||
) | ||
(dfl): DFL( | ||
(conv): Conv2d(16, 1, kernel_size=(1, 1), stride=(1, 1), bias=False) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import torch | ||
from ultralytics import YOLO | ||
|
||
# Load a model | ||
model = YOLO("yolov8n.yaml") # build a new model from scratch | ||
model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training) | ||
|
||
breakpoint() | ||
|
||
# Use the model | ||
model.train(data="coco128.yaml", epochs=3) # train the model | ||
metrics = model.val() # evaluate model performance on the validation set | ||
results = model("https://ultralytics.com/images/bus.jpg") # predict on an image | ||
|
||
print(results) |