Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
a297efc3
Unverified
提交
a297efc3
authored
2月 19, 2022
作者:
Raffaele Galliera
提交者:
GitHub
2月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Edge TPU inference fix (#6686)
* refactor: use edgetpu flag * fix: remove bitwise and assignation to tflite * Cleanup and fix tflite * Cleanup Co-authored-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
上级
03653790
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
19 行删除
+21
-19
common.py
models/common.py
+21
-19
没有找到文件。
models/common.py
浏览文件 @
a297efc3
...
...
@@ -279,17 +279,17 @@ class DetectMultiBackend(nn.Module):
# YOLOv5 MultiBackend class for python inference on various backends
def
__init__
(
self
,
weights
=
'yolov5s.pt'
,
device
=
None
,
dnn
=
False
,
data
=
None
):
# Usage:
# PyTorch: weights = *.pt
# TorchScript: *.torchscript
#
CoreML: *.mlmodel
# O
penVINO: *.xml
#
TensorFlow: *_saved_mode
l
#
TensorFlow: *.pb
# Tensor
Flow Lite: *.tflit
e
# TensorFlow
Edge TPU: *_edgetpu.tflite
#
ONNX Runtime: *.onnx
#
OpenCV DNN: *.onnx with dnn=Tru
e
# Tensor
RT: *.engin
e
# PyTorch:
weights = *.pt
# TorchScript:
*.torchscript
#
ONNX Runtime: *.onnx
# O
NNX OpenCV DNN: *.onnx with --dnn
#
OpenVINO: *.xm
l
#
CoreML: *.mlmodel
# Tensor
RT: *.engin
e
# TensorFlow
SavedModel: *_saved_model
#
TensorFlow GraphDef: *.pb
#
TensorFlow Lite: *.tflit
e
# Tensor
Flow Edge TPU: *_edgetpu.tflit
e
from
models.experimental
import
attempt_download
,
attempt_load
# scoped to avoid circular import
super
()
.
__init__
()
...
...
@@ -367,19 +367,19 @@ class DetectMultiBackend(nn.Module):
def
wrap_frozen_graph
(
gd
,
inputs
,
outputs
):
x
=
tf
.
compat
.
v1
.
wrap_function
(
lambda
:
tf
.
compat
.
v1
.
import_graph_def
(
gd
,
name
=
""
),
[])
# wrapped
return
x
.
prune
(
tf
.
nest
.
map_structure
(
x
.
graph
.
as_graph_element
,
inputs
),
tf
.
nest
.
map_structure
(
x
.
graph
.
as_graph_element
,
outputs
))
ge
=
x
.
graph
.
as_graph_element
return
x
.
prune
(
tf
.
nest
.
map_structure
(
ge
,
inputs
),
tf
.
nest
.
map_structure
(
ge
,
outputs
))
g
raph_def
=
tf
.
Graph
()
.
as_graph_def
()
g
raph_def
.
ParseFromString
(
open
(
w
,
'rb'
)
.
read
())
frozen_func
=
wrap_frozen_graph
(
gd
=
graph_def
,
inputs
=
"x:0"
,
outputs
=
"Identity:0"
)
elif
tflite
:
# https://www.tensorflow.org/lite/guide/python#install_tensorflow_lite_for_python
g
d
=
tf
.
Graph
()
.
as_graph_def
()
# graph_def
g
d
.
ParseFromString
(
open
(
w
,
'rb'
)
.
read
())
frozen_func
=
wrap_frozen_graph
(
gd
,
inputs
=
"x:0"
,
outputs
=
"Identity:0"
)
elif
tflite
or
edgetpu
:
# https://www.tensorflow.org/lite/guide/python#install_tensorflow_lite_for_python
try
:
# https://coral.ai/docs/edgetpu/tflite-python/#update-existing-tf-lite-code-for-the-edge-tpu
from
tflite_runtime.interpreter
import
Interpreter
,
load_delegate
except
ImportError
:
import
tensorflow
as
tf
Interpreter
,
load_delegate
=
tf
.
lite
.
Interpreter
,
tf
.
lite
.
experimental
.
load_delegate
,
if
'edgetpu'
in
w
.
lower
()
:
# Edge TPU https://coral.ai/software/#edgetpu-runtime
if
edgetpu
:
# Edge TPU https://coral.ai/software/#edgetpu-runtime
LOGGER
.
info
(
f
'Loading {w} for TensorFlow Lite Edge TPU inference...'
)
delegate
=
{
'Linux'
:
'libedgetpu.so.1'
,
'Darwin'
:
'libedgetpu.1.dylib'
,
...
...
@@ -391,6 +391,8 @@ class DetectMultiBackend(nn.Module):
interpreter
.
allocate_tensors
()
# allocate
input_details
=
interpreter
.
get_input_details
()
# inputs
output_details
=
interpreter
.
get_output_details
()
# outputs
elif
tfjs
:
raise
Exception
(
'ERROR: YOLOv5 TF.js inference is not supported'
)
self
.
__dict__
.
update
(
locals
())
# assign all variables to self
def
forward
(
self
,
im
,
augment
=
False
,
visualize
=
False
,
val
=
False
):
...
...
@@ -436,7 +438,7 @@ class DetectMultiBackend(nn.Module):
y
=
(
self
.
model
(
im
,
training
=
False
)
if
self
.
keras
else
self
.
model
(
im
)[
0
])
.
numpy
()
elif
self
.
pb
:
# GraphDef
y
=
self
.
frozen_func
(
x
=
self
.
tf
.
constant
(
im
))
.
numpy
()
el
if
self
.
tflite
:
# Lite
el
se
:
# Lite or Edge TPU
input
,
output
=
self
.
input_details
[
0
],
self
.
output_details
[
0
]
int8
=
input
[
'dtype'
]
==
np
.
uint8
# is TFLite quantized uint8 model
if
int8
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论