tflite-micro/python/tflite_micro/signal/utils/util.py
suleshahid f22888af65
Adds Signal Library RFFT OP (#2056)
Second OP for the TFLM Signal library, Real-Valued Fast Fourier Transform.

The RFFT OP provides three resolutions: `FLOAT, INT16, INT32`

Similar usage as to previous Window OP:
* `op_resolver.AddRfft()` (which will add all resolutions, and determine the type at runtime)
* `op_resolver.AddRfftFloat()`, `op_resolver.AddRfftInt16()`, `op_resolver.AddRfftInt32()` for a specific resolution type.
* or via python as can be seen in `fft_ops_test.py`

3 testing options are provided:
* Micro(C++): bazel run signal/micro/kernels:fft_test
* Tensorflow/Micro(Python): bazel run python/tflite_micro/signal:fft_ops_test
* Makefile(C++): make -f tensorflow/lite/micro/tools/make/Makefile test_kernel_fft_test

BUG=[287346710](http://b/287346710)
2023-06-21 20:36:55 +00:00

42 lines
1.5 KiB
Python

# Copyright 2023 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.
# ==============================================================================
"""Python utility functions."""
import tensorflow as tf
from tensorflow.python.framework import load_library
from tensorflow.python.platform import resource_loader
from tflite_micro.python.tflite_micro import runtime
# TODO(b/286889497): find better name and place for this function.
def get_tflm_interpreter(concrete_function, trackable_obj):
"""Initialize a TFLite interpreter with a concerte function.
Args:
concrete_function: A concrete function
Returns:
TFLite interpreter object
"""
converter = tf.lite.TFLiteConverter.from_concrete_functions(
[concrete_function], trackable_obj)
converter.allow_custom_ops = True
tflite_model = converter.convert()
return runtime.Interpreter.from_bytes(tflite_model, arena_size=500000)
def load_custom_op(name):
return load_library.load_op_library(
resource_loader.get_path_to_datafile('../ops/_' + name))