Hello I’m working with Mathematica and neural networks.
In these days I’m trying to load a simple network exported by Mathematica using MxNet C++ API.
My graph is a simple linear layer with bias:
output = W * input + b
with the following dimensions: W 2 rows a 3 columns, b 2 columns, input 3 columns and the output 2 columns.
The Mathematica code is as follows:
linear = LinearLayer[2, "Input" -> 3,
"Weights" -> {{0.8, 0.6, 5.6}, {1.2, 2.3, 3.2}},
"Biases" -> {2.3, 3}]
net = NetChain[{linear}, "Input" -> 3]
Export["netTest.json", net, "MXNet"]
This code creates two files netTest.params and netTest.json.
These two files are loaded using BufferFile class as in example “https://github.com/apache/incubator-mxnet/tree/master/example/image-classification/predict-cpp”.
BufferFile json_data("netTest.json");
BufferFile param_data("netTest.params");
Then MXPredCreate is called to create the network, using the file loaded as:
// Create Predictor
MXPredCreate( //Function to load a network by MXNet C++ API
(const char*)json_data.GetBuffer(), //Network structure
(const char*)param_data.GetBuffer(), //Network weights
static_cast<size_t>(param_data.GetLength()), //Weights file size
1, //dev_type: (1: cpu, 2: gpu)
0, //dev_id: (arbitrary)
1, //num_input_nodes: (1 for feedward)
input_keys, //Exaplained after
input_shape_indptr, //Exaplained after
input_shape_data, //Exaplained after
&net);
MXPredCreate has some parameters to be set, the most important are: “input_keys”, “input_shape_indptr”, “input_shape_data”. The input_keys parameter is the list of the placeholders of the network in Mathematica the standard name of the placeholder is “Input”.
const char* input_keys[1] = {"Input"};
For input_shape_indptr, and input_shape_data parameters I’m not sure which is the right value:
const mx_uint input_shape_indptr[] = ???;
const mx_uint input_shape_data[] = ???;
How should I set my parameters in my example? Or more in general?