Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
9b2f34bf
Commit
9b2f34bf
authored
Aug 23, 2022
by
Fan Yang
Committed by
A. Unique TensorFlower
Aug 23, 2022
Browse files
Internal change
PiperOrigin-RevId: 469600398
parent
4862f9d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
13 deletions
+19
-13
official/vision/serving/export_tflite.py
official/vision/serving/export_tflite.py
+3
-3
official/vision/serving/export_tflite_lib.py
official/vision/serving/export_tflite_lib.py
+7
-4
official/vision/serving/export_tflite_lib_test.py
official/vision/serving/export_tflite_lib_test.py
+9
-6
No files found.
official/vision/serving/export_tflite.py
View file @
9b2f34bf
...
@@ -69,9 +69,9 @@ flags.DEFINE_string(
...
@@ -69,9 +69,9 @@ flags.DEFINE_string(
flags
.
DEFINE_string
(
flags
.
DEFINE_string
(
'quant_type'
,
'quant_type'
,
default
=
None
,
default
=
None
,
help
=
'Post training quantization type. Support `int8_
fp32_
fallback`, '
help
=
'Post training quantization type. Support `int8_fallback`, '
'`int8_f
p32_input_output
`, `int8_full`, `fp16`, `qat`, '
'`int8_f
ull_fp32_io
`, `int8_full`, `fp16`, `qat`,
`qat_fp32_io`,
'
'`
qat_fp32_input_output`,
and `default`. See '
'`
int8_full_int8_io`
and `default`. See '
'https://www.tensorflow.org/lite/performance/post_training_quantization '
'https://www.tensorflow.org/lite/performance/post_training_quantization '
'for more details.'
)
'for more details.'
)
flags
.
DEFINE_integer
(
'calibration_steps'
,
500
,
flags
.
DEFINE_integer
(
'calibration_steps'
,
500
,
...
...
official/vision/serving/export_tflite_lib.py
View file @
9b2f34bf
...
@@ -107,17 +107,20 @@ def convert_tflite_model(saved_model_dir: str,
...
@@ -107,17 +107,20 @@ def convert_tflite_model(saved_model_dir: str,
representative_dataset
,
representative_dataset
,
params
=
params
,
params
=
params
,
calibration_steps
=
calibration_steps
)
calibration_steps
=
calibration_steps
)
if
quant_type
in
(
'int8_full'
,
'int8_fp32_input_output
'
):
if
quant_type
.
startswith
(
'int8_full
'
):
converter
.
target_spec
.
supported_ops
=
[
converter
.
target_spec
.
supported_ops
=
[
tf
.
lite
.
OpsSet
.
TFLITE_BUILTINS_INT8
tf
.
lite
.
OpsSet
.
TFLITE_BUILTINS_INT8
]
]
if
quant_type
==
'int8_full'
:
if
quant_type
==
'int8_full'
:
converter
.
inference_input_type
=
tf
.
uint8
# or tf.int8
converter
.
inference_input_type
=
tf
.
uint8
converter
.
inference_output_type
=
tf
.
uint8
# or tf.int8
converter
.
inference_output_type
=
tf
.
uint8
if
quant_type
==
'int8_full_int8_io'
:
converter
.
inference_input_type
=
tf
.
int8
converter
.
inference_output_type
=
tf
.
int8
elif
quant_type
==
'fp16'
:
elif
quant_type
==
'fp16'
:
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
converter
.
target_spec
.
supported_types
=
[
tf
.
float16
]
converter
.
target_spec
.
supported_types
=
[
tf
.
float16
]
elif
quant_type
in
(
'default'
,
'qat_fp32_i
nput_output
'
):
elif
quant_type
in
(
'default'
,
'qat_fp32_i
o
'
):
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
elif
quant_type
==
'qat'
:
elif
quant_type
==
'qat'
:
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
converter
.
optimizations
=
[
tf
.
lite
.
Optimize
.
DEFAULT
]
...
...
official/vision/serving/export_tflite_lib_test.py
View file @
9b2f34bf
...
@@ -80,9 +80,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -80,9 +80,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
None
,
None
,
'default'
,
'default'
,
'fp16'
,
'fp16'
,
'int8_
fp32_
fallback'
,
'int8_fallback'
,
'int8_full'
,
'int8_full'
,
'int8_fp32_input_output'
,
'int8_full_fp32_io'
,
'int8_full_int8_io'
,
]))
]))
def
test_export_tflite_image_classification
(
self
,
experiment
,
quant_type
):
def
test_export_tflite_image_classification
(
self
,
experiment
,
quant_type
):
...
@@ -116,9 +117,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -116,9 +117,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
None
,
None
,
'default'
,
'default'
,
'fp16'
,
'fp16'
,
'int8_
fp32_
fallback'
,
'int8_fallback'
,
'int8_full'
,
'int8_full'
,
'int8_fp32_input_output'
,
'int8_full_fp32_io'
,
'int8_full_int8_io'
,
]))
]))
def
test_export_tflite_detection
(
self
,
experiment
,
quant_type
):
def
test_export_tflite_detection
(
self
,
experiment
,
quant_type
):
...
@@ -156,9 +158,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -156,9 +158,10 @@ class ExportTfliteLibTest(tf.test.TestCase, parameterized.TestCase):
None
,
None
,
'default'
,
'default'
,
'fp16'
,
'fp16'
,
'int8_
fp32_
fallback'
,
'int8_fallback'
,
'int8_full'
,
'int8_full'
,
'int8_fp32_input_output'
,
'int8_full_fp32_io'
,
'int8_full_int8_io'
,
]))
]))
def
test_export_tflite_semantic_segmentation
(
self
,
experiment
,
quant_type
):
def
test_export_tflite_semantic_segmentation
(
self
,
experiment
,
quant_type
):
...
...
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