Error solved: add tf.keras.layer.Permute(3,1,2) to convert input from NHWC to NCHW. This solves segmentation fault. Because onnx2ncnn is for conversion from pytorch which uses NCHW.
I couldn't solve integer output problem yet. Output is correct but not probabilities, but integers.
error log | 日志或报错信息 | ログ
context | 编译/运行环境 | バックグラウンド
I trained a convolutional model with mnist, saved it as onnx, simplified it,
onnx2ncnn gave no error, but when it comes to inference it with c_api.h, it says "segmentation fault".
It is not happening with master branch, it is happening with tags 20211208, 20211122 and 20201218. I was able to try them,
When I try with master branch result is true but integer, not probabilities of outputs. I use softmax activation at the end of network.
how to reproduce | 复现步骤 | 再現方法
- Ubuntu 20.04 Virtualbox
- Python 3.7, tensorflow 2.7, tf2onnx, op12
- ncnn 20211208
9条答案
按热度按时间5lhxktic1#
I dont know segmentation fault bug. I need to see how you translate it. But i can help you output bugs. You can show ncnn output data with pretty_print function or you should pay attention ncnn2opencv data type convertion. If you are using wrong convert algorithm you will get UINT8 data.
you can use float data conversation algorithm. You should use this function ncnn::Mat 1 channel -> cv::Mat CV_32FC1
bz4sfanl2#
some of libraries are only wrapping functions like
image read etc. working properly, because when I try it with master branch, it works. I am using lodepng to read image.
az31mfrm3#
what is ncnn_mat_get_data function ? How to convert out data?
gwo2fgha4#
It is from squeezenet_c_api example
https://ncnn.docsforge.com/master/api/ncnn_mat_get_data/
kzipqqlq5#
Can you print out data with pretty_print function after ncnn_extractor_extract(ex, "output_layer", &out) line
?
bxjv4tth6#
I'm using c, not cpp, this function contains properties of an object
lvjbypge7#
then I can suggest you to follow the ncnn wiki with c++.
5cg8jx4n8#
Error solved for "segmentation fault": add tf.keras.layer.Permute(3,1,2) to convert input from NHWC to NCHW. This solves segmentation fault. Because onnx2ncnn is for conversion from pytorch which uses NCHW.
jfewjypa9#
How do I do this correct conversion to Mat in python?