<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX ProcessorsのトピックTfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947070#M228022</link>
    <description>&lt;P&gt;Hello everyone&lt;BR /&gt;&lt;BR /&gt;Sorry for asking. I tried to build my own C++ program which is a converted program from &lt;A href="https://github.com/Kazuhito00/Person-Detection-using-RaspberryPi-CPU" target="_self"&gt;python&lt;/A&gt;&amp;nbsp;, to run a simple model to detect people for my board imx8m plus.&lt;BR /&gt;&lt;BR /&gt;The Code:&lt;BR /&gt;&lt;BR /&gt;1. main.cpp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// main.cpp
#include "detector.h"
#include &amp;lt;opencv2/opencv.hpp&amp;gt;

int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr &amp;lt;&amp;lt; "Usage: " &amp;lt;&amp;lt; argv[0] &amp;lt;&amp;lt; " &amp;lt;image_path&amp;gt;" &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; "Failed to load image from " &amp;lt;&amp;lt; image_path &amp;lt;&amp;lt; std::endl;
        return 1;
    }

    auto [bboxes, scores] = detector.detect(image);

    for (size_t i = 0; i &amp;lt; bboxes.size(); ++i) {
        cv::rectangle(image, bboxes[i], cv::Scalar(0, 255, 0), 2);
        std::cout &amp;lt;&amp;lt; "Detected bbox: " &amp;lt;&amp;lt; bboxes[i] &amp;lt;&amp;lt; " with score: " &amp;lt;&amp;lt; scores[i] &amp;lt;&amp;lt; std::endl;
    }

    // cv::imshow("Detections", image);
    cv::waitKey(0);

    return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. detector.h&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// detector.h
#ifndef DETECTOR_H
#define DETECTOR_H

#include &amp;lt;opencv2/opencv.hpp&amp;gt;
#include &amp;lt;tensorflow/lite/interpreter.h&amp;gt;
#include &amp;lt;tensorflow/lite/kernels/register.h&amp;gt;
#include &amp;lt;tensorflow/lite/model.h&amp;gt;
#include &amp;lt;tensorflow/lite/optional_debug_tools.h&amp;gt;
#include &amp;lt;tensorflow/lite/delegates/external/external_delegate.h&amp;gt;
#include &amp;lt;tensorflow-lite-vx-delegate/vsi_npu_custom_op.h&amp;gt;
#include "delegate_main.h"

class Detector {
public:
    Detector(const std::string&amp;amp; model_path, 
             const std::string&amp;amp; delegate_path,
             const cv::Size&amp;amp; input_shape,
             float score_th,
             float nms_th);

    bool init_model();
    std::pair&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;&amp;gt; detect(const cv::Mat&amp;amp; image);

private:
    std::string model_path_;
    std::string delegate_path_;
    cv::Size input_shape_;
    float score_th_;
    float nms_th_;
    std::unique_ptr&amp;lt;tflite::Interpreter&amp;gt; interpreter_;

    std::pair&amp;lt;cv::Mat, float&amp;gt; preprocess(const cv::Mat&amp;amp; image, const cv::Size&amp;amp; input_size);
    std::tuple&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; postprocess(cv::Mat&amp;amp; outputs, 
                                                                                        const cv::Size&amp;amp; img_size, 
                                                                                        float ratio, 
                                                                                        float score_th, 
                                                                                        float nms_th);
    void meshgrid(const cv::Range&amp;amp; x_range, const cv::Range&amp;amp; y_range, cv::Mat&amp;amp; xv, cv::Mat&amp;amp; yv);
    std::tuple&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; nms(const std::vector&amp;lt;cv::Rect&amp;gt;&amp;amp; bboxes, 
                                                                                const std::vector&amp;lt;float&amp;gt;&amp;amp; scores, 
                                                                                float score_th, 
                                                                                float nms_th);
};

#endif // DETECTOR_H&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. detector.cpp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// detector.cpp
#include "detector.h"
#include &amp;lt;iostream&amp;gt;

