I had a similar problem and tried to set the input tensor values ββin C ++ for a model prepared in Python. The model is a simple NN with one hidden layer to learn how to calculate the XOR operation.
First, I created the output graphic file with both the structure of the graph and the model parameters, following the steps 1-4 of this good post: https://medium.com/@hamedmp/exporting-trained-tensorflow-models-to-c- the-right-way-cf24b609d183 # .j4l51ptvb .
Then in C ++ (a simple example of iOS TensorFlow) I used the following code:
tensorflow::Tensor input_tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({4,2}));
auto input_tensor_mapped = input_tensor.tensor<float, 2>();
input_tensor_mapped(0, 0) = 0.0;
input_tensor_mapped(0, 1) = 0.0;
input_tensor_mapped(1, 0) = 0.0;
input_tensor_mapped(1, 1) = 1.0;
input_tensor_mapped(2, 0) = 1.0;
input_tensor_mapped(2, 1) = 0.0;
input_tensor_mapped(3, 0) = 1.0;
input_tensor_mapped(3, 1) = 1.0;
tensorflow::Status run_status = session->Run({{input_layer, input_tensor}},
{output_layer}, {}, &outputs);
After that, it GetTopN(output->flat<float>(), kNumResults, kThreshold, &top_results);returns the same 4 values ββ(0.94433498, 0.94425952, 0.06565627, 0.05823805) as in my Python test code for XOR after training the model in top_results.
, {1,1,10}, :
auto input_tensor_mapped = input_tensor.tensor<float, 3>();
input_tensor_mapped(0, 0, 0) = 0.0;
input_tensor_mapped(0, 0, 1) = 0.1;
....
input_tensor_mapped(0, 0, 9) = 0.9;
: Matrix OpenCV Tensorflow ++? .