[SOLVED] Example in C++ of loading a network created in Mathematica

Hello I’m working on a c++ code for loading networks created in Mathematica.
I have followed the only c++ example in the repository.
I have tried to generalize this code but I have some problems to configure the following variables:

const mx_uint input_shape_indptr[2] = { 0, 4 };
const mx_uint input_shape_data[4] = { 1,
                                    static_cast<mx_uint>(channels),
                                    static_cast<mx_uint>(height),
                                    static_cast<mx_uint>(width)};

My code is on a github repo (https://github.com/tonegas/MXNetWrapper)
The example is in the src/main.cpp file.
To test my code in the example. First of all I have tried to load Inception-BN network and it works.
Then I created and exported a simple network in Mathematica.
My graph is a simple linear layer with bias:

output = W * input + b

with the following dimensions: W 2 rows a 3 column, b 2 column, input 3 column and the output 2 column.
I have configured the two same variables as:

const mx_uint input_shape_indptr[2] = { 0, 2 };
const mx_uint input_shape_data[2] = { 1, 3 };

and I have also tried:

const mx_uint input_shape_indptr[2] = { 0, 1 };
const mx_uint input_shape_data[1] = { 3 };

but the network does not run yet. In both cases the output of the network change every time I call the network that means there is a buffer overflow somewhere. In the second case the dimensions of the output are wrong.

I think that I made a mistake on use MXPredCreate and my configuration parameters input_shape_indptr, input_shape_dat are wrong.

Do you you how to be configured the parameters?
I hope that someone can have a look on my code and help me!
Thanks!


The problem is in the exported Mathematica files. The exported files are not compliant with the standard MXNet and this causes the error in the loading. The solution is to change the way of exporting by Mathematica. It is fully explained in https://mathematica.stackexchange.com/a/162479/54287

Already solved by OP.