Detector::Detector(const std::string&amp;amp; model_path, 
                   const std::string&amp;amp; delegate_path,
                   const cv::Size&amp;amp; 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 &amp;lt;&amp;lt; "Failed to load model from " &amp;lt;&amp;lt; model_path_ &amp;lt;&amp;lt; std::endl;
        return false;
    }

    auto ext_delegate_option = TfLiteExternalDelegateOptionsDefault(delegate_path_.c_str());
    auto ext_delegate_ptr = TfLiteExternalDelegateCreate(&amp;amp;ext_delegate_option);
    if (!ext_delegate_ptr) {
        std::cerr &amp;lt;&amp;lt; "Failed to create external delegate" &amp;lt;&amp;lt; 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(&amp;amp;interpreter_);
    if (!interpreter_) {
        std::cerr &amp;lt;&amp;lt; "Failed to build interpreter" &amp;lt;&amp;lt; std::endl;
        return false;
    }

    interpreter_-&amp;gt;ModifyGraphWithDelegate(ext_delegate_ptr);
    if (interpreter_-&amp;gt;AllocateTensors() != kTfLiteOk) {
        std::cerr &amp;lt;&amp;lt; "Failed to allocate tensors" &amp;lt;&amp;lt; std::endl;
        return false;
    }

    return true;
}

