Skip to content

Commit 9f5ac25

Browse files
authored
No tensorflow 2 (#3548)
1 parent 1c2bae8 commit 9f5ac25

25 files changed

Lines changed: 1374 additions & 85 deletions

python/python_requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ absl_py
3030
ai-edge-litert
3131
bitarray
3232
mako
33+
matplotlib
3334
numpy
3435
pillow
3536
prettyprinter

python/python_requirements_3_10.txt

Lines changed: 304 additions & 0 deletions
Large diffs are not rendered by default.

python/python_requirements_3_11.txt

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

python/python_requirements_3_12.txt

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

python/python_requirements_3_13.txt

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

tensorflow/lite/micro/compression/BUILD

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ py_test(
109109
"metadata_py",
110110
"//:tflite_micro_shim",
111111
requirement("flatbuffers"),
112-
requirement("tensorflow"),
113112
],
114113
)
115114

@@ -162,7 +161,6 @@ py_test(
162161
"//tensorflow/lite/python:schema_py",
163162
requirement("bitarray"),
164163
requirement("numpy"),
165-
requirement("tensorflow"),
166164
],
167165
)
168166

@@ -184,7 +182,6 @@ py_test(
184182
deps = [
185183
":model_facade",
186184
":test_models",
187-
requirement("tensorflow"),
188185
],
189186
)
190187

@@ -204,7 +201,6 @@ py_test(
204201
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
205202
deps = [
206203
":spec",
207-
requirement("tensorflow"),
208204
],
209205
)
210206

@@ -224,7 +220,6 @@ py_test(
224220
deps = [
225221
":spec",
226222
":spec_builder",
227-
requirement("tensorflow"),
228223
],
229224
)
230225

@@ -247,7 +242,6 @@ py_test(
247242
deps = [
248243
":test_models",
249244
"//tensorflow/lite/python:schema_py",
250-
requirement("tensorflow"),
251245
],
252246
)
253247

tensorflow/lite/micro/compression/compress_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import bitarray
1616
import bitarray.util
1717
import numpy as np
18-
import tensorflow as tf
18+
import unittest
1919

2020
from tflite_micro.tensorflow.lite.micro.compression import compress
2121
from tflite_micro.tensorflow.lite.micro.compression import metadata_py_generated as schema
@@ -25,7 +25,7 @@
2525
from tflite_micro.tensorflow.lite.python import schema_py_generated as tflite
2626

2727

28-
class TestPackIndices(tf.test.TestCase):
28+
class TestPackIndices(unittest.TestCase):
2929

3030
def test_basic_case(self):
3131
indices = np.array([1, 2, 3])
@@ -112,7 +112,7 @@ def test_bitwidth_7(self):
112112
self.assertEqual(result, expected_bytes)
113113

114114

115-
class TestPackLookupTables(tf.test.TestCase):
115+
class TestPackLookupTables(unittest.TestCase):
116116

117117
def test_int16_positive(self):
118118
tables = [np.array([0x1234, 0x5678], dtype='<i2')]
@@ -361,7 +361,7 @@ def test_multiple_tables_with_padding(self):
361361
# yapf: enable
362362

363363

364-
class TestsCompression(tf.test.TestCase):
364+
class TestsCompression(unittest.TestCase):
365365
"""Tests with the uncompressed model."""
366366

367367
@classmethod
@@ -435,7 +435,7 @@ def test_no_axis(self):
435435
lambda: compress.compress(self.flatbuffer, specs))
436436

437437

438-
class TestLutCompressedArray(tf.test.TestCase):
438+
class TestLutCompressedArray(unittest.TestCase):
439439

440440
def test_bitwidth(self):
441441
"""Bitwidth is determined from index values."""
@@ -453,7 +453,7 @@ def test_bitwidth(self):
453453
self.assertEqual(a.index_bitwidth, 1)
454454

455455

456-
class TestCompressedModel(tf.test.TestCase):
456+
class TestCompressedModel(unittest.TestCase):
457457
"""Test the compressed model."""
458458

459459
@classmethod
@@ -538,7 +538,7 @@ def test_compressed_uint8(self):
538538
self.assertEqual(indices, expected_indices)
539539

540540
expected_values = np.array(range(16), dtype="<u1")
541-
self.assertAllEqual(values, expected_values)
541+
np.testing.assert_array_equal(values, expected_values)
542542

543543
def test_compressed_int8(self):
544544
bitwidth, indices, values = self._get_compressed(subgraph=0, tensor=1)
@@ -555,7 +555,7 @@ def test_compressed_int8(self):
555555
self.assertEqual(indices, expected_indices)
556556

557557
expected_values = np.array(range(-16, 0), dtype="<i1")
558-
self.assertAllEqual(values, expected_values)
558+
np.testing.assert_array_equal(values, expected_values)
559559

560560
def test_compressed_int16(self):
561561
bitwidth, indices, values = self._get_compressed(subgraph=0, tensor=2)
@@ -572,7 +572,7 @@ def test_compressed_int16(self):
572572
self.assertEqual(indices, expected_indices)
573573

574574
expected_values = np.array(range(-1616, -1600), dtype="<i2")
575-
self.assertAllEqual(values, expected_values)
575+
np.testing.assert_array_equal(values, expected_values)
576576

