Skip to content

Commit

Permalink
Merge branch 'main' of github.com:iMoonLab/Hyper-YOLO
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanfeng97 committed Aug 5, 2024
2 parents 2545645 + d2f06eb commit 82e9da5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ultralytics/cfg/models/hyper-yolo/hyper-yolo-seg.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
# Hyper-YOLO object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# Hyper-YOLO object detection model with N3-N5 outputs.

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=hyper-yolon.yaml' will call hyper-yolo.yaml with scale 'n'
scales: # model compound scaling constants, i.e. 'model=hyper-yolon-seg.yaml' will call hyper-yolo-seg.yaml with scale 'n'
# [depth, width, max_channels, threshold]
n: [0.33, 0.25, 1024, 6]
s: [0.33, 0.50, 1024, 9]
Expand Down
8 changes: 4 additions & 4 deletions ultralytics/cfg/models/hyper-yolo/hyper-yolo.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
# Hyper-YOLO object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# Hyper-YOLO object detection model with N3-N5 outputs.

# Parameters
nc: 80 # number of classes
Expand Down Expand Up @@ -44,14 +44,14 @@ head:

- [17, 1, nn.Upsample, [None, 2, 'nearest']] # 23
- [[-1, 4], 1, Concat, [1]] # cat 24
- [-1, 3, MANet, [256, False, 2, 3]] # 25 P3
- [-1, 3, MANet, [256, False, 2, 3]] # 25 N3

- [-1, 1, Conv, [256, 3, 2]] # 26
- [[-1, 22], 1, Concat, [1]] # 27 cat head
- [-1, 3, MANet, [512, False, 2, 3]] # 28
- [-1, 3, MANet, [512, False, 2, 3]] # 28 N4

- [-1, 1, Conv, [512, 3, 2]] # 29
- [[-1, 20], 1, Concat, [1]] # 30 cat head P5
- [-1, 3, C2f, [1024, False]] # 31
- [-1, 3, C2f, [1024, False]] # 31 N5

- [[25, 28, 31], 1, Detect, [nc]] # Detect(N3, N4, N5)
52 changes: 52 additions & 0 deletions ultralytics/cfg/models/hyper-yolo/hyper-yolot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# HyperYOLO object detection model with N3-N5 outputs.

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants,
# [depth, width, max_channels, threshold]
t: [0.33, 0.25, 1024, 6]

# backbone
backbone:
- [-1, 1, Conv, [64, 3, 2]] # 0-B1/2
- [-1, 1, Conv, [128, 3, 2]] # 1
- [-1, 3, C2f, [128, True]] # 2-B2/4
- [-1, 1, Conv, [256, 3, 2]] # 3
- [-1, 6, MANet, [256, True, 1, 3]] # 4-B3/8
- [-1, 1, Conv, [512, 3, 2]] # 5
- [-1, 6, MANet, [512, True, 1, 3]] # 6-B4/16
- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
- [-1, 3, C2f, [1024, True]] # 8
- [-1, 1, SPPF, [1024, 5]] # 9-B5/32

# head
head:
- [0, 1, nn.AvgPool2d, [8, 8, 0]] # 10
- [2, 1, nn.AvgPool2d, [4, 4, 0]] # 11
- [4, 1, nn.AvgPool2d, [2, 2, 0]] # 12
- [9, 1, nn.Upsample, [None, 2, 'nearest']] # 13
- [[10, 11, 12, 6, 13], 1, Concat, [1]] # cat 14
- [-1, 1, Conv, [512, 1, 1]] # 15
- [-1, 1, HyperComputeModule, [512]] # 16
- [-1, 3, MANet, [512, True]] # 17

- [-1, 1, nn.AvgPool2d, [2, 2, 0]] # 18
- [[-1, 9], 1, Concat, [1]] # cat 19
- [-1, 1, Conv, [1024, 1, 1]] # 20

- [[17, 6], 1, Concat, [1]] # cat 21
- [-1, 3, C2f, [512, False]] # 22

- [17, 1, nn.Upsample, [None, 2, 'nearest']] # 23
- [[-1, 4], 1, Concat, [1]] # cat 24
- [-1, 3, C2f, [256, False]] # 25

- [-1, 1, Conv, [256, 3, 2]] # 26
- [[-1, 22], 1, Concat, [1]] # 27 cat
- [-1, 3, C2f, [512, False]] # 28

- [-1, 1, Conv, [512, 3, 2]] # 29
- [[-1, 20], 1, Concat, [1]] # 30 cat
- [-1, 1, Conv, [1024, 1, 1]] # 31

- [[25, 28, 31], 1, Detect, [nc]] # Detect(N3, N4, N5)
5 changes: 3 additions & 2 deletions ultralytics/nn/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ def yaml_model_load(path):

unified_path = re.sub(r'(\d+)([nslmx])(.+)?$', r'\1\3', str(path)) # i.e. yolov8x.yaml -> yolov8.yaml
unified_path = re.sub(r'(hyper-yolo)([nslmx])(.+)?$', r'\1\3', str(unified_path))
unified_path = re.sub(r'(hyper-yolot)(.+)?$', r'\1\2', str(unified_path))

yaml_file = check_yaml(unified_path, hard=False) or check_yaml(path)
d = yaml_load(yaml_file) # model dict
Expand All @@ -769,8 +770,8 @@ def guess_model_scale(model_path):
"""
with contextlib.suppress(AttributeError):
import re
if re.search(r'(hyper-yolo)([nslmx])', Path(model_path).stem) is not None:
return re.search(r'(hyper-yolo)([nslmx])', Path(model_path).stem).group(2)
if re.search(r'(hyper-yolo)([tnslmx])', Path(model_path).stem) is not None:
return re.search(r'(hyper-yolo)([tnslmx])', Path(model_path).stem).group(2)
else:
return re.search(r'yolov\d+([nslmx])', Path(model_path).stem).group(1) # n, s, m, l, or x
return ''
Expand Down

0 comments on commit 82e9da5

Please sign in to comment.