mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Merge branch 'tensorflow' into HackStrap
This commit is contained in:
commit
ec98c13e24
13
Makefile
13
Makefile
@ -65,6 +65,7 @@ LIBS?=
|
||||
DEFINES?=
|
||||
CFLAGS?=-Wall -Wextra -Wconversion -Werror=implicit-function-declaration -fno-strict-aliasing -g
|
||||
CFLAGS+=-Wno-expansion-to-defined # remove warnings created by Nordic's libs
|
||||
CCFLAGS?= # specific flags when compiling cc files
|
||||
LDFLAGS?=-Winline -g
|
||||
OPTIMIZEFLAGS?=
|
||||
#-fdiagnostics-show-option - shows which flags can be used with -Werror
|
||||
@ -272,6 +273,7 @@ src/jsspi.c \
|
||||
src/jshardware_common.c \
|
||||
$(WRAPPERFILE)
|
||||
CPPSOURCES =
|
||||
CCSOURCES =
|
||||
|
||||
ifdef CFILE
|
||||
WRAPPERSOURCES += $(CFILE)
|
||||
@ -578,6 +580,10 @@ ifeq ($(USE_WIO_LTE),1)
|
||||
SOURCES += targets/stm32/stm32_ws2812b_driver.c
|
||||
endif
|
||||
|
||||
ifeq ($(USE_TENSORFLOW),1)
|
||||
include make/misc/tensorflow.make
|
||||
endif
|
||||
|
||||
|
||||
endif # BOOTLOADER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DON'T USE STUFF ABOVE IN BOOTLOADER
|
||||
|
||||
@ -593,6 +599,7 @@ include make/family/$(FAMILY).make
|
||||
endif
|
||||
# =========================================================================
|
||||
|
||||
|
||||
ifdef USB
|
||||
DEFINES += -DUSB
|
||||
endif
|
||||
@ -601,7 +608,7 @@ PININFOFILE=$(GENDIR)/jspininfo
|
||||
SOURCES += $(PININFOFILE).c
|
||||
|
||||
SOURCES += $(WRAPPERSOURCES) $(TARGETSOURCES)
|
||||
SOURCEOBJS = $(SOURCES:.c=.o) $(CPPSOURCES:.cpp=.o)
|
||||
SOURCEOBJS = $(SOURCES:.c=.o) $(CPPSOURCES:.cpp=.o) $(CCSOURCES:.cc=.o)
|
||||
OBJS = $(PRECOMPILED_OBJS) $(SOURCEOBJS)
|
||||
|
||||
|
||||
@ -720,6 +727,10 @@ quiet_obj_to_bin= GEN $(PROJ_NAME).$2
|
||||
@echo $($(quiet_)compile)
|
||||
@$(call compile)
|
||||
|
||||
.cc.o: %.cc $(PLATFORM_CONFIG_FILE) $(PININFOFILE).h
|
||||
@echo $($(quiet_)compile)
|
||||
@$(CC) $(CCFLAGS) $(CFLAGS) $< -o $@
|
||||
|
||||
.cpp.o: $(PLATFORM_CONFIG_FILE) $(PININFOFILE).h
|
||||
@echo $($(quiet_)compile)
|
||||
@$(call compile)
|
||||
|
||||
@ -22,6 +22,7 @@ info = {
|
||||
'build' : {
|
||||
'libraries' : [
|
||||
'NET',
|
||||
'TENSORFLOW',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
|
||||
203
libs/tensorflow/LICENSE
Normal file
203
libs/tensorflow/LICENSE
Normal file
@ -0,0 +1,203 @@
|
||||
Copyright 2019 The TensorFlow Authors. All rights reserved.
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
142
libs/tensorflow/README.md
Normal file
142
libs/tensorflow/README.md
Normal file
@ -0,0 +1,142 @@
|
||||
Tensorflow for Espruino
|
||||
=======================
|
||||
|
||||
Tensorflow code is Licensed under the Apache License. See `LICENSE` for more info.
|
||||
|
||||
Created with:
|
||||
|
||||
```Bash
|
||||
# https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro
|
||||
git clone https://github.com/tensorflow/tensorflow --depth=1
|
||||
mv tensorflow git-tensorflow
|
||||
cd git-tensorflow
|
||||
make -f tensorflow/lite/experimental/micro/tools/make/Makefile
|
||||
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=make TAGS="disco_f746ng" generate_projects
|
||||
cp -R tensorflow/lite/experimental/micro/tools/make/gen/make_x86_64/prj/hello_world/make/* ..
|
||||
cd ..
|
||||
mv tensorflow/tensorflow/lite/experimental/micro/examples/hello_world/* .
|
||||
```
|
||||
|
||||
## Actually using it
|
||||
|
||||
Follow the steps here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/hello_world/create_sine_model.ipynb
|
||||
|
||||
Then right at the end when you have your model, do:
|
||||
|
||||
```Python
|
||||
import base64;
|
||||
print("var model=atob(\""+base64.b64encode(tflite_model)+"\");")
|
||||
```
|
||||
|
||||
To output to base64 that you can easily stick in your code.
|
||||
|
||||
And to use it, do something like:
|
||||
|
||||
```JS
|
||||
var model=atob("GAAAAFRGTDMAAA4AGAAEAAgADAAQABQADgAAAAMAAADsCQAAuAUAAKAFAAAEAAAACwAAAJAFAAB8BQAAJAUAANQEAADMBAAAxAQAALwEAABsBAAAXAAAAAwAAAAEAAAAePb//7b6//8EAAAAQAAAAJ4IZD5QVk0+7cXIPkq+Er8xYmi8i2/MPqSmNL4qZ529BkrJPsPwij08RhC/GISaPuFzVD5EElI+BF7yvgBVWz4C+///BAAAAAAEAADy1BE+hO4/PpbYQL5lm62+Of0OvqzJgT6emCU+N++UvGqNxr4E0iC+4KYUPWwbhb5x7CC9a6WBPqhwhb5h/qw+nsY4vtWAXb6Mjwa8fL+nPfqwjj4yjtU8vxOaPpw0Tj643ZQ+dEUkPCglib1csyS+V3pqPm3mj75NqYs+sw0xPucVkb4sMBm+Fy3DPbxymL3qREg+7ZoVvowzlz0K6sm+lNNoPmBunr2AD6i8St+MvgJSlD4awpw+1JWxvhaUv7xropi+lvRdPX9dkr6rZKy+rv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84AAAABwAAAAwAAAAEAAAAHP7//x4AAABzZXF1ZW50aWFsL2RlbnNlXzEvTWF0TXVsX2JpYXMAAAEAAAAQAAAAbv7//0wAAAAIAAAADAAAAAQAAABg/v//MgAAAHNlcXVlbnRpYWwvZGVuc2VfMS9NYXRNdWwvUmVhZFZhcmlhYmxlT3AvdHJhbnNwb3NlAAACAAAAEAAAABAAAADK/v//MAAAAAoAAAAMAAAABAAAALz+//8VAAAAc2VxdWVudGlhbC9kZW5zZS9SZWx1AAAAAgAAAAEAAAAQAAAACv///zgAAAADAAAADAAAAAQAAAD8/v//HAAAAHNlcXVlbnRpYWwvZGVuc2UvTWF0TXVsX2JpYXMAAAAAAQAAABAAAABO////TAAAAAkAAAAMAAAABAAAAED///8wAAAAc2VxdWVudGlhbC9kZW5zZS9NYXRNdWwvUmVhZFZhcmlhYmxlT3AvdHJhbnNwb3NlAAAAAAIAAAAQAAAAAQAAAKr///9EAAAABQAAACwAAAAMAAAACAAMAAQACAAIAAAAEAAAAAQAAAABAAAAAAB/QwEAAAAAAAAACwAAAGRlbnNlX2lucHV0AAIAAAABAAAAAQAAAAAADgAUAAQAAAAIAAwAEAAOAAAAKAAAAAYAAAAQAAAACAAAAAQABAAEAAAACAAAAElkZW50aXR5AAAAAAIAAAABAAAAAQAAAAEAAAAQAAAAAAAKAAwABwAAAAgACgAAAAAAAAkDAAAA");
|
||||
|
||||
|
||||
var tf = require("tensorflow").create(2048, model);
|
||||
tf.getInput()[0] = x;
|
||||
tf.invoke();
|
||||
print(tf.getOutput()[0]);
|
||||
```
|
||||
|
||||
Example code (based off the tutorial linked above) to do the training is:
|
||||
|
||||
```Python
|
||||
import tensorflow as tf
|
||||
# Numpy is a math library
|
||||
import numpy as np
|
||||
# Matplotlib is a graphing library
|
||||
import matplotlib.pyplot as plt
|
||||
# math is Python's math library
|
||||
import math
|
||||
|
||||
# We'll generate this many sample datapoints
|
||||
SAMPLES = 1000
|
||||
|
||||
# Set a "seed" value, so we get the same random numbers each time we run this
|
||||
# notebook
|
||||
np.random.seed(1337)
|
||||
|
||||
# Generate a uniformly distributed set of random numbers in the range from
|
||||
# 0 to 2pi, which covers a complete sine wave oscillation
|
||||
x_values = np.random.uniform(low=0, high=2*math.pi, size=SAMPLES)
|
||||
|
||||
# Shuffle the values to guarantee they're not in order
|
||||
np.random.shuffle(x_values)
|
||||
|
||||
# Calculate the corresponding sine values
|
||||
y_values = np.sin(x_values)
|
||||
|
||||
# Add a small random number to each y value
|
||||
y_values += 0.1 * np.random.randn(*y_values.shape)
|
||||
|
||||
# We'll use 60% of our data for training and 20% for testing. The remaining 20%
|
||||
# will be used for validation. Calculate the indices of each section.
|
||||
TRAIN_SPLIT = int(0.6 * SAMPLES)
|
||||
TEST_SPLIT = int(0.2 * SAMPLES + TRAIN_SPLIT)
|
||||
|
||||
# Use np.split to chop our data into three parts.
|
||||
# The second argument to np.split is an array of indices where the data will be
|
||||
# split. We provide two indices, so the data will be divided into three chunks.
|
||||
x_train, x_test, x_validate = np.split(x_values, [TRAIN_SPLIT, TEST_SPLIT])
|
||||
y_train, y_test, y_validate = np.split(y_values, [TRAIN_SPLIT, TEST_SPLIT])
|
||||
|
||||
# Double check that our splits add up correctly
|
||||
assert (x_train.size + x_validate.size + x_test.size) == SAMPLES
|
||||
|
||||
# We'll use Keras to create a simple model architecture
|
||||
from tensorflow.keras import layers
|
||||
model_2 = tf.keras.Sequential()
|
||||
|
||||
# First layer takes a scalar input and feeds it through 16 "neurons". The
|
||||
# neurons decide whether to activate based on the 'relu' activation function.
|
||||
model_2.add(layers.Dense(16, activation='relu', input_shape=(1,)))
|
||||
|
||||
# The new second layer may help the network learn more complex representations
|
||||
model_2.add(layers.Dense(16, activation='relu'))
|
||||
|
||||
# Final layer is a single neuron, since we want to output a single value
|
||||
model_2.add(layers.Dense(1))
|
||||
|
||||
# Compile the model using a standard optimizer and loss function for regression
|
||||
model_2.compile(optimizer='rmsprop', loss='mse', metrics=['mae'])
|
||||
|
||||
history_2 = model_2.fit(x_train, y_train, epochs=600, batch_size=16,
|
||||
validation_data=(x_validate, y_validate))
|
||||
|
||||
# Calculate and print the loss on our test dataset
|
||||
loss = model_2.evaluate(x_test, y_test)
|
||||
|
||||
# Make predictions based on our test dataset
|
||||
predictions = model_2.predict(x_test)
|
||||
|
||||
# Graph the predictions against the actual values
|
||||
plt.clf()
|
||||
plt.title('Comparison of predictions and actual values')
|
||||
plt.plot(x_test, y_test, 'b.', label='Actual')
|
||||
plt.plot(x_test, predictions, 'r.', label='Predicted')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
# Convert the model to the TensorFlow Lite format without quantization
|
||||
converter = tf.lite.TFLiteConverter.from_keras_model(model_2)
|
||||
tflite_model = converter.convert()
|
||||
|
||||
# Save the model to disk
|
||||
open("sine_model.tflite", "wb").write(tflite_model)
|
||||
|
||||
# Convert the model to the TensorFlow Lite format with quantization
|
||||
converter = tf.lite.TFLiteConverter.from_keras_model(model_2)
|
||||
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
|
||||
tflite_model = converter.convert()
|
||||
|
||||
# Save the model to disk
|
||||
open("sine_model_quantized.tflite", "wb").write(tflite_model)
|
||||
|
||||
import base64;
|
||||
print("var model=atob(\""+base64.b64encode(tflite_model)+"\");")
|
||||
```
|
||||
|
||||
163
libs/tensorflow/jswrap_tensorflow.c
Normal file
163
libs/tensorflow/jswrap_tensorflow.c
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* This file is designed to be parsed during the build process
|
||||
*
|
||||
* Contains JavaScript interface for Neopixel/WS281x/APA10x devices
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <jswrap_tensorflow.h>
|
||||
#include "jsvariterator.h"
|
||||
#include "jsparse.h"
|
||||
#include "jsinteractive.h"
|
||||
#include "jswrap_arraybuffer.h"
|
||||
#include "tensorflow.h"
|
||||
|
||||
/*JSON{
|
||||
"type" : "library",
|
||||
"class" : "tensorflow"
|
||||
}
|
||||
*/
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
"class" : "tensorflow",
|
||||
"name" : "create",
|
||||
"generate" : "jswrap_tensorflow_create",
|
||||
"params" : [
|
||||
["arenaSize","int","The TensorFlow Arena size"],
|
||||
["model","JsVar","The model to use - this should be a flat array/string"]
|
||||
],
|
||||
"return" : ["JsVar","A tensorflow instance"],
|
||||
"return_object" : "TFMicroInterpreter"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_tensorflow_create(int arena_size, JsVar *model) {
|
||||
if (arena_size<512) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid Arena Size");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t modelSize = 0;
|
||||
char *modelPtr = jsvGetDataPointer(model, &modelSize);
|
||||
if (!modelPtr) {
|
||||
jsExceptionHere(JSET_TYPEERROR, "Model is not a Flat String/ArrayBuffer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
JsVar *tfmi = jspNewObject(NULL,"TFMicroInterpreter");
|
||||
if (!tfmi) return 0;
|
||||
|
||||
size_t tfSize = tf_get_size((size_t)arena_size, modelSize);
|
||||
JsVar *mi = jsvNewFlatStringOfLength(tfSize);
|
||||
if (!mi) {
|
||||
jsExceptionHere(JSET_ERROR, "Unable to allocate enough RAM for TensorFlow");
|
||||
jsvUnLock(tfmi);
|
||||
return 0;
|
||||
}
|
||||
char *tfPtr = jsvGetDataPointer(mi, &tfSize);
|
||||
if (!tfPtr) {
|
||||
assert(0);
|
||||
return 0; // should never get here
|
||||
}
|
||||
|
||||
if (!tf_create(tfPtr, (size_t)arena_size, modelPtr)) {
|
||||
jsExceptionHere(JSET_ERROR, "MicroInterpreter creation failed");
|
||||
jsvUnLock2(tfmi, mi);
|
||||
}
|
||||
jsvObjectSetChild(tfmi, "model", model); // so we keep a reference
|
||||
jsvObjectSetChildAndUnLock(tfmi, "mi", mi); // so we keep a reference
|
||||
return tfmi;
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "class",
|
||||
"library" : "tensorflow",
|
||||
"class" : "TFMicroInterpreter",
|
||||
"ifdef" : "USE_TENSORFLOW"
|
||||
}
|
||||
Class containing an instance of TFMicroInterpreter
|
||||
*/
|
||||
void *jswrap_tfmicrointerpreter_getTFMI(JsVar *parent) {
|
||||
JsVar *mi = jsvObjectGetChild(parent, "mi", 0);
|
||||
size_t tfSize;
|
||||
char *tfPtr = jsvGetDataPointer(mi, &tfSize);
|
||||
jsvUnLock(mi);
|
||||
if (!tfPtr)
|
||||
jsExceptionHere(JSET_ERROR, "TFMicroInterpreter structure corrupted");
|
||||
return tfPtr;
|
||||
}
|
||||
|
||||
JsVar *jswrap_tfmicrointerpreter_tensorToArrayBuffer(JsVar *parent, TfLiteTensor *tensor) {
|
||||
void *tfmi = jswrap_tfmicrointerpreter_getTFMI(parent);
|
||||
JsVar *mi = jsvObjectGetChild(parent, "mi", 0);
|
||||
if (!tensor && !mi) {
|
||||
jsExceptionHere(JSET_ERROR, "Unable to get tensor");
|
||||
return 0;
|
||||
}
|
||||
JsVarDataArrayBufferViewType abType = ARRAYBUFFERVIEW_UNDEFINED;
|
||||
switch (tensor->type) {
|
||||
case kTfLiteFloat32 :
|
||||
abType = ARRAYBUFFERVIEW_FLOAT32; break;
|
||||
default:
|
||||
jsExceptionHere(JSET_TYPEERROR, "Unknown Tensor format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
JsVar *ab = jsvNewArrayBufferFromString(mi,0);
|
||||
JsVar *b = jswrap_typedarray_constructor(abType, ab, ((size_t)&tensor->data.f[0])-(size_t)tfmi, tensor->bytes / JSV_ARRAYBUFFER_GET_SIZE(abType));
|
||||
jsvUnLock2(ab,mi);
|
||||
return b;
|
||||
}
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "TFMicroInterpreter",
|
||||
"name" : "getInput",
|
||||
"generate" : "jswrap_tfmicrointerpreter_getInput",
|
||||
"return" : ["JsVar","An arraybuffer referencing the input data"],
|
||||
"return_object" : "ArrayBufferView"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_tfmicrointerpreter_getInput(JsVar *parent) {
|
||||
void *tfmi = jswrap_tfmicrointerpreter_getTFMI(parent);
|
||||
if (!tfmi) return 0;
|
||||
return jswrap_tfmicrointerpreter_tensorToArrayBuffer(parent, tf_get_input(tfmi, 0));
|
||||
}
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "TFMicroInterpreter",
|
||||
"name" : "getOutput",
|
||||
"generate" : "jswrap_tfmicrointerpreter_getOutput",
|
||||
"return" : ["JsVar","An arraybuffer referencing the output data"],
|
||||
"return_object" : "ArrayBufferView"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_tfmicrointerpreter_getOutput(JsVar *parent) {
|
||||
void *tfmi = jswrap_tfmicrointerpreter_getTFMI(parent);
|
||||
if (!tfmi) return 0;
|
||||
return jswrap_tfmicrointerpreter_tensorToArrayBuffer(parent, tf_get_output(tfmi, 0));
|
||||
}
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "TFMicroInterpreter",
|
||||
"name" : "invoke",
|
||||
"generate" : "jswrap_tfmicrointerpreter_invoke"
|
||||
}
|
||||
*/
|
||||
void jswrap_tfmicrointerpreter_invoke(JsVar *parent) {
|
||||
void *tfmi = jswrap_tfmicrointerpreter_getTFMI(parent);
|
||||
if (!tfmi) return;
|
||||
if (!tf_invoke(tfmi)) {
|
||||
jsExceptionHere(JSET_TYPEERROR, "TFMicroInterpreter invoke failed");
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: what about tf_destroy?
|
||||
21
libs/tensorflow/jswrap_tensorflow.h
Normal file
21
libs/tensorflow/jswrap_tensorflow.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Contains JavaScript interface for Tensorflow
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "jspin.h"
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_tensorflow_create(int arena_size, JsVar *model);
|
||||
JsVar *jswrap_tfmicrointerpreter_getInput(JsVar *parent);
|
||||
JsVar *jswrap_tfmicrointerpreter_getOutput(JsVar *parent);
|
||||
void jswrap_tfmicrointerpreter_invoke(JsVar *parent);
|
||||
19
libs/tensorflow/patches/01-virtual-delete.diff
Normal file
19
libs/tensorflow/patches/01-virtual-delete.diff
Normal file
@ -0,0 +1,19 @@
|
||||
--- a/tensorflow/lite/experimental/micro/memory_planner/greedy_memory_planner.h 2019-09-11 09:14:45.509106591 +0100
|
||||
+++ b/tensorflow/lite/experimental/micro/memory_planner/greedy_memory_planner.h 2019-09-11 09:13:54.204422772 +0100
|
||||
@@ -17,6 +17,7 @@
|
||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_
|
||||
|
||||
#include "tensorflow/lite/experimental/micro/memory_planner/memory_planner.h"
|
||||
+#include "tensorflow/lite/experimental/micro/compatibility.h"
|
||||
|
||||
namespace tflite {
|
||||
|
||||
@@ -125,6 +126,8 @@
|
||||
|
||||
// Whether buffers have been added since the last plan was calculated.
|
||||
bool need_to_calculate_offsets_;
|
||||
+
|
||||
+ TF_LITE_REMOVE_VIRTUAL_DELETE
|
||||
};
|
||||
|
||||
} // namespace tflite
|
||||
25
libs/tensorflow/patches/02-public-delete.diff
Normal file
25
libs/tensorflow/patches/02-public-delete.diff
Normal file
@ -0,0 +1,25 @@
|
||||
--- a/tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h 2019-09-11 08:48:03.171950502 +0100
|
||||
+++ b/tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h 2019-09-11 10:47:28.818528375 +0100
|
||||
@@ -22,9 +22,8 @@
|
||||
class AllOpsResolver : public MicroMutableOpResolver {
|
||||
public:
|
||||
AllOpsResolver();
|
||||
-
|
||||
- private:
|
||||
TF_LITE_REMOVE_VIRTUAL_DELETE
|
||||
+
|
||||
};
|
||||
|
||||
} // namespace micro
|
||||
--- a/tensorflow/lite/experimental/micro/micro_error_reporter.h 2019-09-11 08:48:03.155950292 +0100
|
||||
+++ b/tensorflow/lite/experimental/micro/micro_error_reporter.h 2019-09-11 10:47:45.290747773 +0100
|
||||
@@ -26,8 +26,6 @@
|
||||
public:
|
||||
~MicroErrorReporter() {}
|
||||
int Report(const char* format, va_list args) override;
|
||||
-
|
||||
- private:
|
||||
TF_LITE_REMOVE_VIRTUAL_DELETE
|
||||
};
|
||||
|
||||
|
||||
119
libs/tensorflow/tensorflow.cc
Normal file
119
libs/tensorflow/tensorflow.cc
Normal file
@ -0,0 +1,119 @@
|
||||
/* Copyright 2019 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,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
||||
#include "tensorflow/lite/schema/schema_generated.h"
|
||||
#include "tensorflow/lite/version.h"
|
||||
extern "C" {
|
||||
#include "jsinteractive.h"
|
||||
#include "tensorflow.h"
|
||||
|
||||
void DebugLog(const char* s) { jsiConsolePrint(s); }
|
||||
|
||||
typedef struct {
|
||||
// logging
|
||||
tflite::MicroErrorReporter micro_error_reporter;
|
||||
// This pulls in all the operation implementations we need
|
||||
tflite::ops::micro::AllOpsResolver resolver;
|
||||
// Build an interpreter to run the model with
|
||||
tflite::MicroInterpreter interpreter;
|
||||
// Create an area of memory to use for input, output, and intermediate arrays.
|
||||
// Finding the minimum value for your model may require some trial and error.
|
||||
uint8_t tensor_arena[0];
|
||||
} TFData;
|
||||
char tfDataPtr[sizeof(TFData)];
|
||||
|
||||
size_t tf_get_size(size_t arena_size, const char *model_data) {
|
||||
return sizeof(TFData) + arena_size;
|
||||
}
|
||||
|
||||
bool tf_create(void *dataPtr, size_t arena_size, const char *model_data) {
|
||||
TFData *tf = (TFData*)dataPtr;
|
||||
new (&tf->micro_error_reporter)tflite::MicroErrorReporter();
|
||||
// Set up logging
|
||||
tflite::ErrorReporter* error_reporter = &tf->micro_error_reporter;
|
||||
|
||||
// Map the model into a usable data structure. This doesn't involve any
|
||||
// copying or parsing, it's a very lightweight operation.
|
||||
const tflite::Model* model = ::tflite::GetModel(model_data);
|
||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||
error_reporter->Report(
|
||||
"Model provided is schema version %d not equal "
|
||||
"to supported version %d.",
|
||||
model->version(), TFLITE_SCHEMA_VERSION);
|
||||
return false;
|
||||
}
|
||||
|
||||
new (&tf->resolver)tflite::ops::micro::AllOpsResolver();
|
||||
|
||||
// Build an interpreter to run the model with
|
||||
new (&tf->interpreter)tflite::MicroInterpreter(
|
||||
model, tf->resolver, tf->tensor_arena,
|
||||
arena_size, error_reporter);
|
||||
|
||||
// Allocate memory from the tensor_arena for the model's tensors
|
||||
tf->interpreter.AllocateTensors();
|
||||
|
||||
|
||||
/*
|
||||
TfLiteTensor* input = tf->interpreter.input(0);
|
||||
TfLiteTensor* output = tf->interpreter.output(0);
|
||||
|
||||
// Place our calculated x value in the model's input tensor
|
||||
input->data.f[0] = x_val;
|
||||
|
||||
|
||||
|
||||
// Read the predicted y value from the model's output tensor
|
||||
float y_val = output->data.f[0];*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void tf_destroy(void *dataPtr) {
|
||||
TFData *tf = (TFData*)dataPtr;
|
||||
|
||||
tf->interpreter.~MicroInterpreter();
|
||||
}
|
||||
|
||||
bool tf_invoke(void *dataPtr) {
|
||||
TFData *tf = (TFData*)dataPtr;
|
||||
tflite::ErrorReporter* error_reporter = &tf->micro_error_reporter;
|
||||
// Run inference, and report any error
|
||||
//jsiConsolePrintf("in %f\n",tf->interpreter.input(0)->data.f[0]);
|
||||
TfLiteStatus invoke_status = tf->interpreter.Invoke();
|
||||
//jsiConsolePrintf("out %f\n",tf->interpreter.output(0)->data.f[0]);
|
||||
if (invoke_status != kTfLiteOk) {
|
||||
error_reporter->Report("Invoke failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TfLiteTensor *tf_get_input(void *dataPtr, int n) {
|
||||
TFData *tf = (TFData*)dataPtr;
|
||||
// Obtain pointers to the model's input and output tensors
|
||||
return tf->interpreter.input(0);
|
||||
}
|
||||
|
||||
TfLiteTensor *tf_get_output(void *dataPtr, int n) {
|
||||
TFData *tf = (TFData*)dataPtr;
|
||||
// Obtain pointers to the model's input and output tensors
|
||||
return tf->interpreter.output(0);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
8
libs/tensorflow/tensorflow.h
Normal file
8
libs/tensorflow/tensorflow.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include "tensorflow/lite/c/c_api_internal.h"
|
||||
|
||||
size_t tf_get_size(size_t arena_size, const char *model_data);
|
||||
bool tf_create(void *dataPtr, size_t arena_size, const char *model_data);
|
||||
void tf_destroy(void *dataPtr);
|
||||
bool tf_invoke(void *dataPtr);
|
||||
TfLiteTensor *tf_get_input(void *dataPtr, int n);
|
||||
TfLiteTensor *tf_get_output(void *dataPtr, int n);
|
||||
60
make/misc/tensorflow.make
Normal file
60
make/misc/tensorflow.make
Normal file
@ -0,0 +1,60 @@
|
||||
TENSOR_ROOT := $(ROOT)/libs/tensorflow
|
||||
CCSOURCES += \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/simple_memory_allocator.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/memory_helpers.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/micro_error_reporter.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/micro_mutable_op_resolver.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/debug_log_numbers.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/test_helpers.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/micro_interpreter.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/micro_allocator.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/pack.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/logical.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/reshape.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/depthwise_conv.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/conv.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/pooling.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/softmax.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/prelu.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/ceil.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/arg_min_max.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/unpack.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/add.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/split.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/neg.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/floor.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/comparisons.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/svdf.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/all_ops_resolver.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/fully_connected.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/maximum_minimum.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/elementwise.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/strided_slice.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/kernels/round.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/memory_planner/linear_memory_planner.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/memory_planner/greedy_memory_planner.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/core/api/error_reporter.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/core/api/flatbuffer_conversions.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/core/api/op_resolver.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/core/api/tensor_utils.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/kernels/kernel_util.cc \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/kernels/internal/quantization_util.cc \
|
||||
$(TENSOR_ROOT)/tensorflow.cc
|
||||
|
||||
#$(TENSOR_ROOT)/tensorflow/lite/experimental/micro/debug_log.cc
|
||||
|
||||
SOURCES += \
|
||||
$(TENSOR_ROOT)/tensorflow/lite/c/c_api_internal.c \
|
||||
|
||||
WRAPPERSOURCES += \
|
||||
$(TENSOR_ROOT)/jswrap_tensorflow.c
|
||||
|
||||
INCLUDE += \
|
||||
-I$(TENSOR_ROOT) \
|
||||
-I$(TENSOR_ROOT)/tensorflow \
|
||||
-I$(TENSOR_ROOT)/third_party/gemmlowp \
|
||||
-I$(TENSOR_ROOT)/third_party/kissfft \
|
||||
-I$(TENSOR_ROOT)/third_party/flatbuffers/include
|
||||
|
||||
CCFLAGS += -DNDEBUG -g -DTF_LITE_STATIC_MEMORY --std=c++11 -g -fno-rtti -fpermissive -Wno-sign-compare -Wno-conversion -Wno-sign-conversion -Wno-missing-field-initializers -Wno-type-limits -Wno-unused-parameter
|
||||
|
||||
@ -3592,7 +3592,7 @@ void _jsvTrace(JsVar *var, int indent, JsVar *baseVar, int level) {
|
||||
else if (jsvIsFloat(var)) jsiConsolePrintf("Double %f", jsvGetFloat(var));
|
||||
else if (jsvIsFunctionParameter(var)) jsiConsolePrintf("Param %q ", var);
|
||||
else if (jsvIsArrayBufferName(var)) jsiConsolePrintf("ArrayBufferName[%d] ", jsvGetInteger(var));
|
||||
else if (jsvIsArrayBuffer(var)) jsiConsolePrintf("%s ", jswGetBasicObjectName(var)?jswGetBasicObjectName(var):"unknown ArrayBuffer"); // way to get nice name
|
||||
else if (jsvIsArrayBuffer(var)) jsiConsolePrintf("%s (offs %d, len %d)", jswGetBasicObjectName(var)?jswGetBasicObjectName(var):"unknown ArrayBuffer", var->varData.arraybuffer.byteOffset, var->varData.arraybuffer.length); // way to get nice name
|
||||
else if (jsvIsString(var)) {
|
||||
size_t blocks = 1;
|
||||
if (jsvGetLastChild(var)) {
|
||||
|
||||
@ -760,7 +760,7 @@ JsVar *jsvNewDataViewWithData(JsVarInt length, unsigned char *data);
|
||||
* allocate it. */
|
||||
JsVar *jsvNewArrayBufferWithPtr(unsigned int length, char **ptr);
|
||||
|
||||
/** create an arraybuffer containing the given data */
|
||||
/** create an arraybuffer containing the given data - this allocates new memory and copies 'data' */
|
||||
JsVar *jsvNewArrayBufferWithData(JsVarInt length, unsigned char *data);
|
||||
|
||||
/** Allocate a flat area of memory inside Espruino's Variable storage space.
|
||||
|
||||
237
tests/test_tensorflow.js
Normal file
237
tests/test_tensorflow.js
Normal file
@ -0,0 +1,237 @@
|
||||
// sine model from 'hello world' example
|
||||
var sine_model_data =
|
||||
E.toString([
|
||||
0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
|
||||
0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x00, 0x00,
|
||||
0xb8, 0x05, 0x00, 0x00, 0xa0, 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x0b, 0x00, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x7c, 0x05, 0x00, 0x00,
|
||||
0x24, 0x05, 0x00, 0x00, 0xd4, 0x04, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00,
|
||||
0x74, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x54, 0xf6, 0xff, 0xff, 0x58, 0xf6, 0xff, 0xff, 0x5c, 0xf6, 0xff, 0xff,
|
||||
0x60, 0xf6, 0xff, 0xff, 0xc2, 0xfa, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x7c, 0x19, 0xa7, 0x3e, 0x99, 0x81, 0xb9, 0x3e,
|
||||
0x56, 0x8b, 0x9f, 0x3e, 0x88, 0xd8, 0x12, 0xbf, 0x74, 0x10, 0x56, 0x3e,
|
||||
0xfe, 0xc6, 0xdf, 0xbe, 0xf2, 0x10, 0x5a, 0xbe, 0xf0, 0xe2, 0x0a, 0xbe,
|
||||
0x10, 0x5a, 0x98, 0xbe, 0xb9, 0x36, 0xce, 0x3d, 0x8f, 0x7f, 0x87, 0x3e,
|
||||
0x2c, 0xb1, 0xfd, 0xbd, 0xe6, 0xa6, 0x8a, 0xbe, 0xa5, 0x3e, 0xda, 0x3e,
|
||||
0x50, 0x34, 0xed, 0xbd, 0x90, 0x91, 0x69, 0xbe, 0x0e, 0xfb, 0xff, 0xff,
|
||||
0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x67, 0x41, 0x48, 0xbf,
|
||||
0x24, 0xcd, 0xa0, 0xbe, 0xb7, 0x92, 0x0c, 0xbf, 0x00, 0x00, 0x00, 0x00,
|
||||
0x98, 0xfe, 0x3c, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x17, 0x9a, 0xbe,
|
||||
0x41, 0xcb, 0xb6, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x13, 0xd6, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x5a, 0xfb, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x4b, 0x98, 0xdd, 0xbd, 0x40, 0x6b, 0xcb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xbe,
|
||||
0x0d, 0xba, 0xb9, 0x3e, 0x66, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x53, 0xd6, 0xe2, 0x3d, 0x66, 0xb6, 0xcc, 0x3e,
|
||||
0x03, 0xe7, 0xf6, 0x3e, 0xe0, 0x28, 0x10, 0xbf, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3e, 0x3d, 0xb0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x62, 0xf0, 0x77, 0x3e,
|
||||
0xa6, 0x9d, 0xa4, 0x3e, 0x3a, 0x4b, 0xf3, 0xbe, 0x71, 0x9e, 0xa7, 0x3e,
|
||||
0x00, 0x00, 0x00, 0x00, 0x34, 0x39, 0xa2, 0x3e, 0x00, 0x00, 0x00, 0x00,
|
||||
0xcc, 0x9c, 0x4a, 0x3e, 0xab, 0x40, 0xa3, 0x3e, 0xb2, 0xff, 0xff, 0xff,
|
||||
0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xb3, 0x71, 0x67, 0x3f,
|
||||
0x9a, 0x7a, 0x95, 0xbf, 0xe1, 0x48, 0xe8, 0xbe, 0x8a, 0x72, 0x96, 0x3e,
|
||||
0x00, 0xd2, 0xd3, 0xbb, 0x1a, 0xc5, 0xd7, 0x3f, 0xac, 0x7e, 0xc8, 0xbe,
|
||||
0x90, 0xa7, 0x95, 0xbe, 0x3b, 0xd7, 0xdc, 0xbe, 0x41, 0xa8, 0x16, 0x3f,
|
||||
0x50, 0x5b, 0xcb, 0x3f, 0x52, 0xb9, 0xed, 0xbe, 0x2e, 0xa7, 0xc6, 0xbe,
|
||||
0xaf, 0x0f, 0x14, 0xbf, 0xb3, 0xda, 0x59, 0x3f, 0x02, 0xec, 0xd7, 0xbe,
|
||||
0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x66, 0x11, 0x1f, 0xbf,
|
||||
0xb8, 0xfb, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x54, 0x4f, 0x43, 0x4f,
|
||||
0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00,
|
||||
0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0xf0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00,
|
||||
0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xce, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x1c, 0xfc, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xba, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x16, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x08, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x0a, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00, 0xa4, 0x02, 0x00, 0x00,
|
||||
0x40, 0x02, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0xac, 0x01, 0x00, 0x00,
|
||||
0x48, 0x01, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
|
||||
0x50, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x26, 0xfd, 0xff, 0xff,
|
||||
0x3c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x18, 0xfd, 0xff, 0xff, 0x20, 0x00, 0x00, 0x00,
|
||||
0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31,
|
||||
0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x2f, 0x4d, 0x61, 0x74,
|
||||
0x4d, 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x6e, 0xfd, 0xff, 0xff,
|
||||
0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x60, 0xfd, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00,
|
||||
0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31,
|
||||
0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x2f, 0x4d, 0x61, 0x74,
|
||||
0x4d, 0x75, 0x6c, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69,
|
||||
0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73,
|
||||
0x70, 0x6f, 0x73, 0x65, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xce, 0xfd, 0xff, 0xff,
|
||||
0x34, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0xc0, 0xfd, 0xff, 0xff, 0x19, 0x00, 0x00, 0x00,
|
||||
0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31,
|
||||
0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x52, 0x65, 0x6c,
|
||||
0x75, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x12, 0xfe, 0xff, 0xff, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x04, 0xfe, 0xff, 0xff, 0x20, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75,
|
||||
0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31, 0x2f, 0x64, 0x65, 0x6e,
|
||||
0x73, 0x65, 0x5f, 0x33, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f,
|
||||
0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x5a, 0xfe, 0xff, 0xff, 0x50, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x4c, 0xfe, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75,
|
||||
0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31, 0x2f, 0x64, 0x65, 0x6e,
|
||||
0x73, 0x65, 0x5f, 0x33, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x2f,
|
||||
0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65,
|
||||
0x4f, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0xba, 0xfe, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00,
|
||||
0x0a, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0xac, 0xfe, 0xff, 0xff, 0x19, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75,
|
||||
0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x31, 0x2f, 0x64, 0x65, 0x6e,
|
||||
0x73, 0x65, 0x5f, 0x32, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xfe, 0xff, 0xff, 0x3c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf0, 0xfe, 0xff, 0xff,
|
||||
0x20, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69,
|
||||
0x61, 0x6c, 0x5f, 0x31, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32,
|
||||
0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x46, 0xff, 0xff, 0xff, 0x50, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x38, 0xff, 0xff, 0xff,
|
||||
0x34, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69,
|
||||
0x61, 0x6c, 0x5f, 0x31, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32,
|
||||
0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x2f, 0x52, 0x65, 0x61, 0x64,
|
||||
0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x74,
|
||||
0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xa6, 0xff, 0xff, 0xff, 0x48, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
|
||||
0x2c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00,
|
||||
0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x43,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
|
||||
0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, 0x69, 0x6e, 0x70, 0x75,
|
||||
0x74, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x04, 0x00,
|
||||
0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00,
|
||||
0x28, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00,
|
||||
0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00]);
|
||||
|
||||
var tf = require("tensorflow").create(2048, sine_model_data);
|
||||
|
||||
function t(x) {
|
||||
tf.getInput()[0] = x;
|
||||
tf.invoke();
|
||||
var o = tf.getOutput()[0];
|
||||
var r = Math.abs(o - Math.sin(x))<0.1;
|
||||
print("Math.sin(",x,") => ",o," vs ",Math.sin(x), r?"ok":"fail");
|
||||
return r;
|
||||
}
|
||||
|
||||
result = t(0) && t(1) && t(2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user