Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈小光丶
yolov4-keras
提交
26308267
Y
yolov4-keras
项目概览
陈小光丶
/
yolov4-keras
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolov4-keras
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
26308267
编写于
2月 07, 2021
作者:
B
Bubbliiiing
提交者:
GitHub
2月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add files via upload
上级
479cf43e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
28 deletion
+50
-28
FPS_test.py
FPS_test.py
+8
-8
get_dr_txt.py
get_dr_txt.py
+6
-7
nets/yolo4.py
nets/yolo4.py
+21
-4
yolo.py
yolo.py
+15
-9
未找到文件。
FPS_test.py
浏览文件 @
26308267
...
...
@@ -17,20 +17,21 @@ video.py里面测试的FPS会低于该FPS,因为摄像头的读取频率有限
'''
class
FPS_YOLO
(
YOLO
):
def
get_FPS
(
self
,
image
,
test_interval
):
# 调整图片使其符合输入要求
new_image_size
=
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
])
boxed_image
=
letterbox_image
(
image
,
new_image_size
)
if
self
.
letterbox_image
:
boxed_image
=
letterbox_image
(
image
,
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]))
else
:
boxed_image
=
image
.
convert
(
'RGB'
)
boxed_image
=
boxed_image
.
resize
((
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]),
Image
.
BICUBIC
)
image_data
=
np
.
array
(
boxed_image
,
dtype
=
'float32'
)
image_data
/=
255.
image_data
=
np
.
expand_dims
(
image_data
,
0
)
image_data
=
np
.
expand_dims
(
image_data
,
0
)
out_boxes
,
out_scores
,
out_classes
=
self
.
sess
.
run
(
[
self
.
boxes
,
self
.
scores
,
self
.
classes
],
feed_dict
=
{
self
.
yolo_model
.
input
:
image_data
,
self
.
input_image_shape
:
[
image
.
size
[
1
],
image
.
size
[
0
]],
K
.
learning_phase
():
0
})
K
.
learning_phase
():
0
})
t1
=
time
.
time
()
for
_
in
range
(
test_interval
):
...
...
@@ -39,8 +40,7 @@ class FPS_YOLO(YOLO):
feed_dict
=
{
self
.
yolo_model
.
input
:
image_data
,
self
.
input_image_shape
:
[
image
.
size
[
1
],
image
.
size
[
0
]],
K
.
learning_phase
():
0
})
K
.
learning_phase
():
0
})
t2
=
time
.
time
()
tact_time
=
(
t2
-
t1
)
/
test_interval
return
tact_time
...
...
get_dr_txt.py
浏览文件 @
26308267
...
...
@@ -71,7 +71,7 @@ class mAP_YOLO(YOLO):
#---------------------------------------------------------#
boxes
,
scores
,
classes
=
yolo_eval
(
self
.
yolo_model
.
output
,
self
.
anchors
,
num_classes
,
self
.
input_image_shape
,
max_boxes
=
self
.
max_boxes
,
score_threshold
=
self
.
score
,
iou_threshold
=
self
.
iou
)
score_threshold
=
self
.
score
,
iou_threshold
=
self
.
iou
,
letterbox_image
=
self
.
letterbox_image
)
return
boxes
,
scores
,
classes
#---------------------------------------------------#
...
...
@@ -79,11 +79,11 @@ class mAP_YOLO(YOLO):
#---------------------------------------------------#
def
detect_image
(
self
,
image_id
,
image
):
f
=
open
(
"./input/detection-results/"
+
image_id
+
".txt"
,
"w"
)
#---------------------------------------------------------#
# 给图像增加灰条,实现不失真的resize
#---------------------------------------------------------#
new_image_size
=
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]
)
boxed_image
=
letterbox_image
(
image
,
new_image_size
)
if
self
.
letterbox_image
:
boxed_image
=
letterbox_image
(
image
,
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]))
else
:
boxed_image
=
image
.
convert
(
'RGB'
)
boxed_image
=
boxed_image
.
resize
((
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]),
Image
.
BICUBIC
)
image_data
=
np
.
array
(
boxed_image
,
dtype
=
'float32'
)
image_data
/=
255.
#---------------------------------------------------------#
...
...
@@ -100,7 +100,6 @@ class mAP_YOLO(YOLO):
self
.
yolo_model
.
input
:
image_data
,
self
.
input_image_shape
:
[
image
.
size
[
1
],
image
.
size
[
0
]],
K
.
learning_phase
():
0
})
for
i
,
c
in
enumerate
(
out_classes
):
predicted_class
=
self
.
class_names
[
int
(
c
)]
score
=
str
(
out_scores
[
i
])
...
...
nets/yolo4.py
浏览文件 @
26308267
...
...
@@ -225,7 +225,7 @@ def yolo_correct_boxes(box_xy, box_wh, input_shape, image_shape):
#---------------------------------------------------#
# 获取每个box和它的得分
#---------------------------------------------------#
def
yolo_boxes_and_scores
(
feats
,
anchors
,
num_classes
,
input_shape
,
image_shape
):
def
yolo_boxes_and_scores
(
feats
,
anchors
,
num_classes
,
input_shape
,
image_shape
,
letterbox_image
):
#-----------------------------------------------------------------#
# 将预测值调成真实值
# box_xy : -1,13,13,3,2;
...
...
@@ -240,7 +240,23 @@ def yolo_boxes_and_scores(feats, anchors, num_classes, input_shape, image_shape)
# 我们需要对齐进行修改,去除灰条的部分。
# 将box_xy、和box_wh调节成y_min,y_max,xmin,xmax
#-----------------------------------------------------------------#
boxes
=
yolo_correct_boxes
(
box_xy
,
box_wh
,
input_shape
,
image_shape
)
if
letterbox_image
:
boxes
=
yolo_correct_boxes
(
box_xy
,
box_wh
,
input_shape
,
image_shape
)
else
:
box_yx
=
box_xy
[...,
::
-
1
]
box_hw
=
box_wh
[...,
::
-
1
]
box_mins
=
box_yx
-
(
box_hw
/
2.
)
box_maxes
=
box_yx
+
(
box_hw
/
2.
)
input_shape
=
K
.
cast
(
input_shape
,
K
.
dtype
(
box_yx
))
image_shape
=
K
.
cast
(
image_shape
,
K
.
dtype
(
box_yx
))
boxes
=
K
.
concatenate
([
box_mins
[...,
0
:
1
]
*
image_shape
[
0
],
# y_min
box_mins
[...,
1
:
2
]
*
image_shape
[
1
],
# x_min
box_maxes
[...,
0
:
1
]
*
image_shape
[
0
],
# y_max
box_maxes
[...,
1
:
2
]
*
image_shape
[
1
]
# x_max
])
#-----------------------------------------------------------------#
# 获得最终得分和框的位置
#-----------------------------------------------------------------#
...
...
@@ -258,7 +274,8 @@ def yolo_eval(yolo_outputs,
image_shape
,
max_boxes
=
20
,
score_threshold
=
.
6
,
iou_threshold
=
.
5
):
iou_threshold
=
.
5
,
letterbox_image
=
True
):
#---------------------------------------------------#
# 获得特征层的数量,有效特征层的数量为3
#---------------------------------------------------#
...
...
@@ -280,7 +297,7 @@ def yolo_eval(yolo_outputs,
# 对每个特征层进行处理
#-----------------------------------------------------------#
for
l
in
range
(
num_layers
):
_boxes
,
_box_scores
=
yolo_boxes_and_scores
(
yolo_outputs
[
l
],
anchors
[
anchor_mask
[
l
]],
num_classes
,
input_shape
,
image_shape
)
_boxes
,
_box_scores
=
yolo_boxes_and_scores
(
yolo_outputs
[
l
],
anchors
[
anchor_mask
[
l
]],
num_classes
,
input_shape
,
image_shape
,
letterbox_image
)
boxes
.
append
(
_boxes
)
box_scores
.
append
(
_box_scores
)
#-----------------------------------------------------------#
...
...
yolo.py
浏览文件 @
26308267
...
...
@@ -21,15 +21,20 @@ from utils.utils import letterbox_image
#--------------------------------------------#
class
YOLO
(
object
):
_defaults
=
{
"model_path"
:
'model_data/yolo4_
weight
.h5'
,
"model_path"
:
'model_data/yolo4_
voc_weights
.h5'
,
"anchors_path"
:
'model_data/yolo_anchors.txt'
,
"classes_path"
:
'model_data/
coco
_classes.txt'
,
"classes_path"
:
'model_data/
voc
_classes.txt'
,
"score"
:
0.5
,
"iou"
:
0.3
,
"max_boxes"
:
100
,
# 显存比较小可以使用416x416
# 显存比较大可以使用608x608
"model_image_size"
:
(
416
,
416
)
"model_image_size"
:
(
416
,
416
),
#---------------------------------------------------------------------#
# 该变量用于控制是否使用letterbox_image对输入图像进行不失真的resize,
# 在多次测试后,发现关闭letterbox_image直接resize的效果更好
#---------------------------------------------------------------------#
"letterbox_image"
:
False
,
}
@
classmethod
...
...
@@ -119,19 +124,22 @@ class YOLO(object):
#---------------------------------------------------------#
boxes
,
scores
,
classes
=
yolo_eval
(
self
.
yolo_model
.
output
,
self
.
anchors
,
num_classes
,
self
.
input_image_shape
,
max_boxes
=
self
.
max_boxes
,
score_threshold
=
self
.
score
,
iou_threshold
=
self
.
iou
)
score_threshold
=
self
.
score
,
iou_threshold
=
self
.
iou
,
letterbox_image
=
self
.
letterbox_image
)
return
boxes
,
scores
,
classes
#---------------------------------------------------#
# 检测图片
#---------------------------------------------------#
def
detect_image
(
self
,
image
):
start
=
timer
()
#---------------------------------------------------------#
# 给图像增加灰条,实现不失真的resize
# 也可以直接resize进行识别
#---------------------------------------------------------#
new_image_size
=
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
])
boxed_image
=
letterbox_image
(
image
,
new_image_size
)
if
self
.
letterbox_image
:
boxed_image
=
letterbox_image
(
image
,
(
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]))
else
:
boxed_image
=
image
.
convert
(
'RGB'
)
boxed_image
=
boxed_image
.
resize
((
self
.
model_image_size
[
1
],
self
.
model_image_size
[
0
]),
Image
.
BICUBIC
)
image_data
=
np
.
array
(
boxed_image
,
dtype
=
'float32'
)
image_data
/=
255.
#---------------------------------------------------------#
...
...
@@ -197,8 +205,6 @@ class YOLO(object):
draw
.
text
(
text_origin
,
str
(
label
,
'UTF-8'
),
fill
=
(
0
,
0
,
0
),
font
=
font
)
del
draw
end
=
timer
()
print
(
end
-
start
)
return
image
def
close_session
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录