У меня есть проблемы с простым вызовом для интерпретатора Tflite (C ++ API). Может быть, моя проблема с настройкой C ++, но я, честно говоря, понятия не имею, где проблема.
Все последовательные прогоны должны происходить в вызове < /code>, но я получаю ошибку сегментации (ядро сброшено) < /code> там.
Если я перемещаю один и тот же код в конструктор, нет проблемы там. Я также пытался перемещать интерпретатор и публику. Он не удается в интерпретаторе-> invoke () и даже не попадает в std :: cout
#include
#include
#include
#include
#include
#include
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
class ObjectDetectionProcessor {
public:
ObjectDetectionProcessor(const std::string& model_path) {
auto model = tflite::FlatBufferModel::BuildFromFile(model_path.c_str());
if (!model) {
std::cout data[1];
const uint input_channels = input_tensor->dims->data[3];
const uint input_type = input_tensor->type;
// get quantization parameters
input_scale = input_tensor->params.scale;
input_zero_point = input_tensor->params.zero_point;
is_initialized = false;
int cv_type = (input_type == kTfLiteFloat32) ? CV_32FC3 : CV_8UC3; // Adjust type based on tensor type
// create a dummy cv::Mat frame of zeros of input_width and input_height of type input_type
cv::Mat dummy_frame = cv::Mat::zeros(input_height, input_width, cv_type);
// // and pass it to the interpreter to warm up the model
TfLiteTensor* input_data = interpreter->tensor(interpreter->inputs()[0]);
std::memcpy(input_data->data.uint8, dummy_frame.ptr(0), dummy_frame.total() * dummy_frame.elemSize());
if (interpreter->Invoke() != kTfLiteOk) {
std::cout tensor(output_index);
float* out_data = interpreter->typed_output_tensor(0);
is_initialized = true;
}
void process(){
if (!is_initialized) {
std::cout data[2], input_tensor->dims->data[1]));
dummy_frame.convertTo(dummy_frame, CV_8UC3);
// get the input and output tensor
TfLiteTensor* input_data = interpreter->tensor(interpreter->inputs()[0]);
TfLiteTensor* output_data = interpreter->tensor(interpreter->outputs()[0]);
std::memcpy(input_data->data.uint8, dummy_frame.ptr(0), dummy_frame.total() * dummy_frame.elemSize());
// run inference
if (interpreter->Invoke() != kTfLiteOk) {
std::cout outputs()[0])->data.f;
float* classes = interpreter->tensor(interpreter->outputs()[1])->data.f;
float* scores = interpreter->tensor(interpreter->outputs()[2])->data.f;
}
private:
std::unique_ptr model;
tflite::ops::builtin::BuiltinOpResolver resolver;
std::unique_ptr interpreter;
TfLiteTensor* input_tensor = nullptr;
TfLiteTensor* output_tensor = nullptr;
bool is_initialized;
};
< /code>
Редактировать: Скомпилирование кода с < /p>
g++ -g -o out src/infer.cpp tensorflow/tensorflow/lite/delegates/external/external_delegate.cc -I/usr/local/tensorflow/include -L/usr/local/tensorflow/lib -ltensorflowlite -I/usr/local/include/opencv4/ -L/usr/local/lib/ -lopencv_core -lopencv_imgcodecs -lopencv_imgproc
edit2:
Это предполагает образец изображения, расположенного по адресу /src/image.jpg и модель Tflite в /src/model.tflite .
Я использовал предварительную модель из Tensorflow здесь
РЕДАКТИРОВАТЬ 3:
Backtrace ничего не дает
(gdb) backtrace
#0 0x0000713a12be8ab9 in ?? () from /usr/local/lib/libtensorflowlite.so
#1 0x0000713a1290aa7b in ?? () from /usr/local/lib/libtensorflowlite.so
#2 0x0000713a12bf1474 in ?? () from /usr/local/lib/libtensorflowlite.so
#3 0x0000713a12bf18ae in ?? () from /usr/local/lib/libtensorflowlite.so
#4 0x0000713a12bd8a52 in ?? () from /usr/local/lib/libtensorflowlite.so
#5 0x0000713a1297e730 in ?? () from /usr/local/lib/libtensorflowlite.so
#6 0x0000713a1297f57e in ?? () from /usr/local/lib/libtensorflowlite.so
#7 0x0000713a1298190b in ?? () from /usr/local/lib/libtensorflowlite.so
#8 0x0000713a12982137 in TfLiteStatus tflite::ops::builtin::conv::EvalImpl(TfLiteContext*, TfLiteNode*) () from /usr/local/lib/libtensorflowlite.so
#9 0x0000713a129821fb in TfLiteStatus tflite::ops::builtin::conv::Eval(TfLiteContext*, TfLiteNode*) () from /usr/local/lib/libtensorflowlite.so
#10 0x0000713a12b8f519 in tflite::Subgraph::Invoke() () from /usr/local/lib/libtensorflowlite.so
#11 0x0000713a12b9508c in tflite::Interpreter::Invoke() () from /usr/local/lib/libtensorflowlite.so
#12 0x00006152b80498d9 in ObjectDetectionProcessor::process (this=0x7ffdf3118b20) at src/inference.hpp:226
#13 0x00006152b8047aaf in main () at src/infer.cpp:12
Просматривать указатели для opper_data и input_tensor по конструктору и вызову функции, они одинаковы, поэтому они указывают на тот же адрес.
Constructor:
(gdb) p interpreter
$2 = std::unique_ptr = {get() = 0x6152ecc21760}
(gdb) p input_tensor
$4 = (TfLiteTensor *) 0x6152ecc3aaa0
(gdb) p input_data
$5 = (TfLiteTensor *) 0x6152ecc3aaa0
Process function:
(gdb) p input_tensor_
$7 = (TfLiteTensor *) 0x6152ecc3aaa0
(gdb) p interpreter
$8 = std::unique_ptr = {get() = 0x6152ecc21760}
(gdb) p input_data
$9 = (TfLiteTensor *) 0x6152ecc3aaa0
Подробнее здесь: https://stackoverflow.com/questions/794 ... tion-fault
Tflite C ++ API вызывают вызывы о разломе сегментации ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение