# net.Forward outputs differ from the keras outputs

I have an issue concerning the classification when using net.forward. First I have trained my model in Keras with TensorFlow as backend. Then I save the model as .pb. I can import it successfully in OpenCV using 'ReadNetFromTensorflow' in C#. I'm using the OpenCVSharp nuget package. The problem I encounter is that my predictions now are not the same as I get in Keras. The accuracy differs a lot. Here is the link for the .pb file. Btw I was using the Flatten layer but as it is not supported by OpenCV (I was getting a error while loading the model) I have changed it to a Reshape layer. I don't know what else to do. Any help? Here is the code I have used for training:

model = K.models.Sequential()

#From Flatten to Reshape
a,b,c,d = model.output_shape
a = b*c*d
model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout

sgd = tf.keras.optimizers.SGD(lr=lr, decay=decay, momentum=0.9, nesterov=False)

model.compile(loss=keras.losses.categorical_crossentropy,
optimizer='sgd',
metrics=['accuracy'])


Then I use the following code to obtain the .pb file:

sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['output_node/Softmax'])
tf.train.write_graph(constant_graph, "", "graph.pb", as_text=False)


Then, in C# I use the following code to try inference:

var model = System.IO.Path.Combine(Location, Model);
var image = System.IO.Path.Combine(Location, sampleImage);
PrintMat ...