File tree Expand file tree Collapse file tree 5 files changed +79
-5
lines changed
tensorflow/lite/micro/compression Expand file tree Collapse file tree 5 files changed +79
-5
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,7 @@ py_package(
130
130
# in the tflm tree.
131
131
packages = [
132
132
"python.tflite_micro" ,
133
+ "tensorflow.lite.micro.compression" ,
133
134
"tensorflow.lite.micro.tools.generate_test_for_model" ,
134
135
"tensorflow.lite.python" ,
135
136
"tensorflow.lite.tools.flatbuffer_utils" ,
@@ -138,6 +139,7 @@ py_package(
138
139
":postinstall_check" ,
139
140
":runtime" ,
140
141
":version" ,
142
+ "//tensorflow/lite/micro/compression" ,
141
143
],
142
144
)
143
145
@@ -223,8 +225,10 @@ py_wheel(
223
225
":local" : "py3" ,
224
226
}),
225
227
requires = [
228
+ "bitarray" ,
226
229
"flatbuffers" ,
227
230
"numpy" ,
231
+ "pyyaml" ,
228
232
"tensorflow" ,
229
233
],
230
234
stamp = 1 , # 1 == always stamp
Original file line number Diff line number Diff line change 24
24
# Unambiguously identify the source used to build the package.
25
25
from tflite_micro .python .tflite_micro ._version import __version__
26
26
27
- # Ordered after `runtime` to avoid a circular dependency
27
+ # Provide a convenient alias for the compression module
28
+ from tflite_micro .tensorflow .lite .micro import compression
29
+
30
+ # Ordered after `runtime` and `compression` to avoid circular dependencies
28
31
from tflite_micro .python .tflite_micro import postinstall_check
Original file line number Diff line number Diff line change 19
19
# in the Python installation environment rather than to locations in the tflm
20
20
# source tree.
21
21
from tflite_micro import runtime
22
+ from tflite_micro import compression
22
23
23
24
import numpy as np
24
25
import pkg_resources
25
26
import sys
27
+ import tempfile
28
+ import os
26
29
27
30
28
- def passed ():
31
+ def runtime_test ():
32
+ """Test the runtime interpreter functionality."""
29
33
# Create an interpreter with a sine model
30
34
model = pkg_resources .resource_filename (__name__ , "sine_float.tflite" )
31
35
interpreter = runtime .Interpreter .from_file (model )
@@ -49,5 +53,23 @@ def infer(x):
49
53
return np .allclose (outputs , goldens , atol = 0.05 )
50
54
51
55
56
+ def compression_test ():
57
+ """Test that the compression module is available and functional."""
58
+
59
+ # Test that compress function is available
60
+ # We don't actually compress here as it requires a properly structured model
61
+ # with compressible tensors, but we verify the function is importable
62
+ assert callable (compression .compress )
63
+
64
+ return True
65
+
66
+
67
+ def passed ():
68
+ """Run all postinstall checks."""
69
+ runtime_passed = runtime_test ()
70
+ compression_passed = compression_test ()
71
+ return runtime_passed and compression_passed
72
+
73
+
52
74
if __name__ == "__main__" :
53
75
sys .exit (0 if passed () else 1 )
Original file line number Diff line number Diff line change 8
8
"flatbuffer_cc_library" ,
9
9
"flatbuffer_py_library" ,
10
10
)
11
- load ("@rules_python//python:defs.bzl" , "py_test" )
11
+ load ("@rules_python//python:defs.bzl" , "py_binary" , "py_library" , " py_test" )
12
12
load ("@tflm_pip_deps//:requirements.bzl" , "requirement" )
13
13
14
14
package (
@@ -17,6 +17,15 @@ package(
17
17
],
18
18
)
19
19
20
+ py_library (
21
+ name = "compression" ,
22
+ srcs = ["__init__.py" ],
23
+ deps = [
24
+ ":compress_lib" ,
25
+ ":spec" ,
26
+ ],
27
+ )
28
+
20
29
flatbuffer_cc_library (
21
30
# Generates the header-only library "metadata_generated.h", used to read
22
31
# the metadata flatbuffer.
@@ -96,8 +105,8 @@ py_test(
96
105
],
97
106
)
98
107
99
- py_binary (
100
- name = "compress " ,
108
+ py_library (
109
+ name = "compress_lib " ,
101
110
srcs = [
102
111
"compress.py" ,
103
112
],
@@ -113,6 +122,16 @@ py_binary(
113
122
],
114
123
)
115
124
125
+ py_binary (
126
+ name = "compress" ,
127
+ srcs = [
128
+ "compress.py" ,
129
+ ],
130
+ deps = [
131
+ ":compress_lib" ,
132
+ ],
133
+ )
134
+
116
135
py_test (
117
136
name = "compress_test" ,
118
137
size = "small" ,
Original file line number Diff line number Diff line change
1
+ # Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """TensorFlow Lite for Microcontrollers compression module."""
15
+
16
+ # This __init__.py file exists to make compression features available as part
17
+ # of the tflite_micro Python package.
18
+ #
19
+ # Usage example:
20
+ # from tflite_micro import compression
21
+ # ...
22
+
23
+ from .compress import compress
24
+ from .spec import parse_yaml
25
+
26
+ __all__ = ["compress" , "parse_yaml" ]
You can’t perform that action at this time.
0 commit comments