8000 Fix duplicate error in LiteRT by replacing tensorflow.lite with tflit… · linux-on-ibm-z/tensorflow@52f1cfe · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 52f1cfe

Browse files
ecalubaquibtensorflower-gardener
authored andcommitted
Fix duplicate error in LiteRT by replacing tensorflow.lite with tflite.python.lite
PiperOrigin-RevId: 730711746
1 parent b482271 commit 52f1cfe

File tree

29 files changed

+163
-132
lines changed

29 files changed

+163
-132
lines changed

tensorflow/lite/examples/experimental_new_converter/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ py_strict_binary(
1111
srcs = ["stack_trace_example.py"],
1212
deps = [
1313
"//tensorflow:tensorflow_py",
14+
"//tensorflow/lite/python:lite",
1415
"@absl_py//absl:app",
1516
],
1617
)

tensorflow/lite/examples/experimental_new_converter/stack_trace_example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from absl import app
2020

2121
import tensorflow as tf
22+
from tensorflow.lite.python import lite
2223

2324

2425
def suppress_exception(f):
@@ -49,7 +50,7 @@ def test_from_saved_model():
4950
tf.saved_model.save(test_model, saved_model_path, options=save_options)
5051

5152
# load the model and convert
52-
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_path)
53+
converter = lite.TFLiteConverterV2.from_saved_model(saved_model_path)
5354
converter.convert()
5455

5556

@@ -63,7 +64,7 @@ def model(x):
6364
return y + y
6465

6566
func = model.get_concrete_function()
66-
converter = tf.lite.TFLiteConverter.from_concrete_functions([func], model)
67+
converter = lite.TFLiteConverterV2.from_concrete_functions([func], model)
6768
converter.convert()
6869

6970

tensorflow/lite/examples/python/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package(
1515
# deps = [
1616
# "//third_party/py/PIL:pil",
1717
# "//third_party/py/numpy",
18-
# "//tensorflow:tensorflow_py",
18+
# "//tensorflow/lite/python:lite",
1919
# ],
2020
# )
2121
# copybara:uncomment_end

tensorflow/lite/examples/python/label_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import numpy as np
2121
from PIL import Image
22-
import tensorflow as tf
22+
from tensorflow.lite.python import lite
2323

2424

2525
def load_labels(filename):
@@ -85,7 +85,7 @@ def load_labels(filename):
8585
tflite.load_delegate(args.ext_delegate, ext_delegate_options)
8686
]
8787

