tflite-micro/python/tflite_micro/interpreter_wrapper.h
Ryan Kuester b5da836410
refactor(python): move runtime to package-friendly directory structure (#2051)
To package the module `runtime` as `tflite_micro.runtime`, put `runtime` under
a directory representing the Python namespace package `tflite_micro`. For
organization's sake, move it all to the top-level directory `python/`. Adjust
tests and docs to match.

Some code outside of the Python extension module has come to depend on
`python/tflite_micro:python_ops_resolver` as a replacement for
`all_ops_resolver` (e.g.:`t/l/m/integration_tests/seanet/add/integration_tests.cc`).
`python_ops_resolver` is intended to be a private implementation detail of the
Python extension module. For now, grandfather in the dependent code by updating
its references to the resolver's location; however, soon the dependent code
should be migrated away to a different resolver. (#2033,
https://issuetracker.google.com/286508251)

BUG=part of #1484
2023-06-15 06:25:19 +00:00

51 lines
1.8 KiB
C++

/* Copyright 2022 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_MICRO_TOOLS_PYTHON_INTERPRETER_WRAPPER_H_
#define TENSORFLOW_LITE_MICRO_TOOLS_PYTHON_INTERPRETER_WRAPPER_H_
#include <Python.h>
#include "python/tflite_micro/python_ops_resolver.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/recording_micro_allocator.h"
namespace tflite {
class InterpreterWrapper {
public:
InterpreterWrapper(PyObject* model_data,
const std::vector<std::string>& registerers_by_name,
size_t arena_size, int num_resource_variables);
~InterpreterWrapper();
void PrintAllocations();
int Invoke();
int Reset();
void SetInputTensor(PyObject* data, size_t index);
PyObject* GetOutputTensor(size_t index) const;
PyObject* GetInputTensorDetails(size_t index) const;
PyObject* GetOutputTensorDetails(size_t index) const;
private:
tflite::RecordingMicroAllocator* allocator_;
const PyObject* model_;
std::unique_ptr<uint8_t[]> memory_arena_;
tflite::PythonOpsResolver python_ops_resolver_;
tflite::MicroInterpreter* interpreter_;
};
} // namespace tflite
#endif // TENSORFLOW_LITE_MICRO_TOOLS_PYTHON_INTERPRETER_WRAPPER_H_