Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
a9553c04
Unverified
提交
a9553c04
authored
6月 09, 2021
作者:
Glenn Jocher
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor test.py arguments (#3558)
* remove opt from test() * pass kwargs * update comments * revert accidental default change * multiple --img options * add comments
上级
c6deb73a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
29 行删除
+19
-29
detect.py
detect.py
+1
-1
test.py
test.py
+18
-28
没有找到文件。
detect.py
浏览文件 @
a9553c04
...
@@ -33,7 +33,7 @@ def detect(opt):
...
@@ -33,7 +33,7 @@ def detect(opt):
# Load model
# Load model
model
=
attempt_load
(
weights
,
map_location
=
device
)
# load FP32 model
model
=
attempt_load
(
weights
,
map_location
=
device
)
# load FP32 model
stride
=
int
(
model
.
stride
.
max
())
# model stride
stride
=
int
(
model
.
stride
.
max
())
# model stride
imgsz
=
check_img_size
(
imgsz
,
s
=
stride
)
# check im
g_
size
imgsz
=
check_img_size
(
imgsz
,
s
=
stride
)
# check im
age
size
names
=
model
.
module
.
names
if
hasattr
(
model
,
'module'
)
else
model
.
names
# get class names
names
=
model
.
module
.
names
if
hasattr
(
model
,
'module'
)
else
model
.
names
# get class names
if
half
:
if
half
:
model
.
half
()
# to FP16
model
.
half
()
# to FP16
...
...
test.py
浏览文件 @
a9553c04
...
@@ -22,9 +22,9 @@ from utils.torch_utils import select_device, time_synchronized
...
@@ -22,9 +22,9 @@ from utils.torch_utils import select_device, time_synchronized
def
test
(
data
,
def
test
(
data
,
weights
=
None
,
weights
=
None
,
batch_size
=
32
,
batch_size
=
32
,
imgsz
=
640
,
imgsz
=
640
,
# image size
conf_thres
=
0.001
,
conf_thres
=
0.001
,
# confidence threshold
iou_thres
=
0.6
,
#
for NMS
iou_thres
=
0.6
,
#
NMS IoU threshold
save_json
=
False
,
save_json
=
False
,
single_cls
=
False
,
single_cls
=
False
,
augment
=
False
,
augment
=
False
,
...
@@ -38,8 +38,12 @@ def test(data,
...
@@ -38,8 +38,12 @@ def test(data,
plots
=
True
,
plots
=
True
,
wandb_logger
=
None
,
wandb_logger
=
None
,
compute_loss
=
None
,
compute_loss
=
None
,
half
=
True
,
half
=
True
,
# FP16 half-precision inference
opt
=
None
):
project
=
'runs/test'
,
name
=
'exp'
,
exist_ok
=
False
,
task
=
'val'
,
device
=
''
):
# Initialize/load model and set device
# Initialize/load model and set device
training
=
model
is
not
None
training
=
model
is
not
None
if
training
:
# called by train.py
if
training
:
# called by train.py
...
@@ -47,16 +51,16 @@ def test(data,
...
@@ -47,16 +51,16 @@ def test(data,
else
:
# called directly
else
:
# called directly
set_logging
()
set_logging
()
device
=
select_device
(
opt
.
device
,
batch_size
=
batch_size
)
device
=
select_device
(
device
,
batch_size
=
batch_size
)
# Directories
# Directories
save_dir
=
increment_path
(
Path
(
opt
.
project
)
/
opt
.
name
,
exist_ok
=
opt
.
exist_ok
)
# increment run
save_dir
=
increment_path
(
Path
(
project
)
/
name
,
exist_ok
=
exist_ok
)
# increment run
(
save_dir
/
'labels'
if
save_txt
else
save_dir
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# make dir
(
save_dir
/
'labels'
if
save_txt
else
save_dir
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# make dir
# Load model
# Load model
model
=
attempt_load
(
weights
,
map_location
=
device
)
# load FP32 model
model
=
attempt_load
(
weights
,
map_location
=
device
)
# load FP32 model
gs
=
max
(
int
(
model
.
stride
.
max
()),
32
)
# grid size (max stride)
gs
=
max
(
int
(
model
.
stride
.
max
()),
32
)
# grid size (max stride)
imgsz
=
check_img_size
(
imgsz
,
s
=
gs
)
# check im
g_
size
imgsz
=
check_img_size
(
imgsz
,
s
=
gs
)
# check im
age
size
# Multi-GPU disabled, incompatible with .half() https://github.com/ultralytics/yolov5/issues/99
# Multi-GPU disabled, incompatible with .half() https://github.com/ultralytics/yolov5/issues/99
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
...
@@ -86,7 +90,7 @@ def test(data,
...
@@ -86,7 +90,7 @@ def test(data,
if
not
training
:
if
not
training
:
if
device
.
type
!=
'cpu'
:
if
device
.
type
!=
'cpu'
:
model
(
torch
.
zeros
(
1
,
3
,
imgsz
,
imgsz
)
.
to
(
device
)
.
type_as
(
next
(
model
.
parameters
())))
# run once
model
(
torch
.
zeros
(
1
,
3
,
imgsz
,
imgsz
)
.
to
(
device
)
.
type_as
(
next
(
model
.
parameters
())))
# run once
task
=
opt
.
task
if
opt
.
task
in
(
'train'
,
'val'
,
'test'
)
else
'val'
# path to train/val/test images
task
=
task
if
task
in
(
'train'
,
'val'
,
'test'
)
else
'val'
# path to train/val/test images
dataloader
=
create_dataloader
(
data
[
task
],
imgsz
,
batch_size
,
gs
,
single_cls
,
pad
=
0.5
,
rect
=
True
,
dataloader
=
create_dataloader
(
data
[
task
],
imgsz
,
batch_size
,
gs
,
single_cls
,
pad
=
0.5
,
rect
=
True
,
prefix
=
colorstr
(
f
'{task}: '
))[
0
]
prefix
=
colorstr
(
f
'{task}: '
))[
0
]
...
@@ -294,7 +298,7 @@ if __name__ == '__main__':
...
@@ -294,7 +298,7 @@ if __name__ == '__main__':
parser
.
add_argument
(
'--weights'
,
nargs
=
'+'
,
type
=
str
,
default
=
'yolov5s.pt'
,
help
=
'model.pt path(s)'
)
parser
.
add_argument
(
'--weights'
,
nargs
=
'+'
,
type
=
str
,
default
=
'yolov5s.pt'
,
help
=
'model.pt path(s)'
)
parser
.
add_argument
(
'--data'
,
type
=
str
,
default
=
'data/coco128.yaml'
,
help
=
'*.data path'
)
parser
.
add_argument
(
'--data'
,
type
=
str
,
default
=
'data/coco128.yaml'
,
help
=
'*.data path'
)
parser
.
add_argument
(
'--batch-size'
,
type
=
int
,
default
=
32
,
help
=
'size of each image batch'
)
parser
.
add_argument
(
'--batch-size'
,
type
=
int
,
default
=
32
,
help
=
'size of each image batch'
)
parser
.
add_argument
(
'--img-size'
,
type
=
int
,
default
=
640
,
help
=
'inference size (pixels)'
)
parser
.
add_argument
(
'--img
sz'
,
'--img'
,
'--img
-size'
,
type
=
int
,
default
=
640
,
help
=
'inference size (pixels)'
)
parser
.
add_argument
(
'--conf-thres'
,
type
=
float
,
default
=
0.001
,
help
=
'object confidence threshold'
)
parser
.
add_argument
(
'--conf-thres'
,
type
=
float
,
default
=
0.001
,
help
=
'object confidence threshold'
)
parser
.
add_argument
(
'--iou-thres'
,
type
=
float
,
default
=
0.6
,
help
=
'IOU threshold for NMS'
)
parser
.
add_argument
(
'--iou-thres'
,
type
=
float
,
default
=
0.6
,
help
=
'IOU threshold for NMS'
)
parser
.
add_argument
(
'--task'
,
default
=
'val'
,
help
=
'train, val, test, speed or study'
)
parser
.
add_argument
(
'--task'
,
default
=
'val'
,
help
=
'train, val, test, speed or study'
)
...
@@ -312,31 +316,17 @@ if __name__ == '__main__':
...
@@ -312,31 +316,17 @@ if __name__ == '__main__':
parser
.
add_argument
(
'--half'
,
action
=
'store_true'
,
help
=
'use FP16 half-precision inference'
)
parser
.
add_argument
(
'--half'
,
action
=
'store_true'
,
help
=
'use FP16 half-precision inference'
)
opt
=
parser
.
parse_args
()
opt
=
parser
.
parse_args
()
opt
.
save_json
|=
opt
.
data
.
endswith
(
'coco.yaml'
)
opt
.
save_json
|=
opt
.
data
.
endswith
(
'coco.yaml'
)
opt
.
save_txt
|=
opt
.
save_hybrid
opt
.
data
=
check_file
(
opt
.
data
)
# check file
opt
.
data
=
check_file
(
opt
.
data
)
# check file
print
(
opt
)
print
(
opt
)
check_requirements
(
exclude
=
(
'tensorboard'
,
'thop'
))
check_requirements
(
exclude
=
(
'tensorboard'
,
'thop'
))
if
opt
.
task
in
(
'train'
,
'val'
,
'test'
):
# run normally
if
opt
.
task
in
(
'train'
,
'val'
,
'test'
):
# run normally
test
(
opt
.
data
,
test
(
**
vars
(
opt
))
opt
.
weights
,
opt
.
batch_size
,
opt
.
img_size
,
opt
.
conf_thres
,
opt
.
iou_thres
,
opt
.
save_json
,
opt
.
single_cls
,
opt
.
augment
,
opt
.
verbose
,
save_txt
=
opt
.
save_txt
|
opt
.
save_hybrid
,
save_hybrid
=
opt
.
save_hybrid
,
save_conf
=
opt
.
save_conf
,
half
=
opt
.
half
,
opt
=
opt
)
elif
opt
.
task
==
'speed'
:
# speed benchmarks
elif
opt
.
task
==
'speed'
:
# speed benchmarks
for
w
in
opt
.
weights
if
isinstance
(
opt
.
weights
,
list
)
else
[
opt
.
weights
]:
for
w
in
opt
.
weights
if
isinstance
(
opt
.
weights
,
list
)
else
[
opt
.
weights
]:
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
opt
.
img
_size
,
0.25
,
0.45
,
save_json
=
False
,
plots
=
False
,
opt
=
opt
)
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
opt
.
img
sz
,
0.25
,
0.45
,
save_json
=
False
,
plots
=
False
)
elif
opt
.
task
==
'study'
:
# run over a range of settings and save/plot
elif
opt
.
task
==
'study'
:
# run over a range of settings and save/plot
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
...
@@ -347,7 +337,7 @@ if __name__ == '__main__':
...
@@ -347,7 +337,7 @@ if __name__ == '__main__':
for
i
in
x
:
# img-size
for
i
in
x
:
# img-size
print
(
f
'
\n
Running {f} point {i}...'
)
print
(
f
'
\n
Running {f} point {i}...'
)
r
,
_
,
t
=
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
i
,
opt
.
conf_thres
,
opt
.
iou_thres
,
opt
.
save_json
,
r
,
_
,
t
=
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
i
,
opt
.
conf_thres
,
opt
.
iou_thres
,
opt
.
save_json
,
plots
=
False
,
opt
=
opt
)
plots
=
False
)
y
.
append
(
r
+
t
)
# results and times
y
.
append
(
r
+
t
)
# results and times
np
.
savetxt
(
f
,
y
,
fmt
=
'
%10.4
g'
)
# save
np
.
savetxt
(
f
,
y
,
fmt
=
'
%10.4
g'
)
# save
os
.
system
(
'zip -r study.zip study_*.txt'
)
os
.
system
(
'zip -r study.zip study_*.txt'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论