88-
interpreter = tf.lite.Interpreter(
88+
interpreter = lite.Interpreter(
8989
model_path=args.model_file,
9090
experimental_delegates=ext_delegate,
9191
num_threads=args.num_threads)

tensorflow/lite/experimental/acceleration/mini_benchmark/metrics/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ py_strict_binary(
4747
deps = [
4848
":kl_divergence",
4949
"//tensorflow:tensorflow_py",
50+
"//tensorflow/lite/python:lite",
5051
"//tensorflow/lite/tools:flatbuffer_utils",
5152
],
5253
)
@@ -90,6 +91,7 @@ py_strict_binary(
9091
deps = [
9192
":kl_divergence",
9293
"//tensorflow:tensorflow_py",
94+
"//tensorflow/lite/python:lite",
9395
"//tensorflow/lite/tools:flatbuffer_utils",
9496
],
9597
)

tensorflow/lite/exper 10000 imental/acceleration/mini_benchmark/metrics/blazeface_metrics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# conversion in v2.
4040
import tensorflow.compat.v1 as tf
4141
from tensorflow.lite.experimental.acceleration.mini_benchmark.metrics import kl_divergence
42+
from tensorflow.lite.python import lite
4243
from tensorflow.lite.tools import flatbuffer_utils
4344

4445
parser = argparse.ArgumentParser(
@@ -107,7 +108,7 @@ def main(output_path):
107108
kld_metric = tf.reshape(kld_metric, [1], name='symmetric_kl_divergence')
108109
box_mse = tf.reshape(box_mse, [1], name='box_mse')
109110
sess = tf.compat.v1.Session()
110-
converter = tf.lite.TFLiteConverter.from_session(sess, [
111+
converter = lite.TFLiteConverter.from_session(sess, [
111112
expected_box_encodings, expected_scores, actual_box_encodings,
112113
actual_scores
113114
], [kld_metric, box_mse, ok])

tensorflow/lite/experimental/acceleration/mini_benchmark/metrics/mobilenet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
# conversion in v2.
2929
import tensorflow.compat.v1 as tf
3030
from tensorflow.lite.experimental.acceleration.mini_benchmark.metrics import kl_divergence
31+
from tensorflow.lite.python import lite
3132
from tensorflow.lite.tools import flatbuffer_utils
32-
3333
parser = argparse.ArgumentParser(
3434
description='Script to generate a metrics model for mobilenet v1.')
3535
parser.add_argument('output', help='Output filepath')
@@ -51,7 +51,7 @@ def main(output_path):
5151
ok = tf.reshape(
5252
tf.logical_and(kld_metric < 5.5, mse < 0.003), [1], name='ok')
5353
sess = tf.compat.v1.Session()
54-
converter = tf.lite.TFLiteConverter.from_session(sess, [
54+
converter = lite.TFLiteConverter.from_session(sess, [
5555
expected_scores,
5656
actual_scores,
5757
], [kld_metric, mse, ok])

tensorflow/lite/kernels/variants/py/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ py_strict_test(
2727
"//third_party/py/numpy",
2828
"//tensorflow:tensorflow_py",
2929
"//tensorflow/lite/python:interpreter",
30+
"//tensorflow/lite/python:lite",
3031
"//tensorflow/python/ops:list_ops",
3132
"//tensorflow/python/platform:test",
3233
],

tensorflow/lite/kernels/variants/py/end_to_end_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from tensorflow.lite.kernels.variants.py import register_list_ops_py
2020
from tensorflow.lite.python import interpreter as _interpreter
21+
from tensorflow.lite.python import lite
2122
from tensorflow.python.ops import list_ops
2223
from tensorflow.python.platform import googletest
2324

@@ -35,12 +36,12 @@ class ListOpsTest(parameterized.TestCase):
3536
def _get_interpreter_from_c_func(self, func):
3637
concrete_function_list = [func.get_concrete_function()]
3738

38-
converter = tf.lite.TFLiteConverter.from_concrete_functions(
39+
converter = lite.TFLiteConverterV2.from_concrete_functions(
3940
concrete_function_list
4041
)
4142
# Don't allow flex ops.
4243
converter.target_spec.supported_ops = [
43-
tf.lite.OpsSet.TFLITE_BUILTINS,
44+
lite.OpsSet.TFLITE_BUILTINS,
4445
]
4546
converter.allow_custom_ops = True
4647
converter.legalize_custom_tensor_list_ops = True

tensorflow/lite/python/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ py_strict_test(
6464
#internal proto upb dep
6565
"//third_party/py/numpy",
6666
"//tensorflow:tensorflow_py",
67+
"//tensorflow/lite/python:lite",
6768
"//tensorflow/lite/python/metrics",
6869
"//tensorflow/lite/python/testdata:_pywrap_test_registerer",
6970
"//tensorflow/python/framework:test_lib",
@@ -79,6 +80,7 @@ py_strict_binary(
7980
deps = [
8081
":tflite_convert_main_lib",
8182
"//tensorflow:tensorflow_py",
83+
"//tensorflow/lite/python:lite",
8284
"@absl_py//absl:app",
8385
],
8486
)
@@ -409,6 +411,7 @@ py_strict_test(
409411
#internal proto upb dep
410412
"//third_party/py/numpy",
411413
"//tensorflow:tensorflow_py",
414+
"//tensorflow/lite/python:lite",
412415
"//tensorflow/lite/tools:flatbuffer_utils",
413416
"//tensorflow/python/client:session",
414417
"//tensorflow/python/framework:convert_to_constants",
@@ -621,6 +624,7 @@ py_strict_test(
621624
":analyzer",
622625
#internal proto upb dep
623626
"//tensorflow:tensorflow_py",
627+
"//tensorflow/lite/python:lite",
624628
"//tensorflow/python/framework:test_lib",
625629
"//tensorflow/python/platform:client_testlib",
626630
"//tensorflow/python/platform:resource_loader",

tensorflow/lite/python/analyzer_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import tensorflow as tf
2222

2323
from tensorflow.lite.python import analyzer
24+
from tensorflow.lite.python import lite
2425
from tensorflow.python.framework import test_util
2526
from tensorflow.python.platform import resource_loader
2627
from tensorflow.python.platform import test
@@ -80,7 +81,7 @@ def testTxtWithFlatBufferModel(self):
8081
def func(x):
8182
return x + tf.cos(x)
8283

83-
converter = tf.lite.TFLiteConverter.from_concrete_functions(
84+
converter = lite.TFLiteConverterV2.from_concrete_functions(
8485
[func.get_concrete_function()], func)
8586
fb_model = converter.convert()
8687
mock_stdout = io.StringIO()
@@ -98,7 +99,7 @@ def testMlirWithFlatBufferModel(self):
9899
def func(x):
99100
return x + tf.cos(x)
100101

101-
converter = tf.lite.TFLiteConverter.from_concrete_functions(
102+
converter = lite.TFLiteConverterV2.from_concrete_functions(
102103
[func.get_concrete_function()], func)
103104
fb_model = converter.convert()
104105
mock_stdout = io.StringIO()
@@ -141,7 +142,7 @@ def sub(x, y):
141142
'sub': root.f2
142143
})
143144

144-
converter = tf.lite.TFLiteConverter.from_saved_model(tmp_dir)
145+
converter = lite.TFLiteConverterV2.from_saved_model(tmp_dir)
145146
fb_model = converter.convert()
146147
mock_stdout = io.StringIO()
147148
with test.mock.patch.object(sys, 'stdout', mock_stdout):
@@ -163,7 +164,7 @@ def testTxtWithoutInput(self):
163164
def func():
164165
return tf.cos(1.0)
165166

166-
converter = tf.lite.TFLiteConverter.from_concrete_functions(
167+
converter = lite.TFLiteConverterV2.from_concrete_functions(
167168
[func.get_concrete_function()], func)
168169
fb_model = converter.convert()
169170
mock_stdout = io.StringIO()
@@ -181,7 +182,7 @@ def testTxtWithEinsum(self):
181182
def func(lhs, rhs):
182183
return tf.einsum('ABD,DNH->ABNH', lhs, rhs)
183184

184-
converter = tf.lite.TFLiteConverter.from_concrete_functions(
185+
converter = lite.TFLiteConverterV2.from_concrete_functions(
185186
[func.get_concrete_function()], func)
186187
converter.unfold_batchmatmul = True
187188
fb_model = converter.convert()

tensorflow/lite/python/authoring/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ py_strict_test(
2626
":authoring",
2727
#internal proto upb dep
2828
"//tensorflow:tensorflow_py",
29+
"//tensorflow/lite/python:lite",
2930
],
3031
)

tensorflow/lite/python/interpreter_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
3030

3131
from tensorflow.lite.python import interpreter as interpreter_wrapper
32+
from tensorflow.lite.python import lite
3233
from tensorflow.lite.python.metrics import metrics
3334
from tensorflow.lite.python.testdata import _pywrap_test_registerer as test_registerer
3435
from tensorflow.python.framework import test_util
@@ -374,12 +375,12 @@ def TestSum(self, x):
374375
return tf.raw_ops.Sum(input=x, axis=[0])
375376

376377
test_model = TestModel()
377-
converter = tf.lite.TFLiteConverter.from_concrete_functions([
378+
converter = lite.TFLiteConverterV2.from_concrete_functions([
378379
test_model.TestSum.get_concrete_function(
379380
tf.TensorSpec([None], tf.float32))
380381
], test_model)
381382
model = converter.convert()
382-
interpreter = tf.lite.Interpreter(model_content=model)
383+
interpreter = lite.Interpreter(model_content=model)
383384
# Make sure that passing empty tensor doesn't cause any errors.
384385
interpreter.get_signature_runner()(x=tf.zeros([0], tf.float32))
385386

tensorflow/lite/python/lite_flex_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ def eval(self, x):
305305
to_save = m.eval.get_concrete_function()
306306
save_dir = os.path.join(self.get_temp_dir(), 'saved_model')
307307
tf.saved_model.save(m, save_dir, to_save)
308-
converter = tf.lite.TFLiteConverter.from_saved_model(save_dir)
308+
converter = lite.TFLiteConverterV2.from_saved_model(save_dir)
309309

310310
converter.target_spec.supported_ops = [
311-
tf.lite.OpsSet.TFLITE_BUILTINS,
312-
tf.lite.OpsSet.SELECT_TF_OPS,
311+
lite.OpsSet.TFLITE_BUILTINS,
312+
lite.OpsSet.SELECT_TF_OPS,
313313
]
314314
converter.experimental_enable_resource_variables = True
315315
tflite_model = converter.convert()

0 commit comments

Comments
 (0)
0