TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed

Jump to solution
1,724 Views
astel_
Contributor II

Hello everyone

Sorry for asking. I tried to build my own C++ program which is a converted program from python , to run a simple model to detect people for my board imx8m plus.

The Code:

1. main.cpp

 

 

 

// main.cpp
#include "detector.h"
#include <opencv2/opencv.hpp>

int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " <image_path>" << std::endl;
        return 1;
    }

    std::string image_path = argv[1];
    std::string model_path = "model.tflite";
    std::string delegate_path = "/usr/lib/libvx_delegate.so";
    cv::Size input_size(192, 192);
    float score_th = 0.5;
    float nms_th = 0.4;

    Detector detector(model_path, delegate_path, input_size, score_th, nms_th);
    if (!detector.init_model()) {
        return 1;
    }

    cv::Mat image = cv::imread(image_path);
    if (image.empty()) {
        std::cerr << "Failed to load image from " << image_path << std::endl;
        return 1;
    }

    auto [bboxes, scores] = detector.detect(image);

    for (size_t i = 0; i < bboxes.size(); ++i) {
        cv::rectangle(image, bboxes[i], cv::Scalar(0, 255, 0), 2);
        std::cout << "Detected bbox: " << bboxes[i] << " with score: " << scores[i] << std::endl;
    }

    // cv::imshow("Detections", image);
    cv::waitKey(0);

    return 0;
}

 

 

 


2. detector.h

 

 

 

// detector.h
#ifndef DETECTOR_H
#define DETECTOR_H

#include <opencv2/opencv.hpp>
#include <tensorflow/lite/interpreter.h>
#include <tensorflow/lite/kernels/register.h>
#include <tensorflow/lite/model.h>
#include <tensorflow/lite/optional_debug_tools.h>
#include <tensorflow/lite/delegates/external/external_delegate.h>
#include <tensorflow-lite-vx-delegate/vsi_npu_custom_op.h>
#include "delegate_main.h"

class Detector {
public:
    Detector(const std::string& model_path, 
             const std::string& delegate_path,
             const cv::Size& input_shape,
             float score_th,
             float nms_th);

    bool init_model();
    std::pair<std::vector<cv::Rect>, std::vector<float>> detect(const cv::Mat& image);

private:
    std::string model_path_;
    std::string delegate_path_;
    cv::Size input_shape_;
    float score_th_;
    float nms_th_;
    std::unique_ptr<tflite::Interpreter> interpreter_;

    std::pair<cv::Mat, float> preprocess(const cv::Mat& image, const cv::Size& input_size);
    std::tuple<std::vector<cv::Rect>, std::vector<float>, std::vector<int>> postprocess(cv::Mat& outputs, 
                                                                                        const cv::Size& img_size, 
                                                                                        float ratio, 
                                                                                        float score_th, 
                                                                                        float nms_th);
    void meshgrid(const cv::Range& x_range, const cv::Range& y_range, cv::Mat& xv, cv::Mat& yv);
    std::tuple<std::vector<cv::Rect>, std::vector<float>, std::vector<int>> nms(const std::vector<cv::Rect>& bboxes, 
                                                                                const std::vector<float>& scores, 
                                                                                float score_th, 
                                                                                float nms_th);
};

#endif // DETECTOR_H

 

 

 

3. detector.cpp

 

 

 

// detector.cpp
#include "detector.h"
#include <iostream>

Detector::Detector(const std::string& model_path, 
                   const std::string& delegate_path,
                   const cv::Size& input_shape,
                   float score_th,
                   float nms_th)
    : model_path_(model_path),
      delegate_path_(delegate_path),
      input_shape_(input_shape),
      score_th_(score_th),
      nms_th_(nms_th) {}

bool Detector::init_model() {
    auto model = tflite::FlatBufferModel::BuildFromFile(model_path_.c_str());
    if (!model) {
        std::cerr << "Failed to load model from " << model_path_ << std::endl;
        return false;
    }

    auto ext_delegate_option = TfLiteExternalDelegateOptionsDefault(delegate_path_.c_str());
    auto ext_delegate_ptr = TfLiteExternalDelegateCreate(&ext_delegate_option);
    if (!ext_delegate_ptr) {
        std::cerr << "Failed to create external delegate" << std::endl;
        return false;
    }

    tflite::ops::builtin::BuiltinOpResolver resolver;
    resolver.AddCustom(kNbgCustomOp, tflite::ops::custom::Register_VSI_NPU_PRECOMPILED());

    tflite::InterpreterBuilder builder(*model, resolver);
    
    builder(&interpreter_);
    if (!interpreter_) {
        std::cerr << "Failed to build interpreter" << std::endl;
        return false;
    }

    interpreter_->ModifyGraphWithDelegate(ext_delegate_ptr);
    if (interpreter_->AllocateTensors() != kTfLiteOk) {
        std::cerr << "Failed to allocate tensors" << std::endl;
        return false;
    }

    return true;
}

std::pair<cv::Mat, float> Detector::preprocess(const cv::Mat& image, const cv::Size& input_size) {
    float ratio = std::min(static_cast<float>(input_size.width) / image.cols,
                           static_cast<float>(input_size.height) / image.rows);

    cv::Size new_size(static_cast<int>(image.cols * ratio), static_cast<int>(image.rows * ratio));
    cv::Mat resized_image;
    cv::resize(image, resized_image, new_size, 0, 0, cv::INTER_LINEAR);

    cv::Mat padded_image = cv::Mat::ones(input_size, CV_8UC3) * 114;
    resized_image.copyTo(padded_image(cv::Rect(0, 0, resized_image.cols, resized_image.rows)));

    std::vector<cv::Mat> channels(3);
    cv::split(padded_image, channels);

    cv::Mat chw_image(3, input_size.height * input_size.width, CV_32F);
    for(int i = 0; i < 3; ++i) {
        channels[i].convertTo(channels[i], CV_32F);
        std::memcpy(chw_image.ptr<float>(i), channels[i].data, channels[i].total() * sizeof(float));
    }

    cv::Mat reshaped_image = chw_image.reshape(1, {1, 3, input_size.height, input_size.width});
    return std::make_pair(reshaped_image, ratio);
}

std::tuple<std::vector<cv::Rect>, std::vector<float>, std::vector<int>> Detector::postprocess(cv::Mat& outputs, 
                                                                                            const cv::Size& img_size, 
                                                                                            float ratio, 
                                                                                            float score_th, 
                                                                                            float nms_th) {
    std::vector<cv::Rect> bboxes;
    std::vector<float> scores;
    std::vector<int> class_ids;

    std::vector<int> strides = {8, 16, 32};
    std::vector<cv::Mat> grids;
    std::vector<cv::Mat> expanded_strides;

    for (int stride : strides) {
        int hsize = img_size.height / stride;
        int wsize = img_size.width / stride;

        cv::Mat xv, yv;
        meshgrid(cv::Range(0, wsize - 1), cv::Range(0, hsize - 1), xv, yv);
        cv::Mat grid;
        cv::hconcat(xv.reshape(1, 1), yv.reshape(1, 1), grid);

        grids.push_back(grid.reshape(2, 1));
        expanded_strides.push_back(cv::Mat(grid.size(), CV_32F, cv::Scalar(stride)));
    }

    cv::Mat grid_cat, stride_cat;
    cv::vconcat(grids, grid_cat);
    cv::vconcat(expanded_strides, stride_cat);

    outputs.colRange(2, 4).convertTo(outputs.colRange(2, 4), CV_32F);
    
    cv::Mat exp_colRange(outputs.colRange(2, 4).size(), CV_32F);
    cv::exp(outputs.colRange(2, 4), exp_colRange);
    
    outputs.colRange(0, 2) = (outputs.colRange(0, 2) + grid_cat) * stride_cat;
    outputs.colRange(2, 4) = exp_colRange.mul(stride_cat);

    cv::Mat predictions = outputs.row(0);
    cv::Mat bboxes_mat = predictions.colRange(0, 4);
    cv::Mat scores_mat = predictions.col(4).mul(predictions.colRange(5, predictions.cols));
    scores.assign(scores_mat.begin<float>(), scores_mat.end<float>());

    std::vector<cv::Rect> bboxes_xyxy(bboxes_mat.rows);
    for (int i = 0; i < bboxes_mat.rows; ++i) {
        float x_center = bboxes_mat.at<float>(i, 0);
        float y_center = bboxes_mat.at<float>(i, 1);
        float width = bboxes_mat.at<float>(i, 2);
        float height = bboxes_mat.at<float>(i, 3);

        float x_min = x_center - width / 2.0;
        float y_min = y_center - height / 2.0;
        float x_max = x_center + width / 2.0;
        float y_max = y_center + height / 2.0;

        bboxes_xyxy[i] = cv::Rect(cv::Point(x_min / ratio, y_min / ratio), cv::Point(x_max / ratio, y_max / ratio));
    }

    return nms(bboxes_xyxy, scores, score_th, nms_th);
}

