The reasoning code is as follows:
#include "net.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <stdio.h>
#include <vector>
#include <opencv2/opencv.hpp>
using namespace std;
void pretty_print(const ncnn::Mat& m)
{
for (int q=0; q<m.c; q++)
{
const float* ptr = m.channel(q);
for (int y=0; y<m.h; y++)
{
for (int x=0; x<m.w; x++)
{
printf("%f ", ptr[x]);
}
ptr += m.w;
printf("\n");
}
printf("------------------------\n");
}
}
//main fuction
int main(){
string img_path = "person1.jpeg";
cv::Mat img = cv::imread(img_path, cv::IMREAD_COLOR);
cv::Mat img2;
int input_width = 512;//Input size specified when going onnx
int input_height = 512;
cv::resize(img, img2, cv::Size(input_width, input_height));
// Load the converted and quantized alexnet network
ncnn::Net net;
// net.opt.num_threads=1;
net.load_param("cps_simplif.param");
net.load_model("cps_simplif.bin");
// Convert opencv mat to ncnn mat
ncnn::Mat input = ncnn::Mat::from_pixels(img2.data, ncnn::Mat::PIXEL_BGR, img2.cols, img2.rows);
const float mean_vals[3] = {0.485, 0.456, 0.406};
const float norm_vals[3] = {0.229, 0.224, 0.225}; //[0.485, 0.456, 0.406]),std=np.array([0.229, 0.224, 0.225]
input.substract_mean_normalize(mean_vals, norm_vals);
// ncnn forward calculation
ncnn::Extractor extractor = net.create_extractor();
extractor.input("input.1", input);
ncnn::Mat output0;
extractor.extract("1035", output0);
//ncnn::mat ->>>>> cv::mat
cv::Mat a(input_height,input_width, CV_8UC3);
output0.to_pixels(a.data, ncnn::Mat::PIXEL_BGR2RGB);
cv::imwrite("ncnninfer.png", a);
// pretty_print(output0);
// pretty_print(output1);
cout<<"done"<<endl;
return 0;
}
Only segmentation fault (core dumped) is reported after running
No core file is generated. Check through ulimit -c
, the size of core file is unlimited and there is no problem. This method solves the problem of not generating core file
With core file
Pass under the terminal
apt-get update
apt-get install gdb
Install GDB
Installation completed, passed
gdb ./Execution file name core
The core here can be modified according to its own core file name.
the error is found at:
Corresponding to the reasoning code above
output0.to_pixels(a.data, ncnn::Mat::PIXEL_BGR2RGB);
It is the code to realize the conversion from ncnn:: mat to cv:mat. After debugging, it is found that the reasoning results of ncnn are all Nan, which leads to the conversion failure
Adjust the previous input, normalization is not done well.
Read More:
- [Solved] docker Commands Execute Error: Segmentation fault
- [Solved] paddle:FatalError: `Segmentation fault` is detected by the operating system.
- [Solved] jetson nano Error: Illegal instruction(core dumped)
- How to Solve “parcel segmentation fault” Error in Linux
- [Solved] jetson Compile pytorch Error: internal compiler error: Segmentation fault
- EF core Creates pg library and Model Report an Error [Solved]
- [Solved] VScode Run C++ File Error: fatal error:opencv2\core.hpp:No such file or diretory
- [Solved] net core HTTP Error 500.31 – Failed to load ASP.NET Core runtime HTTP Error 500.30 – ASP.NET Core
- POI’s XWPFParagraph.getRuns Segmentation problem
- [Solved] Asp.Net Core IIS Error: HTTP Error 500.30 – ASP.NET Core app failed to start
- Android 10 SurfaceView Crash: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
- Cv2.dnn read model error [How to Solve]
- The reason and solution for the error ECONNRESET of the httpClieint request of Node.js
- Memory write error at 0x100000. MMU section translation fault [How to Solve]
- Vitis-AI Generate a Quantitative Model: NotImplementedError
- [Solved] loadrunner Error: Failed to Initialize. Reason: TimeOut
- C++:error C2872: ‘byte‘: ambiguous symbol [How to Solve]
- [Solved] Pytorch loading model specified GPU card number error or failed to specify
- Onnx to tensorrt model error [How to Solve]