Skip to content

Instantly share code, notes, and snippets.

@petewarden
Created February 27, 2020 23:55
Show Gist options
  • Save petewarden/493294425ac522f00ff45342c71939d7 to your computer and use it in GitHub Desktop.
Save petewarden/493294425ac522f00ff45342c71939d7 to your computer and use it in GitHub Desktop.
Example of converting a .cc TensorFlow Lite C data array file back into a binary flatbuffer on disk
import re
output_data = bytearray()
with open('tensorflow/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc', 'r') as file:
for line in file:
values_match = re.match(r"\W*(0x[0-9a-fA-F,x ]+).*", line)
if values_match:
list_text = values_match.group(1)
values_text = filter(None, list_text.split(","))
values = [int(x, base=16) for x in values_text]
output_data.extend(values)
with open('converted.tfl', 'wb') as output_file:
output_file.write(output_data)
@petewarden
Copy link
Author

What error are you having when you try to open the result with Netron?

@olivia1205
Copy link

olivia1205 commented Feb 29, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment