Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
0dd66e2d
Unverified
提交
0dd66e2d
authored
5月 24, 2022
作者:
Glenn Jocher
提交者:
GitHub
5月 24, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OpenVINO metadata fix (#7952)
* Rename OpenVINO meta.yaml to model name * Rename OpenVINO meta.yaml to model name * Rename OpenVINO meta.yaml to model name * fix
上级
a3a652c9
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
14 行删除
+15
-14
export.py
export.py
+1
-1
common.py
models/common.py
+14
-13
没有找到文件。
export.py
浏览文件 @
0dd66e2d
...
@@ -180,7 +180,7 @@ def export_openvino(model, file, half, prefix=colorstr('OpenVINO:')):
...
@@ -180,7 +180,7 @@ def export_openvino(model, file, half, prefix=colorstr('OpenVINO:')):
cmd
=
f
"mo --input_model {file.with_suffix('.onnx')} --output_dir {f} --data_type {'FP16' if half else 'FP32'}"
cmd
=
f
"mo --input_model {file.with_suffix('.onnx')} --output_dir {f} --data_type {'FP16' if half else 'FP32'}"
subprocess
.
check_output
(
cmd
.
split
())
# export
subprocess
.
check_output
(
cmd
.
split
())
# export
with
open
(
Path
(
f
)
/
'meta.yaml'
,
'w'
)
as
g
:
with
open
(
Path
(
f
)
/
file
.
with_suffix
(
'.yaml'
)
,
'w'
)
as
g
:
yaml
.
dump
({
'stride'
:
int
(
max
(
model
.
stride
)),
'names'
:
model
.
names
},
g
)
# add metadata.yaml
yaml
.
dump
({
'stride'
:
int
(
max
(
model
.
stride
)),
'names'
:
model
.
names
},
g
)
# add metadata.yaml
LOGGER
.
info
(
f
'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)'
)
LOGGER
.
info
(
f
'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)'
)
...
...
models/common.py
浏览文件 @
0dd66e2d
...
@@ -323,9 +323,12 @@ class DetectMultiBackend(nn.Module):
...
@@ -323,9 +323,12 @@ class DetectMultiBackend(nn.Module):
super
()
.
__init__
()
super
()
.
__init__
()
w
=
str
(
weights
[
0
]
if
isinstance
(
weights
,
list
)
else
weights
)
w
=
str
(
weights
[
0
]
if
isinstance
(
weights
,
list
)
else
weights
)
pt
,
jit
,
onnx
,
xml
,
engine
,
coreml
,
saved_model
,
pb
,
tflite
,
edgetpu
,
tfjs
=
self
.
model_type
(
w
)
# get backend
pt
,
jit
,
onnx
,
xml
,
engine
,
coreml
,
saved_model
,
pb
,
tflite
,
edgetpu
,
tfjs
=
self
.
model_type
(
w
)
# get backend
stride
,
names
=
32
,
[
f
'class{i}'
for
i
in
range
(
1000
)]
# assign defaults
w
=
attempt_download
(
w
)
# download if not local
w
=
attempt_download
(
w
)
# download if not local
fp16
&=
(
pt
or
jit
or
onnx
or
engine
)
and
device
.
type
!=
'cpu'
# FP16
fp16
&=
(
pt
or
jit
or
onnx
or
engine
)
and
device
.
type
!=
'cpu'
# FP16
stride
,
names
=
32
,
[
f
'class{i}'
for
i
in
range
(
1000
)]
# assign defaults
if
data
:
# assign class names (optional)
with
open
(
data
,
errors
=
'ignore'
)
as
f
:
names
=
yaml
.
safe_load
(
f
)[
'names'
]
if
pt
:
# PyTorch
if
pt
:
# PyTorch
model
=
attempt_load
(
weights
if
isinstance
(
weights
,
list
)
else
w
,
map_location
=
device
)
model
=
attempt_load
(
weights
if
isinstance
(
weights
,
list
)
else
w
,
map_location
=
device
)
...
@@ -365,7 +368,9 @@ class DetectMultiBackend(nn.Module):
...
@@ -365,7 +368,9 @@ class DetectMultiBackend(nn.Module):
network
=
ie
.
read_model
(
model
=
w
,
weights
=
Path
(
w
)
.
with_suffix
(
'.bin'
))
network
=
ie
.
read_model
(
model
=
w
,
weights
=
Path
(
w
)
.
with_suffix
(
'.bin'
))
executable_network
=
ie
.
compile_model
(
model
=
network
,
device_name
=
"CPU"
)
executable_network
=
ie
.
compile_model
(
model
=
network
,
device_name
=
"CPU"
)
output_layer
=
next
(
iter
(
executable_network
.
outputs
))
output_layer
=
next
(
iter
(
executable_network
.
outputs
))
self
.
_load_metadata
(
w
.
parent
/
'meta.yaml'
)
# load metadata
meta
=
w
.
with_suffix
(
'.yaml'
)
if
meta
.
exists
():
stride
,
names
=
self
.
_load_metadata
(
meta
)
# load metadata
elif
engine
:
# TensorRT
elif
engine
:
# TensorRT
LOGGER
.
info
(
f
'Loading {w} for TensorRT inference...'
)
LOGGER
.
info
(
f
'Loading {w} for TensorRT inference...'
)
import
tensorrt
as
trt
# https://developer.nvidia.com/nvidia-tensorrt-download
import
tensorrt
as
trt
# https://developer.nvidia.com/nvidia-tensorrt-download
...
@@ -431,11 +436,7 @@ class DetectMultiBackend(nn.Module):
...
@@ -431,11 +436,7 @@ class DetectMultiBackend(nn.Module):
output_details
=
interpreter
.
get_output_details
()
# outputs
output_details
=
interpreter
.
get_output_details
()
# outputs
elif
tfjs
:
elif
tfjs
:
raise
Exception
(
'ERROR: YOLOv5 TF.js inference is not supported'
)
raise
Exception
(
'ERROR: YOLOv5 TF.js inference is not supported'
)
self
.
__dict__
.
update
(
locals
())
# assign all variables to self
self
.
__dict__
.
update
(
locals
())
# assign all variables to self
if
not
hasattr
(
self
,
'names'
)
and
data
:
# assign class names (optional)
with
open
(
data
,
errors
=
'ignore'
)
as
f
:
names
=
yaml
.
safe_load
(
f
)[
'names'
]
def
forward
(
self
,
im
,
augment
=
False
,
visualize
=
False
,
val
=
False
):
def
forward
(
self
,
im
,
augment
=
False
,
visualize
=
False
,
val
=
False
):
# YOLOv5 MultiBackend inference
# YOLOv5 MultiBackend inference
...
@@ -495,13 +496,6 @@ class DetectMultiBackend(nn.Module):
...
@@ -495,13 +496,6 @@ class DetectMultiBackend(nn.Module):
y
=
torch
.
tensor
(
y
,
device
=
self
.
device
)
y
=
torch
.
tensor
(
y
,
device
=
self
.
device
)
return
(
y
,
[])
if
val
else
y
return
(
y
,
[])
if
val
else
y
def
_load_metadata
(
self
,
f
=
'path/to/meta.yaml'
):
# Load metadata from meta.yaml if it exists
if
Path
(
f
)
.
is_file
():
with
open
(
f
,
errors
=
'ignore'
)
as
f
:
for
k
,
v
in
yaml
.
safe_load
(
f
)
.
items
():
setattr
(
self
,
k
,
v
)
# assign stride, names
def
warmup
(
self
,
imgsz
=
(
1
,
3
,
640
,
640
)):
def
warmup
(
self
,
imgsz
=
(
1
,
3
,
640
,
640
)):
# Warmup model by running inference once
# Warmup model by running inference once
warmup_types
=
self
.
pt
,
self
.
jit
,
self
.
onnx
,
self
.
engine
,
self
.
saved_model
,
self
.
pb
warmup_types
=
self
.
pt
,
self
.
jit
,
self
.
onnx
,
self
.
engine
,
self
.
saved_model
,
self
.
pb
...
@@ -522,6 +516,13 @@ class DetectMultiBackend(nn.Module):
...
@@ -522,6 +516,13 @@ class DetectMultiBackend(nn.Module):
tflite
&=
not
edgetpu
# *.tflite
tflite
&=
not
edgetpu
# *.tflite
return
pt
,
jit
,
onnx
,
xml
,
engine
,
coreml
,
saved_model
,
pb
,
tflite
,
edgetpu
,
tfjs
return
pt
,
jit
,
onnx
,
xml
,
engine
,
coreml
,
saved_model
,
pb
,
tflite
,
edgetpu
,
tfjs
@staticmethod
def
_load_metadata
(
f
=
'path/to/meta.yaml'
):
# Load metadata from meta.yaml if it exists
with
open
(
f
,
errors
=
'ignore'
)
as
f
:
d
=
yaml
.
safe_load
(
f
)
return
d
[
'stride'
],
d
[
'names'
]
# assign stride, names
class
AutoShape
(
nn
.
Module
):
class
AutoShape
(
nn
.
Module
):
# YOLOv5 input-robust model wrapper for passing cv2/np/PIL/torch inputs. Includes preprocessing, inference and NMS
# YOLOv5 input-robust model wrapper for passing cv2/np/PIL/torch inputs. Includes preprocessing, inference and NMS
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论