I am having an issue converting TF model into TF lite.
Running this command works perfectly: # Save tf model for tflite converting
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite
but when I attempt to run
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite
I am met with an error
pi@raspberrypi:~/tensorflow-yolov4-tflite $ python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite
2020-10-30 10:52:33.151754: I tensorflow/core/grappler/devices.cc:78] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA or ROCm support)
2020-10-30 10:52:33.152102: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-10-30 10:52:34.898127: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816] Optimization results for grappler item: graph_to_optimize
2020-10-30 10:52:34.898261: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818] function_optimizer: Graph size after: 2777 nodes (2232), 2811 edges (2265), time = 356.29ms.
2020-10-30 10:52:34.898333: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818] function_optimizer: function_optimizer did nothing. time = 4.518ms.
Traceback (most recent call last):
File "convert_tflite.py", line 76, in
app.run(main)
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 303, in run
_run_main(main, args)
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "convert_tflite.py", line 71, in main
save_tflite()
File "convert_tflite.py", line 45, in save_tflite
tflite_model = converter.convert()
File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 1076, in convert
return super(TFLiteConverterV2, self).convert()
File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 878, in convert
self._funcs[0], lower_control_flow=False))
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 1109, in convert_variables_to_constants_v2_as_graph
converted_input_indices)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 1001, in _construct_concrete_function
new_output_names)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 650, in function_from_graph_def
wrapped_import = wrap_function(_imports_graph_def, [])
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 628, in wrap_function
collections={}),
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
func_outputs = python_func(*func_args, func_kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 87, in call
return self.call_with_variable_creator_scope(self._fn)(*args, *kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 93, in wrapped
return fn(args, kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 648, in _imports_graph_def
importer.import_graph_def(graph_def, name="")
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/importer.py", line 405, in import_graph_def
producer_op_list=producer_op_list)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/importer.py", line 494, in _import_graph_def_internal
with c_api_util.tf_buffer(graph_def.SerializeToString()) as serialized:
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1097, in SerializeToString
return self.SerializePartialToString(kwargs)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1106, in SerializePartialToString
self._InternalSerialize(out.write, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 763, in EncodeRepeatedField
element._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 828, in EncodeField
encode_message(write, entry_msg, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1123, in InternalSerialize
write_bytes, self.value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 727, in EncodeField
return write(value)
MemoryError
I am having an issue converting TF model into TF lite.
Running this command works perfectly: # Save tf model for tflite converting python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite
but when I attempt to run python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite
I am met with an error
pi@raspberrypi:~/tensorflow-yolov4-tflite $ python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite 2020-10-30 10:52:33.151754: I tensorflow/core/grappler/devices.cc:78] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA or ROCm support) 2020-10-30 10:52:33.152102: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session 2020-10-30 10:52:34.898127: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816] Optimization results for grappler item: graph_to_optimize 2020-10-30 10:52:34.898261: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818] function_optimizer: Graph size after: 2777 nodes (2232), 2811 edges (2265), time = 356.29ms. 2020-10-30 10:52:34.898333: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818] function_optimizer: function_optimizer did nothing. time = 4.518ms. Traceback (most recent call last): File "convert_tflite.py", line 76, in
app.run(main)
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 303, in run
_run_main(main, args)
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "convert_tflite.py", line 71, in main
save_tflite()
File "convert_tflite.py", line 45, in save_tflite
tflite_model = converter.convert()
File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 1076, in convert
return super(TFLiteConverterV2, self).convert()
File "/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/lite.py", line 878, in convert
self._funcs[0], lower_control_flow=False))
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 1109, in convert_variables_to_constants_v2_as_graph
converted_input_indices)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 1001, in _construct_concrete_function
new_output_names)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 650, in function_from_graph_def
wrapped_import = wrap_function(_imports_graph_def, [])
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 628, in wrap_function
collections={}),
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
func_outputs = python_func(*func_args, func_kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 87, in call
return self.call_with_variable_creator_scope(self._fn)(*args, *kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 93, in wrapped
return fn(args, kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/wrap_function.py", line 648, in _imports_graph_def
importer.import_graph_def(graph_def, name="")
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/importer.py", line 405, in import_graph_def
producer_op_list=producer_op_list)
File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/importer.py", line 494, in _import_graph_def_internal
with c_api_util.tf_buffer(graph_def.SerializeToString()) as serialized:
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1097, in SerializeToString
return self.SerializePartialToString(kwargs)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1106, in SerializePartialToString
self._InternalSerialize(out.write, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 763, in EncodeRepeatedField
element._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 828, in EncodeField
encode_message(write, entry_msg, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1123, in InternalSerialize
write_bytes, self.value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 769, in EncodeField
return value._InternalSerialize(write, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/python_message.py", line 1126, in InternalSerialize
field_descriptor._encoder(write_bytes, field_value, deterministic)
File "/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/encoder.py", line 727, in EncodeField
return write(value)
MemoryError
I am trying to convert it on Raspberry Pi 4 , 4GB And I am following a video guide on : https://youtu.be/iPwepy-SVCQ?t=973
Thank you