Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tensorflow/lite/micro/examples/recipes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tflm_py_test(
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
deps = [
":resource_variables_lib",
requirement("numpy"),
"//python/tflite_micro:runtime",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
import unittest
import numpy as np

from tensorflow.python.framework import test_util
from tensorflow.python.platform import test
from tflite_micro.python.tflite_micro import runtime as tflm_runtime
from tflite_micro.tensorflow.lite.micro.examples.recipes import (
resource_variables_lib,
)

from tflite_micro.python.tflite_micro import runtime as tflm_runtime


class ResourceVariablesTest(test_util.TensorFlowTestCase):
class ResourceVariablesTest(unittest.TestCase):
# Tests the custom accumulator model. Input conditional is [True], and
# accumulator value is array of 5.0. Given these inputs, we expect the output
# (variable value), to be accumulated by 5.0 each invoke.
Expand All @@ -34,15 +32,15 @@ def test_resource_variables_model(self):
tflm_interpreter.set_input([[True]], 0)
tflm_interpreter.set_input([np.full((100,), 15.0, dtype=np.float32)], 1)
tflm_interpreter.invoke()
self.assertAllEqual(
np.testing.assert_array_equal(
tflm_interpreter.get_output(0),
np.full((1, 100), 15.0, dtype=np.float32),
)

tflm_interpreter.set_input([[False]], 0)
tflm_interpreter.set_input([np.full((100,), 9.0, dtype=np.float32)], 1)
tflm_interpreter.invoke()
self.assertAllEqual(
np.testing.assert_array_equal(
tflm_interpreter.get_output(0),
np.full((1, 100), 6.0, dtype=np.float32),
)
Expand All @@ -52,11 +50,11 @@ def test_resource_variables_model(self):
tflm_interpreter.set_input([[True]], 0)
tflm_interpreter.set_input([np.full((100,), 5.0, dtype=np.float32)], 1)
tflm_interpreter.invoke()
self.assertAllEqual(
np.testing.assert_array_equal(
tflm_interpreter.get_output(0),
np.full((1, 100), 5.0, dtype=np.float32),
)


if __name__ == "__main__":
test.main()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
import unittest
import numpy as np
import tensorflow as tf

from tensorflow.python.framework import test_util
from tensorflow.python.platform import test
from tflite_micro.tensorflow.lite.micro.kernels.testdata import (
lstm_test_data_utils,
)
Expand Down Expand Up @@ -78,7 +77,7 @@ def create_keras_lstm(stateful=True):
return tf.keras.Model(input_layer, lstm_output, name="LSTM")


class QuantizedLSTMDebuggerTest(test_util.TensorFlowTestCase):
class QuantizedLSTMDebuggerTest(unittest.TestCase):
# only the float output from the debugger is used to setup the test data in .cc
def testFloatCompareWithKeras(self):
keras_lstm = create_keras_lstm()
Expand All @@ -102,8 +101,8 @@ def testFloatCompareWithKeras(self):
output_keras, _, _ = keras_lstm.predict(test_data.reshape(1, 1, 2))

diff = abs(output_float.flatten() - output_keras.flatten())
self.assertAllLess(diff, 1e-6)
self.assertTrue(np.all(diff < 1e-6))


if __name__ == "__main__":
test.main()
unittest.main()
Loading