std::pair&amp;lt;cv::Mat, float&amp;gt; Detector::preprocess(const cv::Mat&amp;amp; image, const cv::Size&amp;amp; input_size) {
    float ratio = std::min(static_cast&amp;lt;float&amp;gt;(input_size.width) / image.cols,
                           static_cast&amp;lt;float&amp;gt;(input_size.height) / image.rows);

    cv::Size new_size(static_cast&amp;lt;int&amp;gt;(image.cols * ratio), static_cast&amp;lt;int&amp;gt;(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&amp;lt;cv::Mat&amp;gt; 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 &amp;lt; 3; ++i) {
        channels[i].convertTo(channels[i], CV_32F);
        std::memcpy(chw_image.ptr&amp;lt;float&amp;gt;(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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; Detector::postprocess(cv::Mat&amp;amp; outputs, 
                                                                                            const cv::Size&amp;amp; img_size, 
                                                                                            float ratio, 
                                                                                            float score_th, 
                                                                                            float nms_th) {
    std::vector&amp;lt;cv::Rect&amp;gt; bboxes;
    std::vector&amp;lt;float&amp;gt; scores;
    std::vector&amp;lt;int&amp;gt; class_ids;

    std::vector&amp;lt;int&amp;gt; strides = {8, 16, 32};
    std::vector&amp;lt;cv::Mat&amp;gt; grids;
    std::vector&amp;lt;cv::Mat&amp;gt; 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&amp;lt;float&amp;gt;(), scores_mat.end&amp;lt;float&amp;gt;());

    std::vector&amp;lt;cv::Rect&amp;gt; bboxes_xyxy(bboxes_mat.rows);
    for (int i = 0; i &amp;lt; bboxes_mat.rows; ++i) {
        float x_center = bboxes_mat.at&amp;lt;float&amp;gt;(i, 0);
        float y_center = bboxes_mat.at&amp;lt;float&amp;gt;(i, 1);
        float width = bboxes_mat.at&amp;lt;float&amp;gt;(i, 2);
        float height = bboxes_mat.at&amp;lt;float&amp;gt;(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&amp;amp; x_range, const cv::Range&amp;amp; y_range, cv::Mat&amp;amp; xv, cv::Mat&amp;amp; 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 &amp;lt; x_range.size(); ++i) {
        x_coords.at&amp;lt;float&amp;gt;(i,0) = x_range.start + i;
    }
    
    for (int i = 0; i &amp;lt; y_range.size(); ++i) {
        y_coords.at&amp;lt;float&amp;gt;(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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; Detector::nms(const std::vector&amp;lt;cv::Rect&amp;gt;&amp;amp; bboxes, 
                                                                                        const std::vector&amp;lt;float&amp;gt;&amp;amp; scores, 
                                                                                        float score_th, 
                                                                                        float nms_th) {
    std::vector&amp;lt;cv::Rect&amp;gt; bboxes_filtered;
    std::vector&amp;lt;float&amp;gt; scores_filtered;
    std::vector&amp;lt;int&amp;gt; class_ids_filtered;

    std::vector&amp;lt;int&amp;gt; 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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;&amp;gt; Detector::detect(const cv::Mat&amp;amp; image) {
    cv::Mat temp_image = image.clone();
    
    auto [preprocessed_image, ratio] = preprocess(temp_image, input_shape_);
    
    std::cout &amp;lt;&amp;lt; "Preprocess Completed"&amp;lt;&amp;lt;std::endl;

    // Setting input tensor
    TfLiteTensor* input_data = interpreter_-&amp;gt;tensor(interpreter_-&amp;gt;inputs()[0]);
    const uint input_width = input_data-&amp;gt;dims-&amp;gt;data[3];
    const uint input_height = input_data-&amp;gt;dims-&amp;gt;data[2];
    const uint input_channels = input_data-&amp;gt;dims-&amp;gt;data[1];
    const uint batch_size = input_data-&amp;gt;dims-&amp;gt;data[0];

    std::cout &amp;lt;&amp;lt; "Expected dimension: "&amp;lt;&amp;lt; batch_size &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_channels &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_height &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_width &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; "Image dimension: "&amp;lt;&amp;lt; image_batch_size &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_channels &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_height &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_width &amp;lt;&amp;lt; std::endl;

    if(input_data-&amp;gt;type !=kTfLiteFloat32){
        std::cerr &amp;lt;&amp;lt; "input tensor is not of type float" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }

    if(input_data-&amp;gt;data.f == nullptr) {
        std::cerr &amp;lt;&amp;lt; "input tensor data pointer is null" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }
    std::memcpy(input_data-&amp;gt;data.f, preprocessed_image.ptr&amp;lt;float&amp;gt;(0), batch_size * input_width * input_height * input_channels * sizeof(float));

    if(memcmp(input_data-&amp;gt;data.f, preprocessed_image.ptr&amp;lt;float&amp;gt;(0),batch_size * input_width * input_height * input_channels * sizeof(float)) != 0){
        std::cerr &amp;lt;&amp;lt; "data copy to input tensor failed" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }
    else{
        std::cout &amp;lt;&amp;lt; "Set up Input Tensor Completed"&amp;lt;&amp;lt;std::endl;
    }

    // Running inference
    interpreter_-&amp;gt;Invoke();

    std::cout &amp;lt;&amp;lt; "Inference Completed"&amp;lt;&amp;lt;std::endl;

    // Getting output tensor
    float* output_tensor = interpreter_-&amp;gt;typed_output_tensor&amp;lt;float&amp;gt;(0);
    size_t output_size = interpreter_-&amp;gt;tensor(interpreter_-&amp;gt;outputs()[0])-&amp;gt;bytes / sizeof(float);    
    cv::Mat results(1, output_size, CV_32F, output_tensor);

    std::cout &amp;lt;&amp;lt; "Get Results Completed"&amp;lt;&amp;lt;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&amp;lt;cv::Rect&amp;gt; result_rect_list;
    for (size_t i = 0; i &amp;lt; 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};
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;my board image is nanbield 6.6.3_1.0.0 full image&lt;BR /&gt;&lt;BR /&gt;I tried to run it using VX Delegate and NPU and encounter a problem when running the code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t): Assertion `false' failed.
Aborted (core dumped)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I also tried to get the gdb debug running, and it return something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;(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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t): Assertion `false' failed.

Thread 1 "detector_app" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=&amp;lt;optimized out&amp;gt;, 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=&amp;lt;optimized out&amp;gt;, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x0000fffff69c0568 in __pthread_kill_internal (signo=6, threadid=&amp;lt;optimized out&amp;gt;) 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&amp;lt;unsigned int&amp;gt;&amp;amp;, 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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t)") at assert.c:101
#6  0x0000fffff1fa5f74 in tim::transform::OpLayoutInfer::MapAxis(std::vector&amp;lt;unsigned int, std::allocator&amp;lt;unsigned int&amp;gt; &amp;gt; const&amp;amp;, 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&amp;lt;tim::transform::layout_inference_impl::LayoutInferContext&amp;gt;&amp;amp;, std::shared_ptr&amp;lt;tim::vx::Operation&amp;gt; const&amp;amp;) () from /usr/lib/libtim-vx.so
#9  0x0000fffff1f531f4 in tim::transform::LayoutInference(std::shared_ptr&amp;lt;tim::vx::Graph&amp;gt; const&amp;amp;, std::shared_ptr&amp;lt;tim::vx::Context&amp;gt;&amp;amp;, std::map&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt;, std::shared_ptr&amp;lt;tim::transform::IPermuteVector&amp;gt;, std::less&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt; &amp;gt;, std::allocator&amp;lt;std::pair&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt; const, std::shared_ptr&amp;lt;tim::transform::IPermuteVector&amp;gt; &amp;gt; &amp;gt; &amp;gt;) () from /usr/lib/libtim-vx.so
#10 0x0000fffff23d85ac in vx::delegate::Delegate::Invoke(vx::delegate::OpData const&amp;amp;, 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=&amp;lt;optimized out&amp;gt;, argv=&amp;lt;optimized out&amp;gt;) at /home/ubuntu/imx-yocto-bsp/tflite_test/build_minim/main.cpp:29&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 (?)&lt;BR /&gt;&lt;BR /&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2024 09:02:30 GMT</pubDate>
    <dc:creator>astel_</dc:creator>
    <dc:date>2024-09-04T09:02:30Z</dc:date>
    <item>
      <title>TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947070#M228022</link>
      <description>&lt;P&gt;Hello everyone&lt;BR /&gt;&lt;BR /&gt;Sorry for asking. I tried to build my own C++ program which is a converted program from &lt;A href="https://github.com/Kazuhito00/Person-Detection-using-RaspberryPi-CPU" target="_self"&gt;python&lt;/A&gt;&amp;nbsp;, to run a simple model to detect people for my board imx8m plus.&lt;BR /&gt;&lt;BR /&gt;The Code:&lt;BR /&gt;&lt;BR /&gt;1. main.cpp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// main.cpp
#include "detector.h"
#include &amp;lt;opencv2/opencv.hpp&amp;gt;

int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr &amp;lt;&amp;lt; "Usage: " &amp;lt;&amp;lt; argv[0] &amp;lt;&amp;lt; " &amp;lt;image_path&amp;gt;" &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; "Failed to load image from " &amp;lt;&amp;lt; image_path &amp;lt;&amp;lt; std::endl;
        return 1;
    }

    auto [bboxes, scores] = detector.detect(image);

    for (size_t i = 0; i &amp;lt; bboxes.size(); ++i) {
        cv::rectangle(image, bboxes[i], cv::Scalar(0, 255, 0), 2);
        std::cout &amp;lt;&amp;lt; "Detected bbox: " &amp;lt;&amp;lt; bboxes[i] &amp;lt;&amp;lt; " with score: " &amp;lt;&amp;lt; scores[i] &amp;lt;&amp;lt; std::endl;
    }

    // cv::imshow("Detections", image);
    cv::waitKey(0);

    return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. detector.h&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// detector.h
#ifndef DETECTOR_H
#define DETECTOR_H

#include &amp;lt;opencv2/opencv.hpp&amp;gt;
#include &amp;lt;tensorflow/lite/interpreter.h&amp;gt;
#include &amp;lt;tensorflow/lite/kernels/register.h&amp;gt;
#include &amp;lt;tensorflow/lite/model.h&amp;gt;
#include &amp;lt;tensorflow/lite/optional_debug_tools.h&amp;gt;
#include &amp;lt;tensorflow/lite/delegates/external/external_delegate.h&amp;gt;
#include &amp;lt;tensorflow-lite-vx-delegate/vsi_npu_custom_op.h&amp;gt;
#include "delegate_main.h"

class Detector {
public:
    Detector(const std::string&amp;amp; model_path, 
             const std::string&amp;amp; delegate_path,
             const cv::Size&amp;amp; input_shape,
             float score_th,
             float nms_th);

    bool init_model();
    std::pair&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;&amp;gt; detect(const cv::Mat&amp;amp; image);

private:
    std::string model_path_;
    std::string delegate_path_;
    cv::Size input_shape_;
    float score_th_;
    float nms_th_;
    std::unique_ptr&amp;lt;tflite::Interpreter&amp;gt; interpreter_;

    std::pair&amp;lt;cv::Mat, float&amp;gt; preprocess(const cv::Mat&amp;amp; image, const cv::Size&amp;amp; input_size);
    std::tuple&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; postprocess(cv::Mat&amp;amp; outputs, 
                                                                                        const cv::Size&amp;amp; img_size, 
                                                                                        float ratio, 
                                                                                        float score_th, 
                                                                                        float nms_th);
    void meshgrid(const cv::Range&amp;amp; x_range, const cv::Range&amp;amp; y_range, cv::Mat&amp;amp; xv, cv::Mat&amp;amp; yv);
    std::tuple&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; nms(const std::vector&amp;lt;cv::Rect&amp;gt;&amp;amp; bboxes, 
                                                                                const std::vector&amp;lt;float&amp;gt;&amp;amp; scores, 
                                                                                float score_th, 
                                                                                float nms_th);
};

#endif // DETECTOR_H&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. detector.cpp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// detector.cpp
#include "detector.h"
#include &amp;lt;iostream&amp;gt;

Detector::Detector(const std::string&amp;amp; model_path, 
                   const std::string&amp;amp; delegate_path,
                   const cv::Size&amp;amp; 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 &amp;lt;&amp;lt; "Failed to load model from " &amp;lt;&amp;lt; model_path_ &amp;lt;&amp;lt; std::endl;
        return false;
    }

    auto ext_delegate_option = TfLiteExternalDelegateOptionsDefault(delegate_path_.c_str());
    auto ext_delegate_ptr = TfLiteExternalDelegateCreate(&amp;amp;ext_delegate_option);
    if (!ext_delegate_ptr) {
        std::cerr &amp;lt;&amp;lt; "Failed to create external delegate" &amp;lt;&amp;lt; 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(&amp;amp;interpreter_);
    if (!interpreter_) {
        std::cerr &amp;lt;&amp;lt; "Failed to build interpreter" &amp;lt;&amp;lt; std::endl;
        return false;
    }

    interpreter_-&amp;gt;ModifyGraphWithDelegate(ext_delegate_ptr);
    if (interpreter_-&amp;gt;AllocateTensors() != kTfLiteOk) {
        std::cerr &amp;lt;&amp;lt; "Failed to allocate tensors" &amp;lt;&amp;lt; std::endl;
        return false;
    }

    return true;
}

std::pair&amp;lt;cv::Mat, float&amp;gt; Detector::preprocess(const cv::Mat&amp;amp; image, const cv::Size&amp;amp; input_size) {
    float ratio = std::min(static_cast&amp;lt;float&amp;gt;(input_size.width) / image.cols,
                           static_cast&amp;lt;float&amp;gt;(input_size.height) / image.rows);

    cv::Size new_size(static_cast&amp;lt;int&amp;gt;(image.cols * ratio), static_cast&amp;lt;int&amp;gt;(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&amp;lt;cv::Mat&amp;gt; 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 &amp;lt; 3; ++i) {
        channels[i].convertTo(channels[i], CV_32F);
        std::memcpy(chw_image.ptr&amp;lt;float&amp;gt;(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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; Detector::postprocess(cv::Mat&amp;amp; outputs, 
                                                                                            const cv::Size&amp;amp; img_size, 
                                                                                            float ratio, 
                                                                                            float score_th, 
                                                                                            float nms_th) {
    std::vector&amp;lt;cv::Rect&amp;gt; bboxes;
    std::vector&amp;lt;float&amp;gt; scores;
    std::vector&amp;lt;int&amp;gt; class_ids;

    std::vector&amp;lt;int&amp;gt; strides = {8, 16, 32};
    std::vector&amp;lt;cv::Mat&amp;gt; grids;
    std::vector&amp;lt;cv::Mat&amp;gt; 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&amp;lt;float&amp;gt;(), scores_mat.end&amp;lt;float&amp;gt;());

    std::vector&amp;lt;cv::Rect&amp;gt; bboxes_xyxy(bboxes_mat.rows);
    for (int i = 0; i &amp;lt; bboxes_mat.rows; ++i) {
        float x_center = bboxes_mat.at&amp;lt;float&amp;gt;(i, 0);
        float y_center = bboxes_mat.at&amp;lt;float&amp;gt;(i, 1);
        float width = bboxes_mat.at&amp;lt;float&amp;gt;(i, 2);
        float height = bboxes_mat.at&amp;lt;float&amp;gt;(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&amp;amp; x_range, const cv::Range&amp;amp; y_range, cv::Mat&amp;amp; xv, cv::Mat&amp;amp; 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 &amp;lt; x_range.size(); ++i) {
        x_coords.at&amp;lt;float&amp;gt;(i,0) = x_range.start + i;
    }
    
    for (int i = 0; i &amp;lt; y_range.size(); ++i) {
        y_coords.at&amp;lt;float&amp;gt;(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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;, std::vector&amp;lt;int&amp;gt;&amp;gt; Detector::nms(const std::vector&amp;lt;cv::Rect&amp;gt;&amp;amp; bboxes, 
                                                                                        const std::vector&amp;lt;float&amp;gt;&amp;amp; scores, 
                                                                                        float score_th, 
                                                                                        float nms_th) {
    std::vector&amp;lt;cv::Rect&amp;gt; bboxes_filtered;
    std::vector&amp;lt;float&amp;gt; scores_filtered;
    std::vector&amp;lt;int&amp;gt; class_ids_filtered;

    std::vector&amp;lt;int&amp;gt; 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&amp;lt;std::vector&amp;lt;cv::Rect&amp;gt;, std::vector&amp;lt;float&amp;gt;&amp;gt; Detector::detect(const cv::Mat&amp;amp; image) {
    cv::Mat temp_image = image.clone();
    
    auto [preprocessed_image, ratio] = preprocess(temp_image, input_shape_);
    
    std::cout &amp;lt;&amp;lt; "Preprocess Completed"&amp;lt;&amp;lt;std::endl;

    // Setting input tensor
    TfLiteTensor* input_data = interpreter_-&amp;gt;tensor(interpreter_-&amp;gt;inputs()[0]);
    const uint input_width = input_data-&amp;gt;dims-&amp;gt;data[3];
    const uint input_height = input_data-&amp;gt;dims-&amp;gt;data[2];
    const uint input_channels = input_data-&amp;gt;dims-&amp;gt;data[1];
    const uint batch_size = input_data-&amp;gt;dims-&amp;gt;data[0];

    std::cout &amp;lt;&amp;lt; "Expected dimension: "&amp;lt;&amp;lt; batch_size &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_channels &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_height &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; input_width &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; "Image dimension: "&amp;lt;&amp;lt; image_batch_size &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_channels &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_height &amp;lt;&amp;lt; "x" &amp;lt;&amp;lt; image_width &amp;lt;&amp;lt; std::endl;

    if(input_data-&amp;gt;type !=kTfLiteFloat32){
        std::cerr &amp;lt;&amp;lt; "input tensor is not of type float" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }

    if(input_data-&amp;gt;data.f == nullptr) {
        std::cerr &amp;lt;&amp;lt; "input tensor data pointer is null" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }
    std::memcpy(input_data-&amp;gt;data.f, preprocessed_image.ptr&amp;lt;float&amp;gt;(0), batch_size * input_width * input_height * input_channels * sizeof(float));

    if(memcmp(input_data-&amp;gt;data.f, preprocessed_image.ptr&amp;lt;float&amp;gt;(0),batch_size * input_width * input_height * input_channels * sizeof(float)) != 0){
        std::cerr &amp;lt;&amp;lt; "data copy to input tensor failed" &amp;lt;&amp;lt; std::endl;
        return std::make_pair(std::vector&amp;lt;cv::Rect&amp;gt;(), std::vector&amp;lt;float&amp;gt;());
    }
    else{
        std::cout &amp;lt;&amp;lt; "Set up Input Tensor Completed"&amp;lt;&amp;lt;std::endl;
    }

    // Running inference
    interpreter_-&amp;gt;Invoke();

    std::cout &amp;lt;&amp;lt; "Inference Completed"&amp;lt;&amp;lt;std::endl;

    // Getting output tensor
    float* output_tensor = interpreter_-&amp;gt;typed_output_tensor&amp;lt;float&amp;gt;(0);
    size_t output_size = interpreter_-&amp;gt;tensor(interpreter_-&amp;gt;outputs()[0])-&amp;gt;bytes / sizeof(float);    
    cv::Mat results(1, output_size, CV_32F, output_tensor);

    std::cout &amp;lt;&amp;lt; "Get Results Completed"&amp;lt;&amp;lt;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&amp;lt;cv::Rect&amp;gt; result_rect_list;
    for (size_t i = 0; i &amp;lt; 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};
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;my board image is nanbield 6.6.3_1.0.0 full image&lt;BR /&gt;&lt;BR /&gt;I tried to run it using VX Delegate and NPU and encounter a problem when running the code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t): Assertion `false' failed.
Aborted (core dumped)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I also tried to get the gdb debug running, and it return something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;(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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t): Assertion `false' failed.

Thread 1 "detector_app" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=&amp;lt;optimized out&amp;gt;, 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=&amp;lt;optimized out&amp;gt;, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x0000fffff69c0568 in __pthread_kill_internal (signo=6, threadid=&amp;lt;optimized out&amp;gt;) 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&amp;lt;unsigned int&amp;gt;&amp;amp;, 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&amp;lt;unsigned int&amp;gt;&amp;amp;, uint32_t)") at assert.c:101
#6  0x0000fffff1fa5f74 in tim::transform::OpLayoutInfer::MapAxis(std::vector&amp;lt;unsigned int, std::allocator&amp;lt;unsigned int&amp;gt; &amp;gt; const&amp;amp;, 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&amp;lt;tim::transform::layout_inference_impl::LayoutInferContext&amp;gt;&amp;amp;, std::shared_ptr&amp;lt;tim::vx::Operation&amp;gt; const&amp;amp;) () from /usr/lib/libtim-vx.so
#9  0x0000fffff1f531f4 in tim::transform::LayoutInference(std::shared_ptr&amp;lt;tim::vx::Graph&amp;gt; const&amp;amp;, std::shared_ptr&amp;lt;tim::vx::Context&amp;gt;&amp;amp;, std::map&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt;, std::shared_ptr&amp;lt;tim::transform::IPermuteVector&amp;gt;, std::less&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt; &amp;gt;, std::allocator&amp;lt;std::pair&amp;lt;std::shared_ptr&amp;lt;tim::vx::Tensor&amp;gt; const, std::shared_ptr&amp;lt;tim::transform::IPermuteVector&amp;gt; &amp;gt; &amp;gt; &amp;gt;) () from /usr/lib/libtim-vx.so
#10 0x0000fffff23d85ac in vx::delegate::Delegate::Invoke(vx::delegate::OpData const&amp;amp;, 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=&amp;lt;optimized out&amp;gt;, argv=&amp;lt;optimized out&amp;gt;) at /home/ubuntu/imx-yocto-bsp/tflite_test/build_minim/main.cpp:29&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 (?)&lt;BR /&gt;&lt;BR /&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 09:02:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947070#M228022</guid>
      <dc:creator>astel_</dc:creator>
      <dc:date>2024-09-04T09:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947334#M228036</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;It looks tile t&lt;SPAN&gt;he assertion is there to say that as far as you aware, has made it &lt;STRONG&gt;impossible&lt;/STRONG&gt; to call the zero-args constructor according is private and so if a call occurs, that assertion has been violated per your error.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 14:35:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947334#M228036</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2024-09-04T14:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947846#M228067</link>
      <description>is it possible that the model is not compatible with the NPU/VX delegate run?&lt;BR /&gt;&lt;BR /&gt;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)</description>
      <pubDate>Thu, 05 Sep 2024 05:56:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1947846#M228067</guid>
      <dc:creator>astel_</dc:creator>
      <dc:date>2024-09-05T05:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: TfLite NPU run error op_layout_inference.cc:MapAxis:177 Map axis failed</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1955444#M228478</link>
      <description>&lt;P&gt;I found the cause of the problem. Apparently this line caused the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;resolver.AddCustom(kNbgCustomOp, tflite::ops::custom::Register_VSI_NPU_PRECOMPILED());&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;For the model, I check it using Python code, and apparently no error, so the model itself is compatible with the NPU run.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 06:24:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/TfLite-NPU-run-error-op-layout-inference-cc-MapAxis-177-Map-axis/m-p/1955444#M228478</guid>
      <dc:creator>astel_</dc:creator>
      <dc:date>2024-09-17T06:24:04Z</dc:date>
    </item>
  </channel>
</rss>

