Skip to content

Commit b17bb64

Browse files
committed
feat(compression): implement model_editor for TFLite model manipulation
Implement unified module for creating, reading, and modifying TFLite models with a clean API. The module eliminates manual index tracking and buffer management through automatic bookkeeping, supporting both declarative and imperative construction styles. Core design uses first-class Buffer objects that can be shared between tensors, with automatic deduplication during build. Tensors reference Buffers directly, matching the TFLite schema structure. The compiler automatically extracts inline tensor declarations, builds operator code tables, and handles index assignment according to TFLite conventions. Supports quantization parameters (per-tensor and per-channel), metadata key-value pairs, and read-modify-write workflows. The read() function preserves the object graph structure, enabling models to be read, modified, and rebuilt. Add comprehensive test coverage for core functionality, advanced features, quantization, and modification workflows.
1 parent 9cbf6e0 commit b17bb64

File tree

3 files changed

+1314
-0
lines changed

3 files changed

+1314
-0
lines changed

tensorflow/lite/micro/compression/BUILD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,28 @@ py_test(
237237
],
238238
)
239239

240+
py_library(
241+
name = "model_editor",
242+
srcs = ["model_editor.py"],
243+
deps = [
244+
"//tensorflow/lite/python:schema_py",
245+
requirement("flatbuffers"),
246+
requirement("numpy"),
247+
],
248+
)
249+
250+
py_test(
251+
name = "model_editor_test",
252+
size = "small",
253+
srcs = ["model_editor_test.py"],
254+
deps = [
255+
":model_editor",
256+
"//tensorflow/lite/python:schema_py",
257+
requirement("numpy"),
258+
requirement("tensorflow-cpu"),
259+
],
260+
)
261+
240262
py_binary(
241263
name = "view",
242264
srcs = [

0 commit comments

Comments
 (0)