void Detector::meshgrid(const cv::Range& x_range, const cv::Range& y_range, cv::Mat& xv, cv::Mat& yv) {
    cv::Mat x_coords = cv::Mat(x_range.size(), 1, CV_32F);
    cv::Mat y_coords = cv::Mat(y_range.size(), 1, CV_32F);
    
    for (int i = 0; i < x_range.size(); ++i) {
        x_coords.at<float>(i,0) = x_range.start + i;
    }
    
    for (int i = 0; i < y_range.size(); ++i) {
        y_coords.at<float>(i,0) = y_range.start + i;
    } 
    
    cv::repeat(x_coords, 1, y_range.size(), xv);
    cv::repeat(y_coords.t(), x_range.size(), 1, yv);
}

std::tuple<std::vector<cv::Rect>, std::vector<float>, std::vector<int>> Detector::nms(const std::vector<cv::Rect>& bboxes, 
                                                                                        const std::vector<float>& scores, 
                                                                                        float score_th, 
                                                                                        float nms_th) {
    std::vector<cv::Rect> bboxes_filtered;
    std::vector<float> scores_filtered;
    std::vector<int> class_ids_filtered;

    std::vector<int> indices;
    cv::dnn::NMSBoxes(bboxes, scores, score_th, nms_th, indices);
    
    for(int idx : indices) {
        bboxes_filtered.push_back(bboxes[idx]);
        scores_filtered.push_back(scores[idx]);
        class_ids_filtered.push_back(0);
    }

    return std::make_tuple(bboxes_filtered, scores_filtered, class_ids_filtered);
}

std::pair<std::vector<cv::Rect>, std::vector<float>> Detector::detect(const cv::Mat& image) {
    cv::Mat temp_image = image.clone();
    
    auto [preprocessed_image, ratio] = preprocess(temp_image, input_shape_);
    
    std::cout << "Preprocess Completed"<<std::endl;

    // Setting input tensor
    TfLiteTensor* input_data = interpreter_->tensor(interpreter_->inputs()[0]);
    const uint input_width = input_data->dims->data[3];
    const uint input_height = input_data->dims->data[2];
    const uint input_channels = input_data->dims->data[1];
    const uint batch_size = input_data->dims->data[0];

    std::cout << "Expected dimension: "<< batch_size << "x" << input_channels << "x" << input_height << "x" << input_width << std::endl;

    const uint image_width = preprocessed_image.size[3];
    const uint image_height = preprocessed_image.size[2];
    const uint image_channels = preprocessed_image.size[1];
    const uint image_batch_size = preprocessed_image.size[0];

    std::cout << "Image dimension: "<< image_batch_size << "x" << image_channels << "x" << image_height << "x" << image_width << std::endl;

    if(input_data->type !=kTfLiteFloat32){
        std::cerr << "input tensor is not of type float" << std::endl;
        return std::make_pair(std::vector<cv::Rect>(), std::vector<float>());
    }

    if(input_data->data.f == nullptr) {
        std::cerr << "input tensor data pointer is null" << std::endl;
        return std::make_pair(std::vector<cv::Rect>(), std::vector<float>());
    }
    std::memcpy(input_data->data.f, preprocessed_image.ptr<float>(0), batch_size * input_width * input_height * input_channels * sizeof(float));

    if(memcmp(input_data->data.f, preprocessed_image.ptr<float>(0),batch_size * input_width * input_height * input_channels * sizeof(float)) != 0){
        std::cerr << "data copy to input tensor failed" << std::endl;
        return std::make_pair(std::vector<cv::Rect>(), std::vector<float>());
    }
    else{
        std::cout << "Set up Input Tensor Completed"<<std::endl;
    }

    // Running inference
    interpreter_->Invoke();

    std::cout << "Inference Completed"<<std::endl;

    // Getting output tensor
    float* output_tensor = interpreter_->typed_output_tensor<float>(0);
    size_t output_size = interpreter_->tensor(interpreter_->outputs()[0])->bytes / sizeof(float);    
    cv::Mat results(1, output_size, CV_32F, output_tensor);

    std::cout << "Get Results Completed"<<std::endl;

    // Postprocessing
    auto [bboxes_xyxy, scores, class_ids] = postprocess(results, input_shape_, ratio, score_th_, nms_th_);

    // Converting the bboxes to cv::Rect and packing results
    std::vector<cv::Rect> result_rect_list;
    for (size_t i = 0; i < bboxes_xyxy.size(); ++i) {
        result_rect_list.push_back(bboxes_xyxy[i]);
    }

    // Returning the list of rectangles and the associated scores
    return {result_rect_list, scores};
}

 

 

 


my board image is nanbield 6.6.3_1.0.0 full image

I tried to run it using VX Delegate and NPU and encounter a problem when running the code

 

 

 

 

root@imx8mpevk:/run/media/SD CARD-sda1/test_npu# ./detector_app lena_color_512.tif
INFO: Vx delegate: allowed_cache_mode set to 0.
INFO: Vx delegate: device num set to 0.
INFO: Vx delegate: allowed_builtin_code set to 0.
INFO: Vx delegate: error_during_init set to 0.
INFO: Vx delegate: error_during_prepare set to 0.
INFO: Vx delegate: error_during_invoke set to 0.
Preprocess Completed
Expected dimension: 1x3x192x192
Image dimension: 1x3x192x192
Set up Input Tensor Completed
E [/usr/src/debug/tim-vx/1.1.88-r[  126.612163] audit: type=1701 audit(1695250801.923:18): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=1270 comm="detector_app" exe=2F72756E2F6D656469612F534420434152442D736461312F746573745F6E70752F6465746563746F725F617070 sig=6 res=1
0/src/tim/transform/ops/op_layout_inference.cc:MapAxis:177]Map axis failed.
detector_app: /usr/src/debug/tim-vx/1.1.88-r0/src/tim/transform/ops/op_layout_inference.cc:178: uint32_t tim::transform::OpLayoutInfer::MapAxis(const std::vector<unsigned int>&, uint32_t): Assertion `false' failed.
Aborted (core dumped)

 

 

 

 


I also tried to get the gdb debug running, and it return something like this:

 

 

 

 

(gdb) set args lena_color_512.tif
(gdb) run
Starting program: /run/media/SD CARD-sda1/test_npu/detector_app lena_color_512.tif
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
INFO: Vx delegate: allowed_cache_mode set to 0.
INFO: Vx delegate: device num set to 0.
INFO: Vx delegate: allowed_builtin_code set to 0.
INFO: Vx delegate: error_during_init set to 0.
INFO: Vx delegate: error_during_prepare set to 0.
INFO: Vx delegate: error_during_invoke set to 0.
Preprocess Completed
Expected dimension: 1x3x192x192
Image dimension: 1x3x192x192
Set up Input Tensor Completed
[New Thread 0xfffff146cf00 (LWP 1660)]
E [/usr/src/debug/tim-vx/1.1.88-r0/src/tim/transform/ops/op_layout_inference.cc:MapAxis:177]Map axis failed.
detector_app: /usr/src/debug/tim-vx/1.1.88-r0/src/tim/transform/ops/op_layout_inference.cc:178: uint32_t tim::transform::OpLayoutInfer::MapAxis(const std::vector<unsigned int>&, uint32_t): Assertion `false' failed.

