Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
e545ea9b
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e545ea9b
编写于
4月 19, 2023
作者:
J
Jiageng Zhang
提交者:
A. Unique TensorFlower
4月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 525585347
上级
b2539e5e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
137 addition
and
3 deletion
+137
-3
official/projects/yolo/README.md
official/projects/yolo/README.md
+1
-0
official/projects/yolo/configs/yolov7.py
official/projects/yolo/configs/yolov7.py
+30
-0
official/projects/yolo/modeling/backbones/yolov7.py
official/projects/yolo/modeling/backbones/yolov7.py
+39
-0
official/projects/yolo/modeling/decoders/yolov7.py
official/projects/yolo/modeling/decoders/yolov7.py
+67
-3
未找到文件。
official/projects/yolo/README.md
浏览文件 @
e545ea9b
...
@@ -90,6 +90,7 @@ connected to a new, more powerful backbone if a person chose to.
...
@@ -90,6 +90,7 @@ connected to a new, more powerful backbone if a person chose to.
| Yolo-v4 csp |
| Yolo-v4 csp |
| Yolo-v4 large |
| Yolo-v4 large |
| Yolo-v7 |
| Yolo-v7 |
| Yolo-v7-tiny |
## Requirements
## Requirements
[
![TensorFlow 2.11
](
https://img.shields.io/badge/TensorFlow-2.11-FF6F00?logo=tensorflow
)
](https://github.com/tensorflow/tensorflow/releases/tag/v2.11.0)
[
![TensorFlow 2.11
](
https://img.shields.io/badge/TensorFlow-2.11-FF6F00?logo=tensorflow
)
](https://github.com/tensorflow/tensorflow/releases/tag/v2.11.0)
...
...
official/projects/yolo/configs/yolov7.py
浏览文件 @
e545ea9b
...
@@ -309,3 +309,33 @@ def coco_yolov7() -> cfg.ExperimentConfig:
...
@@ -309,3 +309,33 @@ def coco_yolov7() -> cfg.ExperimentConfig:
)
)
return
config
return
config
@
exp_factory
.
register_config_factory
(
'coco_yolov7tiny'
)
def
coco_yolov7_tiny
()
->
cfg
.
ExperimentConfig
:
"""COCO object detection with YOLOv7-tiny."""
config
=
coco_yolov7
()
config
.
task
.
model
.
input_size
=
[
416
,
416
,
3
]
config
.
task
.
model
.
backbone
.
yolov7
.
model_id
=
'yolov7-tiny'
config
.
task
.
model
.
decoder
.
yolov7
.
model_id
=
'yolov7-tiny'
config
.
task
.
model
.
norm_activation
.
activation
=
'leaky'
config
.
task
.
model
.
anchor_boxes
.
boxes
=
[
Box
(
box
=
[
10
,
13
]),
Box
(
box
=
[
16
,
30
]),
Box
(
box
=
[
33
,
23
]),
Box
(
box
=
[
30
,
61
]),
Box
(
box
=
[
62
,
45
]),
Box
(
box
=
[
59
,
119
]),
Box
(
box
=
[
116
,
90
]),
Box
(
box
=
[
156
,
198
]),
Box
(
box
=
[
373
,
326
]),
]
config
.
task
.
model
.
loss
.
cls_weight
=
0.5
config
.
task
.
model
.
loss
.
obj_weight
=
1.0
config
.
task
.
train_data
.
parser
.
aug_rand_translate
=
0.1
config
.
task
.
train_data
.
parser
.
mosaic
.
mixup_frequency
=
0.05
config
.
task
.
train_data
.
parser
.
mosaic
.
aug_scale_min
=
0.5
config
.
task
.
train_data
.
parser
.
mosaic
.
aug_scale_max
=
1.5
config
.
trainer
.
optimizer_config
.
learning_rate
.
cosine
.
alpha
=
0.01
return
config
official/projects/yolo/modeling/backbones/yolov7.py
浏览文件 @
e545ea9b
...
@@ -68,6 +68,44 @@ _BLOCK_SPEC_SCHEMAS = {
...
@@ -68,6 +68,44 @@ _BLOCK_SPEC_SCHEMAS = {
]
]
}
}
# Define YOLOv7-tiny variant.
_YoloV7Tiny
=
[
[
'convbn'
,
-
1
,
3
,
2
,
32
,
False
],
# 0-P1/2
[
'convbn'
,
-
1
,
3
,
2
,
64
,
False
],
# 1-P2/4
[
'convbn'
,
-
1
,
1
,
1
,
32
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
32
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
# 7
[
'maxpool2d'
,
-
1
,
2
,
2
,
'same'
,
False
],
# 8-P3/8
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
128
,
True
],
# 14
[
'maxpool2d'
,
-
1
,
2
,
2
,
'same'
,
False
],
# 15-P4/16
[
'convbn'
,
-
1
,
1
,
1
,
128
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
128
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
128
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
128
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
256
,
True
],
# 21
[
'maxpool2d'
,
-
1
,
2
,
2
,
'same'
,
False
],
# 22-P5/32
[
'convbn'
,
-
1
,
1
,
1
,
256
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
256
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
256
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
256
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
512
,
True
],
# 28
]
# Define YOLOv7 variant.
# Define YOLOv7 variant.
_YoloV7
=
[
_YoloV7
=
[
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
# 0
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
# 0
...
@@ -133,6 +171,7 @@ _YoloV7 = [
...
@@ -133,6 +171,7 @@ _YoloV7 = [
# Aggregates all variants for YOLOv7 backbones.
# Aggregates all variants for YOLOv7 backbones.
BACKBONES
=
{
BACKBONES
=
{
'yolov7-tiny'
:
_YoloV7Tiny
,
'yolov7'
:
_YoloV7
,
'yolov7'
:
_YoloV7
,
}
}
...
...
official/projects/yolo/modeling/decoders/yolov7.py
浏览文件 @
e545ea9b
...
@@ -91,6 +91,69 @@ _BLOCK_SPEC_SCHEMAS = {
...
@@ -91,6 +91,69 @@ _BLOCK_SPEC_SCHEMAS = {
],
],
}
}
# Define specs for YOLOv7-tiny variant. It is recommended to use together with
# YOLOv7-tiny backbone.
_YoloV7Tiny
=
[
[
'convbn'
,
-
1
,
1
,
1
,
256
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
256
,
False
],
[
'maxpool2d'
,
-
1
,
5
,
1
,
'same'
,
False
],
[
'maxpool2d'
,
-
2
,
9
,
1
,
'same'
,
False
],
[
'maxpool2d'
,
-
3
,
13
,
1
,
'same'
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
256
,
False
],
[
'concat'
,
[
-
1
,
-
7
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
256
,
False
],
# 8
[
'convbn'
,
-
1
,
1
,
1
,
128
,
False
],
[
'upsample2d'
,
-
1
,
2
,
'nearest'
,
False
],
[
'convbn'
,
'4'
,
1
,
1
,
128
,
False
],
# route from backbone P4
[
'concat'
,
[
-
1
,
-
2
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
128
,
False
],
# 18
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
[
'upsample2d'
,
-
1
,
2
,
'nearest'
,
False
],
[
'convbn'
,
'3'
,
1
,
1
,
64
,
False
],
# route from backbone P3
[
'concat'
,
[
-
1
,
-
2
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
32
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
32
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
32
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
# 28
[
'convbn'
,
-
1
,
3
,
2
,
128
,
False
],
[
'concat'
,
[
-
1
,
18
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
64
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
128
,
False
],
# 36
[
'convbn'
,
-
1
,
3
,
2
,
256
,
False
],
[
'concat'
,
[
-
1
,
8
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
128
,
False
],
[
'convbn'
,
-
2
,
1
,
1
,
128
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
128
,
False
],
[
'convbn'
,
-
1
,
3
,
1
,
128
,
False
],
[
'concat'
,
[
-
1
,
-
2
,
-
3
,
-
4
],
-
1
,
False
],
[
'convbn'
,
-
1
,
1
,
1
,
256
,
False
],
# 44
[
'convbn'
,
28
,
1
,
1
,
128
,
True
],
[
'convbn'
,
36
,
1
,
1
,
256
,
True
],
[
'convbn'
,
44
,
1
,
1
,
512
,
True
],
]
# Define specs YOLOv7 variant. The spec schema is defined above.
# Define specs YOLOv7 variant. The spec schema is defined above.
# It is recommended to use together with YOLOv7 backbone.
# It is recommended to use together with YOLOv7 backbone.
_YoloV7
=
[
_YoloV7
=
[
...
@@ -161,6 +224,7 @@ _YoloV7 = [
...
@@ -161,6 +224,7 @@ _YoloV7 = [
# Aggregates all variants for YOLOv7 decoders.
# Aggregates all variants for YOLOv7 decoders.
DECODERS
=
{
DECODERS
=
{
'yolov7-tiny'
:
_YoloV7Tiny
,
'yolov7'
:
_YoloV7
,
'yolov7'
:
_YoloV7
,
}
}
...
@@ -257,13 +321,13 @@ class YoloV7(tf.keras.Model):
...
@@ -257,13 +321,13 @@ class YoloV7(tf.keras.Model):
return
inputs
return
inputs
def
_group_layer_inputs
(
self
,
from_index
,
inputs
,
outputs
):
def
_group_layer_inputs
(
self
,
from_index
,
inputs
,
outputs
):
if
not
outputs
:
return
inputs
[
max
(
inputs
.
keys
())]
if
isinstance
(
from_index
,
list
):
if
isinstance
(
from_index
,
list
):
return
[
self
.
_group_layer_inputs
(
i
,
inputs
,
outputs
)
for
i
in
from_index
]
return
[
self
.
_group_layer_inputs
(
i
,
inputs
,
outputs
)
for
i
in
from_index
]
if
isinstance
(
from_index
,
int
):
if
isinstance
(
from_index
,
int
):
# Need last layer output from backbone.
if
len
(
outputs
)
+
from_index
==
-
1
:
return
inputs
[
max
(
inputs
.
keys
())]
return
outputs
[
from_index
]
return
outputs
[
from_index
]
return
inputs
[
from_index
]
# from_index is a string.
return
inputs
[
from_index
]
# from_index is a string.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录