This an experimental port of TensorFlow Lite aimed at micro controllers and other devices with only kilobytes of memory. It doesn't require any operating system support, any standard C or C++ libraries, or dynamic memory allocation, so it's designed to be portable even to 'bare metal' systems. The core runtime fits in 16KB on a Cortex M3, and with enough operators to run a speech keyword detection model, takes up a total of 22KB.
This an experimental port of TensorFlow Lite aimed at micro controllers and other devices with only kilobytes of memory. It doesn't require any operating system support, any standard C or C++ libraries, or dynamic memory allocation, so it's designed to be portable even to 'bare metal' systems. The core runtime fits in 16KB on a Cortex M3, and with enough operators to run a speech keyword detection model, takes up a total of 22KB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define call_test | |
| %: % | |
| echo "foo" | |
| foo/%: % | |
| echo "foo" | |
| endef | |
| $(call call_test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To convert from .ogg files to .wavs: | |
| # find . -iname "*.ogg" -print0 | xargs -0 basename -s .ogg | xargs -I {} ffmpeg -i {}.ogg -ar 16000 ../converted_early_wavs/{}.wav | |
| # Then run the extract_loudest xcode project to get one-second clips. | |
| import glob | |
| import os | |
| import re | |
| import shutil | |
| data_index = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def StripTfliteFile(tflite_input, tflite_output): | |
| """Given 'tflite_input`, write stripped version, 'tflite_output'.""" | |
| if not os.path.exists(tflite_input): | |
| raise RuntimeError("Invalid filename %r" % tflite_input) | |
| with open(tflite_input, "rb") as file_handle: | |
| file_data = bytearray(file_handle.read()) | |
| model_obj = schema_fb.Model.GetRootAsModel(file_data, 0) | |
| model = schema_fb.ModelT.InitFromObj(model_obj) | |
| model.description = "" | |
| for subgraph in model.subgraphs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ============================================================================== | |
| """LSTM quantization with python.""" | |
| from __future__ import absolute_import | |
| from __future__ import division | |
| from __future__ import print_function | |
| import pathlib | |
| from absl import app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # By Pete Warden, @petewarden | |
| # To use this, open ~/.bashrc in your editor of choice, | |
| # and place these settings at the end. | |
| # Based on https://unix.stackexchange.com/a/48113 and | |
| # https://blog.sanctum.geek.nz/better-bash-history/ | |
| # Ignore both duplicate commands, and those that start with a space. | |
| HISTCONTROL=ignoreboth | |
| # Append to the history file, don't overwrite it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef INCLUDE_TRACE_H | |
| #define INCLUDE_TRACE_H | |
| #include <stdio.h> | |
| #include <stdint.h> | |
| #define TRACE_STR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%s\n", __LINE__, variable); } while (0) | |
| #define TRACE_INT(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%d\n", __LINE__, variable); } while (0) | |
| #define TRACE_PTR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=0x%016lx\n", __LINE__, (uint64_t)(variable)); } while (0) | |
| #define TRACE_SIZ(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%zu\n", __LINE__, variable); } while (0) |