Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
bfb811c7
Commit
bfb811c7
authored
Oct 14, 2019
by
Animesh Jain
Committed by
Zhi
Oct 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[QNN][TFLite] Parsing TFLite quantized models. (#3900)
parent
7530e043
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
python/tvm/relay/frontend/tflite.py
+0
-0
tests/python/frontend/tflite/test_forward.py
+45
-0
No files found.
python/tvm/relay/frontend/tflite.py
View file @
bfb811c7
This diff is collapsed.
Click to expand it.
tests/python/frontend/tflite/test_forward.py
View file @
bfb811c7
...
...
@@ -997,6 +997,46 @@ def test_forward_inception_v4_net():
tvm
.
testing
.
assert_allclose
(
np
.
squeeze
(
tvm_output
[
0
]),
np
.
squeeze
(
tflite_output
[
0
]),
rtol
=
1e-5
,
atol
=
1e-5
)
def
test_forward_qnn_inception_v1_net
():
"""Test the Quantized TFLite Inception model."""
# InceptionV1
tflite_model_file
=
tf_testing
.
get_workload_official
(
"https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_224_quant_20181026.tgz"
,
"inception_v1_224_quant.tflite"
)
with
open
(
tflite_model_file
,
"rb"
)
as
f
:
tflite_model_buf
=
f
.
read
()
# Checking the labels because the requantize implementation is different between TFLite and
# Relay. This cause final output numbers to mismatch. So, testing accuracy via labels.
np
.
random
.
seed
(
0
)
data
=
np
.
random
.
random_integers
(
low
=
0
,
high
=
128
,
size
=
(
1
,
224
,
224
,
3
))
.
astype
(
'uint8'
)
tflite_output
=
run_tflite_graph
(
tflite_model_buf
,
data
)
tflite_predictions
=
np
.
squeeze
(
tflite_output
)
tflite_sorted_labels
=
tflite_predictions
.
argsort
()[
-
3
:][::
-
1
]
tvm_output
=
run_tvm_graph
(
tflite_model_buf
,
data
,
'input'
)
tvm_predictions
=
np
.
squeeze
(
tvm_output
)
tvm_sorted_labels
=
tvm_predictions
.
argsort
()[
-
3
:][::
-
1
]
tvm
.
testing
.
assert_allclose
(
tvm_sorted_labels
,
tflite_sorted_labels
)
def
test_forward_qnn_mobilenet_v1_net
():
"""Test the Quantized TFLite Mobilenet V1 model."""
# MobilenetV1
tflite_model_file
=
tf_testing
.
get_workload_official
(
"https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz"
,
"mobilenet_v1_1.0_224_quant.tflite"
)
with
open
(
tflite_model_file
,
"rb"
)
as
f
:
tflite_model_buf
=
f
.
read
()
# Checking the labels because the requantize implementation is different between TFLite and
# Relay. This cause final output numbers to mismatch. So, testing accuracy via labels.
np
.
random
.
seed
(
0
)
data
=
np
.
random
.
random_integers
(
low
=
0
,
high
=
128
,
size
=
(
1
,
224
,
224
,
3
))
.
astype
(
'uint8'
)
tflite_output
=
run_tflite_graph
(
tflite_model_buf
,
data
)
tflite_predictions
=
np
.
squeeze
(
tflite_output
)
tflite_sorted_labels
=
tflite_predictions
.
argsort
()[
-
3
:][::
-
1
]
tvm_output
=
run_tvm_graph
(
tflite_model_buf
,
data
,
'input'
)
tvm_predictions
=
np
.
squeeze
(
tvm_output
)
tvm_sorted_labels
=
tvm_predictions
.
argsort
()[
-
3
:][::
-
1
]
tvm
.
testing
.
assert_allclose
(
tvm_sorted_labels
,
tflite_sorted_labels
)
#######################################################################
# SSD Mobilenet
# -------------
...
...
@@ -1069,3 +1109,8 @@ if __name__ == '__main__':
test_forward_inception_v3_net
()
test_forward_inception_v4_net
()
test_forward_ssd_mobilenet_v1
()
# End to End quantized
# TODO - MobilenetV2 fails for now. Remove when fixed.
test_forward_qnn_inception_v1_net
()
test_forward_qnn_mobilenet_v1_net
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment