Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 111d2ba

Browse files
committed
--rigorous_optimization_for_myriad added
1 parent 98a146b commit 111d2ba

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG CPVER=cp38
77
ARG OPENVINOVER=2021.4.582
88
ARG OPENVINOROOTDIR=/opt/intel/openvino_2021
99
ARG TENSORRTVER=cuda11.3-trt8.0.1.6-ga-20210626
10-
ARG APPVER=v1.13.0
10+
ARG APPVER=v1.13.1
1111
ARG wkdir=/home/user
1212

1313
# dash -> bash

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ usage: tflite2tensorflow
308308
[--vpu_number_of_shaves VPU_NUMBER_OF_SHAVES]
309309
[--vpu_number_of_cmx_slices VPU_NUMBER_OF_CMX_SLICES]
310310
[--optimizing_for_openvino_and_myriad]
311+
[--rigorous_optimization_for_myriad]
311312
[--replace_swish_and_hardswish]
312313
[--optimizing_hardswish_for_edgetpu]
313314
[--replace_prelu_and_minmax]
@@ -393,6 +394,8 @@ optional arguments:
393394
vpu number of cmx slices. Default: 4
394395
--optimizing_for_openvino_and_myriad
395396
Optimizing graph for openvino/myriad
397+
--rigorous_optimization_for_myriad
398+
Replace operations that are not supported by myriad with operations that are as feasible as possible.
396399
--replace_swish_and_hardswish
397400
Replace swish and hard-swish with each other
398401
--optimizing_hardswish_for_edgetpu
@@ -422,6 +425,16 @@ $ tflite2tensorflow \
422425
```
423426
or
424427
```
428+
$ tflite2tensorflow \
429+
--model_path segm_full_v679.tflite \
430+
--flatc_path ../flatc \
431+
--schema_path ../schema.fbs \
432+
--output_pb \
433+
--optimizing_for_openvino_and_myriad \
434+
--rigorous_optimization_for_myriad
435+
```
436+
or
437+
```
425438
$ tflite2tensorflow \
426439
--model_path segm_full_v679.tflite \
427440
--flatc_path ../flatc \

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
setup(
1212
name="tflite2tensorflow",
1313
scripts=scripts,
14-
version="1.13.0",
14+
version="1.13.1",
1515
description="Generate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite.",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",

tflite2tensorflow/tflite2tensorflow.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ def make_graph(
419419
replace_swish_and_hardswish,
420420
replace_prelu_and_minmax,
421421
optimizing_for_edgetpu_flg,
422-
optimizing_for_openvino_and_myriad):
422+
optimizing_for_openvino_and_myriad,
423+
rigorous_optimization_for_myriad):
423424

424425
import tensorflow.compat.v1 as tf
425426
tf.get_logger().setLevel('INFO')
@@ -3240,10 +3241,22 @@ def pad_v2(x, paddings, constant_values):
32403241
input_tensor1 = backward_quantization(input_detail, input_tensor1)
32413242

32423243
output_detail = interpreter._get_tensor_details(op['outputs'][0])
3243-
output_tensor = tf.math.abs(
3244-
input_tensor1,
3245-
name=get_op_name(output_detail['name'])
3246-
)
3244+
if not optimizing_for_openvino_and_myriad:
3245+
output_tensor = tf.math.abs(
3246+
input_tensor1,
3247+
name=get_op_name(output_detail['name'])
3248+
)
3249+
elif optimizing_for_openvino_and_myriad and not rigorous_optimization_for_myriad:
3250+
output_tensor = tf.math.abs(
3251+
input_tensor1,
3252+
name=get_op_name(output_detail['name'])
3253+
)
3254+
elif optimizing_for_openvino_and_myriad and rigorous_optimization_for_myriad:
3255+
output_tensor = tf.math.sqrt(
3256+
tf.math.square(input_tensor1),
3257+
name=get_op_name(output_detail['name'])
3258+
)
3259+
32473260
tensors[output_detail['index']] = output_tensor
32483261

32493262
elif op_type == 'UNIQUE':
@@ -5384,6 +5397,7 @@ def main():
53845397
parser.add_argument('--vpu_number_of_shaves', type=int, default=4, help='vpu number of shaves. Default: 4')
53855398
parser.add_argument('--vpu_number_of_cmx_slices', type=int, default=4, help='vpu number of cmx slices. Default: 4')
53865399
parser.add_argument('--optimizing_for_openvino_and_myriad', action='store_true', help='Optimizing graph for openvino/myriad')
5400+
parser.add_argument('--rigorous_optimization_for_myriad', action='store_true', help='Replace operations that are not supported by myriad with operations that are as feasible as possible.')
53875401
parser.add_argument('--replace_swish_and_hardswish', action='store_true', help='Replace swish and hard-swish with each other')
53885402
parser.add_argument('--optimizing_hardswish_for_edgetpu', action='store_true', help='Optimizing hardswish for edgetpu')
53895403
parser.add_argument('--replace_prelu_and_minmax', action='store_true', help='Replace prelu and minimum/maximum with each other')
@@ -5427,6 +5441,7 @@ def main():
54275441
vpu_number_of_shaves = args.vpu_number_of_shaves
54285442
vpu_number_of_cmx_slices = args.vpu_number_of_cmx_slices
54295443
optimizing_for_openvino_and_myriad = args.optimizing_for_openvino_and_myriad
5444+
rigorous_optimization_for_myriad = args.rigorous_optimization_for_myriad
54305445
replace_swish_and_hardswish = args.replace_swish_and_hardswish
54315446
optimizing_hardswish_for_edgetpu = args.optimizing_hardswish_for_edgetpu
54325447
replace_prelu_and_minmax = args.replace_prelu_and_minmax
@@ -5530,6 +5545,9 @@ def main():
55305545
print(f'{Color.RED}ERROR:{Color.RESET} optimizing_for_openvino_and_myriad and optimizing_hardswish_for_edgetpu cannot be True at the same time.')
55315546
sys.exit(-1)
55325547

5548+
if not optimizing_for_openvino_and_myriad and rigorous_optimization_for_myriad:
5549+
optimizing_for_openvino_and_myriad = True
5550+
55335551
if tfv1_flg:
55345552
from tensorflow.lite.python.interpreter import Interpreter as tflite_interpreter
55355553

@@ -5563,7 +5581,8 @@ def main():
55635581
replace_swish_and_hardswish,
55645582
replace_prelu_and_minmax,
55655583
optimizing_for_edgetpu_flg,
5566-
optimizing_for_openvino_and_myriad)
5584+
optimizing_for_openvino_and_myriad,
5585+
rigorous_optimization_for_myriad)
55675586
print('outputs:')
55685587
if not TFLite_Detection_PostProcess_flg:
55695588
for output in output_details:

0 commit comments

Comments
 (0)