Thread 1 "detector_app" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44      pthread_kill.c: No such file or directory.
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x0000fffff69c0568 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x0000fffff697acd0 in __GI_raise (sig=sig@entry=6) at /usr/src/debug/glibc/2.38+git-r0/sysdeps/posix/raise.c:26
#3  0x0000fffff6966ef0 in __GI_abort () at abort.c:79
#4  0x0000fffff69743f8 in __assert_fail_base (fmt=0xfffff6a8a8e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0xfffff1ffdcf0 "false",
    file=file@entry=0xfffff1fff568 "/usr/src/debug/tim-vx/1.1.88-r0/src/tim/transform/ops/op_layout_inference.cc", line=line@entry=178,
    function=function@entry=0xfffff1fff5d8 "uint32_t tim::transform::OpLayoutInfer::MapAxis(const std::vector<unsigned int>&, uint32_t)") at assert.c:92
#5  0x0000fffff6974470 in __assert_fail (assertion=0xfffff1ffdcf0 "false", file=0xfffff1fff568 "/usr/src/debug/tim-vx/1.1.88-r0/src/tim/transform/ops/op_layout_inference.cc", line=178,
    function=0xfffff1fff5d8 "uint32_t tim::transform::OpLayoutInfer::MapAxis(const std::vector<unsigned int>&, uint32_t)") at assert.c:101
#6  0x0000fffff1fa5f74 in tim::transform::OpLayoutInfer::MapAxis(std::vector<unsigned int, std::allocator<unsigned int> > const&, unsigned int) () from /usr/lib/libtim-vx.so
#7  0x0000fffff1f6a1b0 in ?? () from /usr/lib/libtim-vx.so
#8  0x0000fffff1f4e5f4 in tim::transform::layout_inference_impl::HandleLayoutInfer(std::shared_ptr<tim::transform::layout_inference_impl::LayoutInferContext>&, std::shared_ptr<tim::vx::Operation> const&) () from /usr/lib/libtim-vx.so
#9  0x0000fffff1f531f4 in tim::transform::LayoutInference(std::shared_ptr<tim::vx::Graph> const&, std::shared_ptr<tim::vx::Context>&, std::map<std::shared_ptr<tim::vx::Tensor>, std::shared_ptr<tim::transform::IPermuteVector>, std::less<std::shared_ptr<tim::vx::Tensor> >, std::allocator<std::pair<std::shared_ptr<tim::vx::Tensor> const, std::shared_ptr<tim::transform::IPermuteVector> > > >) () from /usr/lib/libtim-vx.so
#10 0x0000fffff23d85ac in vx::delegate::Delegate::Invoke(vx::delegate::OpData const&, TfLiteContext*, TfLiteNode*) () from /usr/lib/libvx_delegate.so
#11 0x0000fffff7be9d9c in tflite::Subgraph::InvokeImpl() () from /usr/lib/libtensorflow-lite.so.2.14.0
#12 0x0000fffff7bea388 in tflite::Subgraph::Invoke() () from /usr/lib/libtensorflow-lite.so.2.14.0
#13 0x0000fffff7bd440c in tflite::impl::Interpreter::Invoke() () from /usr/lib/libtensorflow-lite.so.2.14.0
#14 0x0000aaaaaaaa62e0 in Detector::detect (this=this@entry=0xfffffffff890, image=...)
    at /home/ubuntu/imx-yocto-bsp/sdk/sysroots/armv8a-poky-linux/usr/include/c++/13.2.0/bits/unique_ptr.h:199
#15 0x0000aaaaaaaa35b0 in main (argc=<optimized out>, argv=<optimized out>) at /home/ubuntu/imx-yocto-bsp/tflite_test/build_minim/main.cpp:29

 

Does anyone have a clue what is wrong? because I am not sure what happened here. but what i only know that the assertion at op_layout_inference.cc:MapAxis:177 Map axis failed because of assertion error (?)

Thank you in advance

0 Kudos
Reply
1 Solution
1,582 Views
astel_
Contributor II

I found the cause of the problem. Apparently this line caused the error:

 

resolver.AddCustom(kNbgCustomOp, tflite::ops::custom::Register_VSI_NPU_PRECOMPILED());

 

So for now, i just disable it and magically it works. Maybe someone can explain why it trigger the error, but for now I can finally continue with my app development.

For the model, I check it using Python code, and apparently no error, so the model itself is compatible with the NPU run. 

Thank you

View solution in original post

0 Kudos
Reply
3 Replies
1,695 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

It looks tile the assertion is there to say that as far as you aware, has made it impossible to call the zero-args constructor according is private and so if a call occurs, that assertion has been violated per your error.

Regards

0 Kudos
Reply
1,686 Views
astel_
Contributor II
is it possible that the model is not compatible with the NPU/VX delegate run?

bc when i try to run it with CPU i got different error (related to one of the StridedSlice layer, but i havent check it properly yet for CPU run)
0 Kudos
Reply
1,583 Views
astel_
Contributor II

I found the cause of the problem. Apparently this line caused the error:

 

resolver.AddCustom(kNbgCustomOp, tflite::ops::custom::Register_VSI_NPU_PRECOMPILED());

 

So for now, i just disable it and magically it works. Maybe someone can explain why it trigger the error, but for now I can finally continue with my app development.

For the model, I check it using Python code, and apparently no error, so the model itself is compatible with the NPU run. 