577577
def test_compressed_int32(self):
578578
bitwidth, indices, values = self._get_compressed(subgraph=0, tensor=3)
@@ -589,7 +589,7 @@ def test_compressed_int32(self):
589589
self.assertEqual(indices, expected_indices)
590590

591591
expected_values = np.array(range(-160_016, -160_000), dtype="<i4")
592-
self.assertAllEqual(values, expected_values)
592+
np.testing.assert_array_equal(values, expected_values)
593593

594594
def test_axis_1(self):
595595
"""Compression along quanitzation_dimension == 1."""
@@ -607,7 +607,7 @@ def test_axis_1(self):
607607
self.assertEqual(indices, expected_indices)
608608

609609
expected_values = np.array(range(1, 21), dtype=np.dtype("<i2"))
610-
self.assertAllEqual(values, expected_values)
610+
np.testing.assert_array_equal(values, expected_values)
611611

612612
def test_axis_0(self):
613613
"""Compression along quanitzation_dimension == 0."""
@@ -626,7 +626,7 @@ def test_axis_0(self):
626626
self.assertEqual(indices, expected_indices)
627627

628628
expected_values = np.array(range(1, 21), dtype=np.dtype("<i2"))
629-
self.assertAllEqual(values, expected_values)
629+
np.testing.assert_array_equal(values, expected_values)
630630

631631
def test_per_tensor(self):
632632
"""Compression with one value table per tensor."""
@@ -645,8 +645,8 @@ def test_per_tensor(self):
645645
self.assertEqual(indices, expected_indices)
646646

647647
expected_values = np.array(range(1, 5), dtype=np.dtype("<i2"))
648-
self.assertAllEqual(values, expected_values)
648+
np.testing.assert_array_equal(values, expected_values)
649649

650650

651651
if __name__ == "__main__":
652-
tf.test.main()
652+
unittest.main()

tensorflow/lite/micro/compression/metadata_test.py

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

1919
from dataclasses import dataclass
2020
import flatbuffers
21-
import tensorflow as tf
21+
import unittest
2222

2323
# `.*_generated` is the name of the module created by the Bazel rule
2424
# `flatbuffer_py_library' based on the schema.
@@ -48,7 +48,7 @@ class _LutTensor:
4848
_EXPECTED_SCHEMA_VERSION = 1
4949

5050

51-
class TestReadEqualsWrite(tf.test.TestCase):
51+
class TestReadEqualsWrite(unittest.TestCase):
5252

5353
def setUp(self):
5454
"""Sets up the test by creating a flatbuffer using the metadata schema.
@@ -108,4 +108,4 @@ def testPrintFlatbufferLen(self):
108108

109109

110110
if __name__ == "__main__":
111-
tf.test.main()
111+
unittest.main()

tensorflow/lite/micro/compression/model_facade_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import numpy as np
16-
import tensorflow as tf
16+
import unittest
1717
from tflite_micro.tensorflow.lite.python import schema_py_generated as tflite
1818
from tflite_micro.tensorflow.lite.micro.compression import model_facade
1919
from tflite_micro.tensorflow.lite.micro.compression import test_models
@@ -96,7 +96,7 @@
9696
}
9797

9898

99-
class TestModelFacade(tf.test.TestCase):
99+
class TestModelFacade(unittest.TestCase):
100100

101101
def setUp(self):
102102
self.flatbuffer = test_models.build(TEST_MODEL)
@@ -116,7 +116,7 @@ def testMetadata(self):
116116
self.assertNotIn("metadata2", self.facade.metadata)
117117

118118

119-
class TestTensors(tf.test.TestCase):
119+
class TestTensors(unittest.TestCase):
120120

121121
def setUp(self):
122122
flatbuffer = test_models.build(TEST_MODEL)
@@ -135,10 +135,10 @@ def testNameIsString(self):
135135
def testTensors(self):
136136
for id, attrs in self.test_tensors:
137137
tensor = self.facade.subgraphs[0].tensors[id]
138-
self.assertAllEqual(tensor.shape, attrs["shape"])
138+
np.testing.assert_array_equal(tensor.shape, attrs["shape"])
139139
data = TEST_MODEL["buffers"][attrs["buffer"]]
140-
self.assertAllEqual(tensor.array, data.reshape(tensor.shape))
140+
np.testing.assert_array_equal(tensor.array, data.reshape(tensor.shape))
141141

142142

143143
if __name__ == "__main__":
144-
tf.test.main()
144+
unittest.main()

tensorflow/lite/micro/compression/spec_builder_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#
1515
"""Tests for the compression spec builder."""
1616

17-
import tensorflow as tf
17+
import unittest
1818

1919
from tflite_micro.tensorflow.lite.micro.compression import spec
2020
from tflite_micro.tensorflow.lite.micro.compression import spec_builder
2121

2222

23-
class SpecBuilderTest(tf.test.TestCase):
23+
class SpecBuilderTest(unittest.TestCase):
2424

2525
def test_basic_builder_pattern(self):
2626
"""Test basic fluent builder usage."""
@@ -109,4 +109,4 @@ def test_builder_produces_same_type_as_parse_yaml(self):
109109

110110

111111
if __name__ == "__main__":
112-
tf.test.main()
112+
unittest.main()

0 commit comments

Comments
 (0)