From 54eec806272b7574a0757c77a913a369a9ecdc70 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 21 Nov 2023 12:29:38 +0000 Subject: MLIA-835 Invalid JSON output TFLiteConverter was producing log messages in the output that was not possible to capture and redirect to logging. The solution/workaround is to run it as a subprocess. This change required some refactoring around existing invocations of the converter. Change-Id: I394bd0d49d36e6686cfcb9d658e4aad05326cb87 Signed-off-by: Gergely Nagy --- src/mlia/nn/rewrite/core/train.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/mlia/nn/rewrite/core/train.py') diff --git a/src/mlia/nn/rewrite/core/train.py b/src/mlia/nn/rewrite/core/train.py index 6345f07..72b8f48 100644 --- a/src/mlia/nn/rewrite/core/train.py +++ b/src/mlia/nn/rewrite/core/train.py @@ -34,9 +34,9 @@ from mlia.nn.rewrite.core.utils.numpy_tfrecord import numpytf_count from mlia.nn.rewrite.core.utils.numpy_tfrecord import numpytf_read from mlia.nn.rewrite.core.utils.parallel import ParallelTFLiteModel from mlia.nn.tensorflow.config import TFLiteModel +from mlia.nn.tensorflow.tflite_convert import convert_to_tflite from mlia.nn.tensorflow.tflite_graph import load_fb from mlia.nn.tensorflow.tflite_graph import save_fb -from mlia.nn.tensorflow.utils import get_tflite_converter from mlia.utils.logging import log_action @@ -499,11 +499,7 @@ def save_as_tflite( keras_model.input.set_shape(orig_shape) with fixed_input(keras_model, input_shape) as fixed_model: - converter = get_tflite_converter(fixed_model, quantized=model_is_quantized) - tflite_model = converter.convert() - - with open(filename, "wb") as file: - file.write(tflite_model) + convert_to_tflite(fixed_model, model_is_quantized, Path(filename)) # Now fix the shapes and names to match those we expect flatbuffer = load_fb(filename) -- cgit v1.2.1