Thank you

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1947070%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ETfLite%20NPU%20run%20error%20op_layout_inference.cc%3AMapAxis%3A177%20Map%20axis%20failed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1947070%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20everyone%3CBR%20%2F%3E%3CBR%20%2F%3ESorry%20for%20asking.%20I%20tried%20to%20build%20my%20own%20C%2B%2B%20program%20which%20is%20a%20converted%20program%20from%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FKazuhito00%2FPerson-Detection-using-RaspberryPi-CPU%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Epython%3C%2FA%3E%26nbsp%3B%2C%20to%20run%20a%20simple%20model%20to%20detect%20people%20for%20my%20board%20imx8m%20plus.%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20Code%3A%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20main.cpp%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3E%2F%2F%20main.cpp%0A%23include%20%22detector.h%22%0A%23include%20%3COPENCV2%3E%0A%0Aint%20main(int%20argc%2C%20char*%20argv%5B%5D)%20%7B%0A%20%20%20%20if%20(argc%20!%3D%202)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Usage%3A%20%22%20%26lt%3B%26lt%3B%20argv%5B0%5D%20%26lt%3B%26lt%3B%20%22%20%3CIMAGE_PATH%3E%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20std%3A%3Astring%20image_path%20%3D%20argv%5B1%5D%3B%0A%20%20%20%20std%3A%3Astring%20model_path%20%3D%20%22model.tflite%22%3B%0A%20%20%20%20std%3A%3Astring%20delegate_path%20%3D%20%22%2Fusr%2Flib%2Flibvx_delegate.so%22%3B%0A%20%20%20%20cv%3A%3ASize%20input_size(192%2C%20192)%3B%0A%20%20%20%20float%20score_th%20%3D%200.5%3B%0A%20%20%20%20float%20nms_th%20%3D%200.4%3B%0A%0A%20%20%20%20Detector%20detector(model_path%2C%20delegate_path%2C%20input_size%2C%20score_th%2C%20nms_th)%3B%0A%20%20%20%20if%20(!detector.init_model())%20%7B%0A%20%20%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20cv%3A%3AMat%20image%20%3D%20cv%3A%3Aimread(image_path)%3B%0A%20%20%20%20if%20(image.empty())%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Failed%20to%20load%20image%20from%20%22%20%26lt%3B%26lt%3B%20image_path%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20auto%20%5Bbboxes%2C%20scores%5D%20%3D%20detector.detect(image)%3B%0A%0A%20%20%20%20for%20(size_t%20i%20%3D%200%3B%20i%20%26lt%3B%20bboxes.size()%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20cv%3A%3Arectangle(image%2C%20bboxes%5Bi%5D%2C%20cv%3A%3AScalar(0%2C%20255%2C%200)%2C%202)%3B%0A%20%20%20%20%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Detected%20bbox%3A%20%22%20%26lt%3B%26lt%3B%20bboxes%5Bi%5D%20%26lt%3B%26lt%3B%20%22%20with%20score%3A%20%22%20%26lt%3B%26lt%3B%20scores%5Bi%5D%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20cv%3A%3Aimshow(%22Detections%22%2C%20image)%3B%0A%20%20%20%20cv%3A%3AwaitKey(0)%3B%0A%0A%20%20%20%20return%200%3B%0A%7D%3C%2FIMAGE_PATH%3E%3C%2FOPENCV2%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E%3CBR%20%2F%3E2.%20detector.h%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3E%2F%2F%20detector.h%0A%23ifndef%20DETECTOR_H%0A%23define%20DETECTOR_H%0A%0A%23include%20%3COPENCV2%3E%0A%23include%20%3CTENSORFLOW%3E%0A%23include%20%3CTENSORFLOW%3E%0A%23include%20%3CTENSORFLOW%3E%0A%23include%20%3CTENSORFLOW%3E%0A%23include%20%3CTENSORFLOW%3E%0A%23include%20%3CTENSORFLOW-LITE-VX-DELEGATE%3E%0A%23include%20%22delegate_main.h%22%0A%0Aclass%20Detector%20%7B%0Apublic%3A%0A%20%20%20%20Detector(const%20std%3A%3Astring%26amp%3B%20model_path%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20const%20std%3A%3Astring%26amp%3B%20delegate_path%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20const%20cv%3A%3ASize%26amp%3B%20input_shape%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%3B%0A%0A%20%20%20%20bool%20init_model()%3B%0A%20%20%20%20std%3A%3Apair%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%26gt%3B%20detect(const%20cv%3A%3AMat%26amp%3B%20image)%3B%0A%0Aprivate%3A%0A%20%20%20%20std%3A%3Astring%20model_path_%3B%0A%20%20%20%20std%3A%3Astring%20delegate_path_%3B%0A%20%20%20%20cv%3A%3ASize%20input_shape_%3B%0A%20%20%20%20float%20score_th_%3B%0A%20%20%20%20float%20nms_th_%3B%0A%20%20%20%20std%3A%3Aunique_ptr%26lt%3B%3Ainterpreter%26gt%3B%20interpreter_%3B%0A%0A%20%20%20%20std%3A%3Apair%26lt%3B%3Amat%26gt%3B%20preprocess(const%20cv%3A%3AMat%26amp%3B%20image%2C%20const%20cv%3A%3ASize%26amp%3B%20input_size)%3B%0A%20%20%20%20std%3A%3Atuple%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%2C%20std%3A%3Avector%3CINT%3E%26gt%3B%20postprocess(cv%3A%3AMat%26amp%3B%20outputs%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20cv%3A%3ASize%26amp%3B%20img_size%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20ratio%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%3B%0A%20%20%20%20void%20meshgrid(const%20cv%3A%3ARange%26amp%3B%20x_range%2C%20const%20cv%3A%3ARange%26amp%3B%20y_range%2C%20cv%3A%3AMat%26amp%3B%20xv%2C%20cv%3A%3AMat%26amp%3B%20yv)%3B%0A%20%20%20%20std%3A%3Atuple%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%2C%20std%3A%3Avector%3CINT%3E%26gt%3B%20nms(const%20std%3A%3Avector%26lt%3B%3Arect%26gt%3B%26amp%3B%20bboxes%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20std%3A%3Avector%3CFLOAT%3E%26amp%3B%20scores%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%3B%0A%7D%3B%0A%0A%23endif%20%2F%2F%20DETECTOR_H%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FTENSORFLOW-LITE-VX-DELEGATE%3E%3C%2FTENSORFLOW%3E%3C%2FTENSORFLOW%3E%3C%2FTENSORFLOW%3E%3C%2FTENSORFLOW%3E%3C%2FTENSORFLOW%3E%3C%2FOPENCV2%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E3.%20detector.cpp%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3E%2F%2F%20detector.cpp%0A%23include%20%22detector.h%22%0A%23include%20%3CIOSTREAM%3E%0A%0ADetector%3A%3ADetector(const%20std%3A%3Astring%26amp%3B%20model_path%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20std%3A%3Astring%26amp%3B%20delegate_path%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20cv%3A%3ASize%26amp%3B%20input_shape%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%0A%20%20%20%20%3A%20model_path_(model_path)%2C%0A%20%20%20%20%20%20delegate_path_(delegate_path)%2C%0A%20%20%20%20%20%20input_shape_(input_shape)%2C%0A%20%20%20%20%20%20score_th_(score_th)%2C%0A%20%20%20%20%20%20nms_th_(nms_th)%20%7B%7D%0A%0Abool%20Detector%3A%3Ainit_model()%20%7B%0A%20%20%20%20auto%20model%20%3D%20tflite%3A%3AFlatBufferModel%3A%3ABuildFromFile(model_path_.c_str())%3B%0A%20%20%20%20if%20(!model)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Failed%20to%20load%20model%20from%20%22%20%26lt%3B%26lt%3B%20model_path_%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20auto%20ext_delegate_option%20%3D%20TfLiteExternalDelegateOptionsDefault(delegate_path_.c_str())%3B%0A%20%20%20%20auto%20ext_delegate_ptr%20%3D%20TfLiteExternalDelegateCreate(%26amp%3Bext_delegate_option)%3B%0A%20%20%20%20if%20(!ext_delegate_ptr)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Failed%20to%20create%20external%20delegate%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20tflite%3A%3Aops%3A%3Abuiltin%3A%3ABuiltinOpResolver%20resolver%3B%0A%20%20%20%20resolver.AddCustom(kNbgCustomOp%2C%20tflite%3A%3Aops%3A%3Acustom%3A%3ARegister_VSI_NPU_PRECOMPILED())%3B%0A%0A%20%20%20%20tflite%3A%3AInterpreterBuilder%20builder(*model%2C%20resolver)%3B%0A%20%20%20%20%0A%20%20%20%20builder(%26amp%3Binterpreter_)%3B%0A%20%20%20%20if%20(!interpreter_)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Failed%20to%20build%20interpreter%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20interpreter_-%26gt%3BModifyGraphWithDelegate(ext_delegate_ptr)%3B%0A%20%20%20%20if%20(interpreter_-%26gt%3BAllocateTensors()%20!%3D%20kTfLiteOk)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22Failed%20to%20allocate%20tensors%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20return%20true%3B%0A%7D%0A%0Astd%3A%3Apair%26lt%3B%3Amat%26gt%3B%20Detector%3A%3Apreprocess(const%20cv%3A%3AMat%26amp%3B%20image%2C%20const%20cv%3A%3ASize%26amp%3B%20input_size)%20%7B%0A%20%20%20%20float%20ratio%20%3D%20std%3A%3Amin(static_cast%3CFLOAT%3E(input_size.width)%20%2F%20image.cols%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20static_cast%3CFLOAT%3E(input_size.height)%20%2F%20image.rows)%3B%0A%0A%20%20%20%20cv%3A%3ASize%20new_size(static_cast%3CINT%3E(image.cols%20*%20ratio)%2C%20static_cast%3CINT%3E(image.rows%20*%20ratio))%3B%0A%20%20%20%20cv%3A%3AMat%20resized_image%3B%0A%20%20%20%20cv%3A%3Aresize(image%2C%20resized_image%2C%20new_size%2C%200%2C%200%2C%20cv%3A%3AINTER_LINEAR)%3B%0A%0A%20%20%20%20cv%3A%3AMat%20padded_image%20%3D%20cv%3A%3AMat%3A%3Aones(input_size%2C%20CV_8UC3)%20*%20114%3B%0A%20%20%20%20resized_image.copyTo(padded_image(cv%3A%3ARect(0%2C%200%2C%20resized_image.cols%2C%20resized_image.rows)))%3B%0A%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Amat%26gt%3B%20channels(3)%3B%0A%20%20%20%20cv%3A%3Asplit(padded_image%2C%20channels)%3B%0A%0A%20%20%20%20cv%3A%3AMat%20chw_image(3%2C%20input_size.height%20*%20input_size.width%2C%20CV_32F)%3B%0A%20%20%20%20for(int%20i%20%3D%200%3B%20i%20%26lt%3B%203%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20channels%5Bi%5D.convertTo(channels%5Bi%5D%2C%20CV_32F)%3B%0A%20%20%20%20%20%20%20%20std%3A%3Amemcpy(chw_image.ptr%3CFLOAT%3E(i)%2C%20channels%5Bi%5D.data%2C%20channels%5Bi%5D.total()%20*%20sizeof(float))%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20cv%3A%3AMat%20reshaped_image%20%3D%20chw_image.reshape(1%2C%20%7B1%2C%203%2C%20input_size.height%2C%20input_size.width%7D)%3B%0A%20%20%20%20return%20std%3A%3Amake_pair(reshaped_image%2C%20ratio)%3B%0A%7D%0A%0Astd%3A%3Atuple%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%2C%20std%3A%3Avector%3CINT%3E%26gt%3B%20Detector%3A%3Apostprocess(cv%3A%3AMat%26amp%3B%20outputs%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20cv%3A%3ASize%26amp%3B%20img_size%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20ratio%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%20%7B%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Arect%26gt%3B%20bboxes%3B%0A%20%20%20%20std%3A%3Avector%3CFLOAT%3E%20scores%3B%0A%20%20%20%20std%3A%3Avector%3CINT%3E%20class_ids%3B%0A%0A%20%20%20%20std%3A%3Avector%3CINT%3E%20strides%20%3D%20%7B8%2C%2016%2C%2032%7D%3B%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Amat%26gt%3B%20grids%3B%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Amat%26gt%3B%20expanded_strides%3B%0A%0A%20%20%20%20for%20(int%20stride%20%3A%20strides)%20%7B%0A%20%20%20%20%20%20%20%20int%20hsize%20%3D%20img_size.height%20%2F%20stride%3B%0A%20%20%20%20%20%20%20%20int%20wsize%20%3D%20img_size.width%20%2F%20stride%3B%0A%0A%20%20%20%20%20%20%20%20cv%3A%3AMat%20xv%2C%20yv%3B%0A%20%20%20%20%20%20%20%20meshgrid(cv%3A%3ARange(0%2C%20wsize%20-%201)%2C%20cv%3A%3ARange(0%2C%20hsize%20-%201)%2C%20xv%2C%20yv)%3B%0A%20%20%20%20%20%20%20%20cv%3A%3AMat%20grid%3B%0A%20%20%20%20%20%20%20%20cv%3A%3Ahconcat(xv.reshape(1%2C%201)%2C%20yv.reshape(1%2C%201)%2C%20grid)%3B%0A%0A%20%20%20%20%20%20%20%20grids.push_back(grid.reshape(2%2C%201))%3B%0A%20%20%20%20%20%20%20%20expanded_strides.push_back(cv%3A%3AMat(grid.size()%2C%20CV_32F%2C%20cv%3A%3AScalar(stride)))%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20cv%3A%3AMat%20grid_cat%2C%20stride_cat%3B%0A%20%20%20%20cv%3A%3Avconcat(grids%2C%20grid_cat)%3B%0A%20%20%20%20cv%3A%3Avconcat(expanded_strides%2C%20stride_cat)%3B%0A%0A%20%20%20%20outputs.colRange(2%2C%204).convertTo(outputs.colRange(2%2C%204)%2C%20CV_32F)%3B%0A%20%20%20%20%0A%20%20%20%20cv%3A%3AMat%20exp_colRange(outputs.colRange(2%2C%204).size()%2C%20CV_32F)%3B%0A%20%20%20%20cv%3A%3Aexp(outputs.colRange(2%2C%204)%2C%20exp_colRange)%3B%0A%20%20%20%20%0A%20%20%20%20outputs.colRange(0%2C%202)%20%3D%20(outputs.colRange(0%2C%202)%20%2B%20grid_cat)%20*%20stride_cat%3B%0A%20%20%20%20outputs.colRange(2%2C%204)%20%3D%20exp_colRange.mul(stride_cat)%3B%0A%0A%20%20%20%20cv%3A%3AMat%20predictions%20%3D%20outputs.row(0)%3B%0A%20%20%20%20cv%3A%3AMat%20bboxes_mat%20%3D%20predictions.colRange(0%2C%204)%3B%0A%20%20%20%20cv%3A%3AMat%20scores_mat%20%3D%20predictions.col(4).mul(predictions.colRange(5%2C%20predictions.cols))%3B%0A%20%20%20%20scores.assign(scores_mat.begin%3CFLOAT%3E()%2C%20scores_mat.end%3CFLOAT%3E())%3B%0A%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Arect%26gt%3B%20bboxes_xyxy(bboxes_mat.rows)%3B%0A%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%26lt%3B%20bboxes_mat.rows%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20float%20x_center%20%3D%20bboxes_mat.at%3CFLOAT%3E(i%2C%200)%3B%0A%20%20%20%20%20%20%20%20float%20y_center%20%3D%20bboxes_mat.at%3CFLOAT%3E(i%2C%201)%3B%0A%20%20%20%20%20%20%20%20float%20width%20%3D%20bboxes_mat.at%3CFLOAT%3E(i%2C%202)%3B%0A%20%20%20%20%20%20%20%20float%20height%20%3D%20bboxes_mat.at%3CFLOAT%3E(i%2C%203)%3B%0A%0A%20%20%20%20%20%20%20%20float%20x_min%20%3D%20x_center%20-%20width%20%2F%202.0%3B%0A%20%20%20%20%20%20%20%20float%20y_min%20%3D%20y_center%20-%20height%20%2F%202.0%3B%0A%20%20%20%20%20%20%20%20float%20x_max%20%3D%20x_center%20%2B%20width%20%2F%202.0%3B%0A%20%20%20%20%20%20%20%20float%20y_max%20%3D%20y_center%20%2B%20height%20%2F%202.0%3B%0A%0A%20%20%20%20%20%20%20%20bboxes_xyxy%5Bi%5D%20%3D%20cv%3A%3ARect(cv%3A%3APoint(x_min%20%2F%20ratio%2C%20y_min%20%2F%20ratio)%2C%20cv%3A%3APoint(x_max%20%2F%20ratio%2C%20y_max%20%2F%20ratio))%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20return%20nms(bboxes_xyxy%2C%20scores%2C%20score_th%2C%20nms_th)%3B%0A%7D%0A%0Avoid%20Detector%3A%3Ameshgrid(const%20cv%3A%3ARange%26amp%3B%20x_range%2C%20const%20cv%3A%3ARange%26amp%3B%20y_range%2C%20cv%3A%3AMat%26amp%3B%20xv%2C%20cv%3A%3AMat%26amp%3B%20yv)%20%7B%0A%20%20%20%20cv%3A%3AMat%20x_coords%20%3D%20cv%3A%3AMat(x_range.size()%2C%201%2C%20CV_32F)%3B%0A%20%20%20%20cv%3A%3AMat%20y_coords%20%3D%20cv%3A%3AMat(y_range.size()%2C%201%2C%20CV_32F)%3B%0A%20%20%20%20%0A%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%26lt%3B%20x_range.size()%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20x_coords.at%3CFLOAT%3E(i%2C0)%20%3D%20x_range.start%20%2B%20i%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%26lt%3B%20y_range.size()%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20y_coords.at%3CFLOAT%3E(i%2C0)%20%3D%20y_range.start%20%2B%20i%3B%0A%20%20%20%20%7D%20%0A%20%20%20%20%0A%20%20%20%20cv%3A%3Arepeat(x_coords%2C%201%2C%20y_range.size()%2C%20xv)%3B%0A%20%20%20%20cv%3A%3Arepeat(y_coords.t()%2C%20x_range.size()%2C%201%2C%20yv)%3B%0A%7D%0A%0Astd%3A%3Atuple%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%2C%20std%3A%3Avector%3CINT%3E%26gt%3B%20Detector%3A%3Anms(const%20std%3A%3Avector%26lt%3B%3Arect%26gt%3B%26amp%3B%20bboxes%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20std%3A%3Avector%3CFLOAT%3E%26amp%3B%20scores%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20score_th%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20float%20nms_th)%20%7B%0A%20%20%20%20std%3A%3Avector%26lt%3B%3Arect%26gt%3B%20bboxes_filtered%3B%0A%20%20%20%20std%3A%3Avector%3CFLOAT%3E%20scores_filtered%3B%0A%20%20%20%20std%3A%3Avector%3CINT%3E%20class_ids_filtered%3B%0A%0A%20%20%20%20std%3A%3Avector%3CINT%3E%20indices%3B%0A%20%20%20%20cv%3A%3Adnn%3A%3ANMSBoxes(bboxes%2C%20scores%2C%20score_th%2C%20nms_th%2C%20indices)%3B%0A%20%20%20%20%0A%20%20%20%20for(int%20idx%20%3A%20indices)%20%7B%0A%20%20%20%20%20%20%20%20bboxes_filtered.push_back(bboxes%5Bidx%5D)%3B%0A%20%20%20%20%20%20%20%20scores_filtered.push_back(scores%5Bidx%5D)%3B%0A%20%20%20%20%20%20%20%20class_ids_filtered.push_back(0)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20return%20std%3A%3Amake_tuple(bboxes_filtered%2C%20scores_filtered%2C%20class_ids_filtered)%3B%0A%7D%0A%0Astd%3A%3Apair%26lt%3B%3Avector%26gt%3B%26lt%3B%3Arect%26gt%3B%2C%20std%3A%3Avector%3CFLOAT%3E%26gt%3B%20Detector%3A%3Adetect(const%20cv%3A%3AMat%26amp%3B%20image)%20%7B%0A%20%20%20%20cv%3A%3AMat%20temp_image%20%3D%20image.clone()%3B%0A%20%20%20%20%0A%20%20%20%20auto%20%5Bpreprocessed_image%2C%20ratio%5D%20%3D%20preprocess(temp_image%2C%20input_shape_)%3B%0A%20%20%20%20%0A%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Preprocess%20Completed%22%26lt%3B%26lt%3B%3Aendl%26gt%3Btensor(interpreter_-%26gt%3Binputs()%5B0%5D)%3B%0A%20%20%20%20const%20uint%20input_width%20%3D%20input_data-%26gt%3Bdims-%26gt%3Bdata%5B3%5D%3B%0A%20%20%20%20const%20uint%20input_height%20%3D%20input_data-%26gt%3Bdims-%26gt%3Bdata%5B2%5D%3B%0A%20%20%20%20const%20uint%20input_channels%20%3D%20input_data-%26gt%3Bdims-%26gt%3Bdata%5B1%5D%3B%0A%20%20%20%20const%20uint%20batch_size%20%3D%20input_data-%26gt%3Bdims-%26gt%3Bdata%5B0%5D%3B%0A%0A%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Expected%20dimension%3A%20%22%26lt%3B%26lt%3B%20batch_size%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20input_channels%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20input_height%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20input_width%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%0A%20%20%20%20const%20uint%20image_width%20%3D%20preprocessed_image.size%5B3%5D%3B%0A%20%20%20%20const%20uint%20image_height%20%3D%20preprocessed_image.size%5B2%5D%3B%0A%20%20%20%20const%20uint%20image_channels%20%3D%20preprocessed_image.size%5B1%5D%3B%0A%20%20%20%20const%20uint%20image_batch_size%20%3D%20preprocessed_image.size%5B0%5D%3B%0A%0A%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Image%20dimension%3A%20%22%26lt%3B%26lt%3B%20image_batch_size%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20image_channels%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20image_height%20%26lt%3B%26lt%3B%20%22x%22%20%26lt%3B%26lt%3B%20image_width%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%0A%20%20%20%20if(input_data-%26gt%3Btype%20!%3DkTfLiteFloat32)%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22input%20tensor%20is%20not%20of%20type%20float%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20std%3A%3Amake_pair(std%3A%3Avector%26lt%3B%3Arect%26gt%3B()%2C%20std%3A%3Avector%3CFLOAT%3E())%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20if(input_data-%26gt%3Bdata.f%20%3D%3D%20nullptr)%20%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22input%20tensor%20data%20pointer%20is%20null%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20std%3A%3Amake_pair(std%3A%3Avector%26lt%3B%3Arect%26gt%3B()%2C%20std%3A%3Avector%3CFLOAT%3E())%3B%0A%20%20%20%20%7D%0A%20%20%20%20std%3A%3Amemcpy(input_data-%26gt%3Bdata.f%2C%20preprocessed_image.ptr%3CFLOAT%3E(0)%2C%20batch_size%20*%20input_width%20*%20input_height%20*%20input_channels%20*%20sizeof(float))%3B%0A%0A%20%20%20%20if(memcmp(input_data-%26gt%3Bdata.f%2C%20preprocessed_image.ptr%3CFLOAT%3E(0)%2Cbatch_size%20*%20input_width%20*%20input_height%20*%20input_channels%20*%20sizeof(float))%20!%3D%200)%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acerr%20%26lt%3B%26lt%3B%20%22data%20copy%20to%20input%20tensor%20failed%22%20%26lt%3B%26lt%3B%20std%3A%3Aendl%3B%0A%20%20%20%20%20%20%20%20return%20std%3A%3Amake_pair(std%3A%3Avector%26lt%3B%3Arect%26gt%3B()%2C%20std%3A%3Avector%3CFLOAT%3E())%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%7B%0A%20%20%20%20%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Set%20up%20Input%20Tensor%20Completed%22%26lt%3B%26lt%3B%3Aendl%26gt%3BInvoke()%3B%0A%0A%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Inference%20Completed%22%26lt%3B%26lt%3B%3Aendl%26gt%3Btyped_output_tensor%3CFLOAT%3E(0)%3B%0A%20%20%20%20size_t%20output_size%20%3D%20interpreter_-%26gt%3Btensor(interpreter_-%26gt%3Boutputs()%5B0%5D)-%26gt%3Bbytes%20%2F%20sizeof(float)%3B%20%20%20%20%0A%20%20%20%20cv%3A%3AMat%20results(1%2C%20output_size%2C%20CV_32F%2C%20output_tensor)%3B%0A%0A%20%20%20%20std%3A%3Acout%20%26lt%3B%26lt%3B%20%22Get%20Results%20Completed%22%26lt%3B%26lt%3B%3Aendl%26gt%3B%20result_rect_list%3B%0A%20%20%20%20for%20(size_t%20i%20%3D%200%3B%20i%20%26lt%3B%20bboxes_xyxy.size()%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20result_rect_list.push_back(bboxes_xyxy%5Bi%5D)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20Returning%20the%20list%20of%20rectangles%20and%20the%20associated%20scores%0A%20%20%20%20return%20%7Bresult_rect_list%2C%20scores%7D%3B%0A%7D%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FINT%3E%3C%2FINT%3E%3C%2FFLOAT%3E%3C%2FFLOAT%3E%3C%2FIOSTREAM%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E%3CBR%20%2F%3Emy%20board%20image%20is%20nanbield%206.6.3_1.0.0%20full%20image%3CBR%20%2F%3E%3CBR%20%2F%3EI%20tried%20to%20run%20it%20using%20VX%20Delegate%20and%20NPU%20and%20encounter%20a%20problem%20when%20running%20the%20code%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3Eroot%40imx8mpevk%3A%2Frun%2Fmedia%2FSD%20CARD-sda1%2Ftest_npu%23%20.%2Fdetector_app%20lena_color_512.tif%0AINFO%3A%20Vx%20delegate%3A%20allowed_cache_mode%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20device%20num%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20allowed_builtin_code%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_init%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_prepare%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_invoke%20set%20to%200.%0APreprocess%20Completed%0AExpected%20dimension%3A%201x3x192x192%0AImage%20dimension%3A%201x3x192x192%0ASet%20up%20Input%20Tensor%20Completed%0AE%20%5B%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r%5B%20%20126.612163%5D%20audit%3A%20type%3D1701%20audit(1695250801.923%3A18)%3A%20auid%3D4294967295%20uid%3D0%20gid%3D0%20ses%3D4294967295%20pid%3D1270%20comm%3D%22detector_app%22%20exe%3D2F72756E2F6D656469612F534420434152442D736461312F746573745F6E70752F6465746563746F725F617070%20sig%3D6%20res%3D1%0A0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%3AMapAxis%3A177%5DMap%20axis%20failed.%0Adetector_app%3A%20%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%3A178%3A%20uint32_t%20tim%3A%3Atransform%3A%3AOpLayoutInfer%3A%3AMapAxis(const%20std%3A%3Avector%3CUNSIGNED%20int%3D%22%22%3E%26amp%3B%2C%20uint32_t)%3A%20Assertion%20%60false'%20failed.%0AAborted%20(core%20dumped)%3C%2FUNSIGNED%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E%3CBR%20%2F%3EI%20also%20tried%20to%20get%20the%20gdb%20debug%20running%2C%20and%20it%20return%20something%20like%20this%3A%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E(gdb)%20set%20args%20lena_color_512.tif%0A(gdb)%20run%0AStarting%20program%3A%20%2Frun%2Fmedia%2FSD%20CARD-sda1%2Ftest_npu%2Fdetector_app%20lena_color_512.tif%0A%5BThread%20debugging%20using%20libthread_db%20enabled%5D%0AUsing%20host%20libthread_db%20library%20%22%2Fusr%2Flib%2Flibthread_db.so.1%22.%0AINFO%3A%20Vx%20delegate%3A%20allowed_cache_mode%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20device%20num%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20allowed_builtin_code%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_init%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_prepare%20set%20to%200.%0AINFO%3A%20Vx%20delegate%3A%20error_during_invoke%20set%20to%200.%0APreprocess%20Completed%0AExpected%20dimension%3A%201x3x192x192%0AImage%20dimension%3A%201x3x192x192%0ASet%20up%20Input%20Tensor%20Completed%0A%5BNew%20Thread%200xfffff146cf00%20(LWP%201660)%5D%0AE%20%5B%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%3AMapAxis%3A177%5DMap%20axis%20failed.%0Adetector_app%3A%20%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%3A178%3A%20uint32_t%20tim%3A%3Atransform%3A%3AOpLayoutInfer%3A%3AMapAxis(const%20std%3A%3Avector%3CUNSIGNED%20int%3D%22%22%3E%26amp%3B%2C%20uint32_t)%3A%20Assertion%20%60false'%20failed.%0A%0AThread%201%20%22detector_app%22%20received%20signal%20SIGABRT%2C%20Aborted.%0A__pthread_kill_implementation%20(threadid%3D%3COPTIMIZED%20out%3D%22%22%3E%2C%20signo%3Dsigno%40entry%3D6%2C%20no_tid%3Dno_tid%40entry%3D0)%20at%20pthread_kill.c%3A44%0A44%20%20%20%20%20%20pthread_kill.c%3A%20No%20such%20file%20or%20directory.%0A(gdb)%20bt%0A%230%20%20__pthread_kill_implementation%20(threadid%3D%3COPTIMIZED%20out%3D%22%22%3E%2C%20signo%3Dsigno%40entry%3D6%2C%20no_tid%3Dno_tid%40entry%3D0)%20at%20pthread_kill.c%3A44%0A%231%20%200x0000fffff69c0568%20in%20__pthread_kill_internal%20(signo%3D6%2C%20threadid%3D%3COPTIMIZED%20out%3D%22%22%3E)%20at%20pthread_kill.c%3A78%0A%232%20%200x0000fffff697acd0%20in%20__GI_raise%20(sig%3Dsig%40entry%3D6)%20at%20%2Fusr%2Fsrc%2Fdebug%2Fglibc%2F2.38%2Bgit-r0%2Fsysdeps%2Fposix%2Fraise.c%3A26%0A%233%20%200x0000fffff6966ef0%20in%20__GI_abort%20()%20at%20abort.c%3A79%0A%234%20%200x0000fffff69743f8%20in%20__assert_fail_base%20(fmt%3D0xfffff6a8a8e8%20%22%25s%25s%25s%3A%25u%3A%20%25s%25sAssertion%20%60%25s'%20failed.%5Cn%25n%22%2C%20assertion%3Dassertion%40entry%3D0xfffff1ffdcf0%20%22false%22%2C%0A%20%20%20%20file%3Dfile%40entry%3D0xfffff1fff568%20%22%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%22%2C%20line%3Dline%40entry%3D178%2C%0A%20%20%20%20function%3Dfunction%40entry%3D0xfffff1fff5d8%20%22uint32_t%20tim%3A%3Atransform%3A%3AOpLayoutInfer%3A%3AMapAxis(const%20std%3A%3Avector%3CUNSIGNED%20int%3D%22%22%3E%26amp%3B%2C%20uint32_t)%22)%20at%20assert.c%3A92%0A%235%20%200x0000fffff6974470%20in%20__assert_fail%20(assertion%3D0xfffff1ffdcf0%20%22false%22%2C%20file%3D0xfffff1fff568%20%22%2Fusr%2Fsrc%2Fdebug%2Ftim-vx%2F1.1.88-r0%2Fsrc%2Ftim%2Ftransform%2Fops%2Fop_layout_inference.cc%22%2C%20line%3D178%2C%0A%20%20%20%20function%3D0xfffff1fff5d8%20%22uint32_t%20tim%3A%3Atransform%3A%3AOpLayoutInfer%3A%3AMapAxis(const%20std%3A%3Avector%3CUNSIGNED%20int%3D%22%22%3E%26amp%3B%2C%20uint32_t)%22)%20at%20assert.c%3A101%0A%236%20%200x0000fffff1fa5f74%20in%20tim%3A%3Atransform%3A%3AOpLayoutInfer%3A%3AMapAxis(std%3A%3Avector%3CUNSIGNED%20int%3D%22%22%3E%20%26gt%3B%20const%26amp%3B%2C%20unsigned%20int)%20()%20from%20%2Fusr%2Flib%2Flibtim-vx.so%0A%237%20%200x0000fffff1f6a1b0%20in%20%3F%3F%20()%20from%20%2Fusr%2Flib%2Flibtim-vx.so%0A%238%20%200x0000fffff1f4e5f4%20in%20tim%3A%3Atransform%3A%3Alayout_inference_impl%3A%3AHandleLayoutInfer(std%3A%3Ashared_ptr%26lt%3B%3Atransform%3A%3Alayout_inference_impl%3A%3Alayoutinfercontext%26gt%3B%26amp%3B%2C%20std%3A%3Ashared_ptr%26lt%3B%3Avx%3A%3Aoperation%26gt%3B%20const%26amp%3B)%20()%20from%20%2Fusr%2Flib%2Flibtim-vx.so%0A%239%20%200x0000fffff1f531f4%20in%20tim%3A%3Atransform%3A%3ALayoutInference(std%3A%3Ashared_ptr%26lt%3B%3Avx%3A%3Agraph%26gt%3B%20const%26amp%3B%2C%20std%3A%3Ashared_ptr%26lt%3B%3Avx%3A%3Acontext%26gt%3B%26amp%3B%2C%20std%3A%3Amap%26lt%3B%3Ashared_ptr%26gt%3B%26lt%3B%3Avx%3A%3Atensor%26gt%3B%2C%20std%3A%3Ashared_ptr%26lt%3B%3Atransform%3A%3Aipermutevector%26gt%3B%2C%20std%3A%3Aless%26lt%3B%3Ashared_ptr%26gt%3B%26lt%3B%3Avx%3A%3Atensor%26gt%3B%20%26gt%3B%2C%20std%3A%3Aallocator%26lt%3B%3Apair%26gt%3B%26lt%3B%3Ashared_ptr%26gt%3B%26lt%3B%3Avx%3A%3Atensor%26gt%3B%20const%2C%20std%3A%3Ashared_ptr%26lt%3B%3Atransform%3A%3Aipermutevector%26gt%3B%20%26gt%3B%20%26gt%3B%20%26gt%3B)%20()%20from%20%2Fusr%2Flib%2Flibtim-vx.so%0A%2310%200x0000fffff23d85ac%20in%20vx%3A%3Adelegate%3A%3ADelegate%3A%3AInvoke(vx%3A%3Adelegate%3A%3AOpData%20const%26amp%3B%2C%20TfLiteContext*%2C%20TfLiteNode*)%20()%20from%20%2Fusr%2Flib%2Flibvx_delegate.so%0A%2311%200x0000fffff7be9d9c%20in%20tflite%3A%3ASubgraph%3A%3AInvokeImpl()%20()%20from%20%2Fusr%2Flib%2Flibtensorflow-lite.so.2.14.0%0A%2312%200x0000fffff7bea388%20in%20tflite%3A%3ASubgraph%3A%3AInvoke()%20()%20from%20%2Fusr%2Flib%2Flibtensorflow-lite.so.2.14.0%0A%2313%200x0000fffff7bd440c%20in%20tflite%3A%3Aimpl%3A%3AInterpreter%3A%3AInvoke()%20()%20from%20%2Fusr%2Flib%2Flibtensorflow-lite.so.2.14.0%0A%2314%200x0000aaaaaaaa62e0%20in%20Detector%3A%3Adetect%20(this%3Dthis%40entry%3D0xfffffffff890%2C%20image%3D...)%0A%20%20%20%20at%20%2Fhome%2Fubuntu%2Fimx-yocto-bsp%2Fsdk%2Fsysroots%2Farmv8a-poky-linux%2Fusr%2Finclude%2Fc%2B%2B%2F13.2.0%2Fbits%2Funique_ptr.h%3A199%0A%2315%200x0000aaaaaaaa35b0%20in%20main%20(argc%3D%3COPTIMIZED%20out%3D%22%22%3E%2C%20argv%3D%3COPTIMIZED%20out%3D%22%22%3E)%20at%20%2Fhome%2Fubuntu%2Fimx-yocto-bsp%2Ftflite_test%2Fbuild_minim%2Fmain.cpp%3A29%3C%2FOPTIMIZED%3E%3C%2FOPTIMIZED%3E%3C%2FUNSIGNED%3E%3C%2FUNSIGNED%3E%3C%2FUNSIGNED%3E%3C%2FOPTIMIZED%3E%3C%2FOPTIMIZED%3E%3C%2FOPTIMIZED%3E%3C%2FUNSIGNED%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EDoes%20anyone%20have%20a%20clue%20what%20is%20wrong%3F%20because%20I%20am%20not%20sure%20what%20happened%20here.%20but%20what%20i%20only%20know%20that%20the%20assertion%20at%20op_layout_inference.cc%3AMapAxis%3A177%20Map%20axis%20failed%20because%20of%20assertion%20error%20(%3F)%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20in%20advance%3C%2FP%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1947070%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX%208%20Family%20%7C%20i.MX%208QuadMax%20(8QM)%20%7C%208QuadPlus%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1955444%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20TfLite%20NPU%20run%20error%20op_layout_inference.cc%3AMapAxis%3A177%20Map%20axis%20failed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1955444%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20found%20the%20cause%20of%20the%20problem.%20Apparently%20this%20line%20caused%20the%20error%3A%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%3Eresolver.AddCustom(kNbgCustomOp%2C%20tflite%3A%3Aops%3A%3Acustom%3A%3ARegister_VSI_NPU_PRECOMPILED())%3B%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3ESo%20for%20now%2C%20i%20just%20disable%20it%20and%20magically%20it%20works.%20Maybe%20someone%20can%20explain%20why%20it%20trigger%20the%20error%2C%20but%20for%20now%20I%20can%20finally%20continue%20with%20my%20app%20development.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20the%20model%2C%20I%20check%20it%20using%20Python%20code%2C%20and%20apparently%20no%20error%2C%20so%20the%20model%20itself%20is%20compatible%20with%20the%20NPU%20run.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1947846%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20TfLite%20NPU%20run%20error%20op_layout_inference.cc%3AMapAxis%3A177%20Map%20axis%20failed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1947846%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Eis%20it%20possible%20that%20the%20model%20is%20not%20compatible%20with%20the%20NPU%2FVX%20delegate%20run%3F%3CBR%20%2F%3E%3CBR%20%2F%3Ebc%20when%20i%20try%20to%20run%20it%20with%20CPU%20i%20got%20different%20error%20(related%20to%20one%20of%20the%20StridedSlice%20layer%2C%20but%20i%20havent%20check%20it%20properly%20yet%20for%20CPU%20run)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1947334%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20TfLite%20NPU%20run%20error%20op_layout_inference.cc%3AMapAxis%3A177%20Map%20axis%20failed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1947334%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EIt%20looks%20tile%20t%3CSPAN%3Ehe%20assertion%20is%20there%20to%20say%20that%20as%20far%20as%20you%20aware%2C%20has%20made%20it%20%3CSTRONG%3Eimpossible%3C%2FSTRONG%3E%20to%20call%20the%20zero-args%20constructor%20according%20is%20private%20and%20so%20if%20a%20call%20occurs%2C%20that%20assertion%20has%20been%20violated%20per%20your%20error.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ERegards%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E