diff --git a/.gitignore b/.gitignore index 5a90a61..f179718 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ __pycache__/ *.gcno test___* docs/_build/* -local/* \ No newline at end of file +local/* +*.egg-info/ diff --git a/keras2c/__main__.py b/keras2c/__main__.py index 5b1fe73..7e1b970 100644 --- a/keras2c/__main__.py +++ b/keras2c/__main__.py @@ -9,6 +9,7 @@ import argparse import sys from keras2c.keras2c_main import k2c +import tensorflow as tf __author__ = "Rory Conlin" @@ -37,7 +38,7 @@ def parse_args(args): def main(args=sys.argv[1:]): - + tf.compat.v1.disable_eager_execution() args = parse_args(args) if args.malloc: malloc = True diff --git a/keras2c/check_model.py b/keras2c/check_model.py index 3845bc8..7785523 100644 --- a/keras2c/check_model.py +++ b/keras2c/check_model.py @@ -13,7 +13,6 @@ from keras2c.weights2c import Weights2C from keras2c.layer2c import Layers2C import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/keras2c/keras2c_main.py b/keras2c/keras2c_main.py index ace0245..0bc2660 100644 --- a/keras2c/keras2c_main.py +++ b/keras2c/keras2c_main.py @@ -18,7 +18,6 @@ import subprocess import tensorflow.keras as keras import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" @@ -31,7 +30,7 @@ def model2c(model, function_name, malloc=False, verbose=True): """Generates C code for model - Writes main function definition to "function_name.c" and a public header + Writes main function definition to "function_name.c" and a public header with declarations to "function_name.h" Args: @@ -196,7 +195,7 @@ def k2c(model, function_name, malloc=False, num_tests=10, verbose=True): verbose (bool): whether to print progress Raises: - ValueError: if model is not instance of keras.models.Model + ValueError: if model is not instance of keras.models.Model Returns: None diff --git a/keras2c/layer2c.py b/keras2c/layer2c.py index 79e1985..07c4083 100644 --- a/keras2c/layer2c.py +++ b/keras2c/layer2c.py @@ -10,7 +10,6 @@ # imports from keras2c.io_parsing import layer_type, get_model_io_names, get_all_io_names, get_layer_io_names, flatten import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" diff --git a/keras2c/make_test_suite.py b/keras2c/make_test_suite.py index 9b6904e..8bb5a56 100644 --- a/keras2c/make_test_suite.py +++ b/keras2c/make_test_suite.py @@ -13,7 +13,6 @@ from keras2c.weights2c import Weights2C import tensorflow as tf import subprocess -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" @@ -109,7 +108,7 @@ def make_test_suite(model, function_name, malloc_vars, num_tests=10, stateful=Fa model_outputs[j] + '_test' + str(i+1))) s = 'int main(){\n' file.write(s) - + s = ' float errors[' + str(num_tests*num_outputs) + '];\n' s += ' size_t num_tests = ' + str(num_tests) + '; \n' s += 'size_t num_outputs = ' + str(num_outputs) + '; \n' diff --git a/keras2c/weights2c.py b/keras2c/weights2c.py index a4b3e47..04ad178 100644 --- a/keras2c/weights2c.py +++ b/keras2c/weights2c.py @@ -12,7 +12,7 @@ from keras2c.io_parsing import layer_type, get_layer_io_names, get_model_io_names from tensorflow.keras import backend as K import tensorflow as tf -tf.compat.v1.disable_eager_execution() + maxndim = 5 @@ -113,7 +113,7 @@ def write_weights(self, verbose=True): (tuple): tuple containing - **stack_vars** (*str*): code for variables allocated on the stack - - **malloc_vars** (*dict*): dictionary of name,value pairs for arrays to be + - **malloc_vars** (*dict*): dictionary of name,value pairs for arrays to be allocated on the heap - **static_vars** (*str*): code fora C struct containing static variables (eg, states of a stateful RNN) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..55e6d9b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,16 @@ +[metadata] +name = keras2c +version = 0.0.1 +description = Library for deploying keras neural networks in C99, using only standard libraries. It is designed to be as simple as possible for real time applications. +long_description = file: README.md + +[options] +include_package_data = True +packages = find: +install_requires = + tensorflow + numpy + +[options.entry_points] +console_scripts = + keras2c = keras2c.__main__:main \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..864b617 --- /dev/null +++ b/setup.py @@ -0,0 +1,2 @@ +import setuptools +setuptools.setup() \ No newline at end of file diff --git a/tests/test_advanced_activation_layers.py b/tests/test_advanced_activation_layers.py index c9e81aa..5d340ca 100644 --- a/tests/test_advanced_activation_layers.py +++ b/tests/test_advanced_activation_layers.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_checks.py b/tests/test_checks.py index a5f9108..0be4952 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -12,7 +12,6 @@ import time import numpy as np import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_convolution_layers.py b/tests/test_convolution_layers.py index 2952125..9ccdcb0 100644 --- a/tests/test_convolution_layers.py +++ b/tests/test_convolution_layers.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_core_layers.py b/tests/test_core_layers.py index 0bfb930..f2df67d 100644 --- a/tests/test_core_layers.py +++ b/tests/test_core_layers.py @@ -12,7 +12,6 @@ import time import os import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" @@ -22,7 +21,7 @@ CC = 'gcc' - +seed = 100 def build_and_run(name, return_output=False): @@ -153,7 +152,7 @@ class TestNormalization(unittest.TestCase): def test_BatchNorm1(self): inshp = (10, 11, 12) axis = 3 - init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0) + init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0, seed=seed) a = keras.layers.Input(inshp) b = keras.layers.BatchNormalization(axis=axis, beta_initializer=init, @@ -170,7 +169,7 @@ def test_BatchNorm1(self): def test_BatchNorm2(self): inshp = (10, 11, 12) axis = 2 - init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0) + init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0, seed=seed) a = keras.layers.Input(inshp) b = keras.layers.BatchNormalization(axis=axis, beta_initializer=init, @@ -187,7 +186,7 @@ def test_BatchNorm2(self): def test_BatchNorm3(self): inshp = (10, 11, 12, 13) axis = 1 - init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0) + init = keras.initializers.RandomUniform(minval=0.1, maxval=1.0, seed=seed) a = keras.layers.Input(inshp) b = keras.layers.BatchNormalization(axis=axis, beta_initializer=init, @@ -204,7 +203,7 @@ def test_BatchNorm3(self): def test_BatchNorm4(self): inshp = (10, 11, 12) axis = 2 - init = keras.initializers.RandomUniform(minval=0.1, maxval=2.0) + init = keras.initializers.RandomUniform(minval=0.1, maxval=2.0, seed=seed) a = keras.layers.Input(inshp) b = keras.layers.BatchNormalization(axis=axis, beta_initializer=init, diff --git a/tests/test_malloc.py b/tests/test_malloc.py index 9813555..cefdda5 100644 --- a/tests/test_malloc.py +++ b/tests/test_malloc.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_merge_layers.py b/tests/test_merge_layers.py index 7ab2e8b..f1fed76 100644 --- a/tests/test_merge_layers.py +++ b/tests/test_merge_layers.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_models.py b/tests/test_models.py index 6b68ff8..8a94fe6 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -18,7 +18,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_pooling_layers.py b/tests/test_pooling_layers.py index fbe7776..9e45e0c 100644 --- a/tests/test_pooling_layers.py +++ b/tests/test_pooling_layers.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin" diff --git a/tests/test_recurrent_layers.py b/tests/test_recurrent_layers.py index c07cab2..a7dce34 100644 --- a/tests/test_recurrent_layers.py +++ b/tests/test_recurrent_layers.py @@ -13,7 +13,6 @@ import os from test_core_layers import build_and_run import tensorflow as tf -tf.compat.v1.disable_eager_execution() __author__ = "Rory Conlin" __copyright__ = "Copyright 2020, Rory Conlin"