Same model has different results in python and java


keras model , saved in .h5 file ;
then read h5 file and import it in java

I found that most predicted values are smaller than the real ones;

The error is a little bit huge and I want to fix it. Thanks in advance!

I solved this question by using new keras version.
in DL4J , more parameters should be fixed, results are good enough then.

@Dominic97 did you use keras 1? We have a ton of regression tests to prevent these kinds of issues. If you have anything in particular we should be testing for, please let me know.

@agibsonccc Hi, some of the tensorflow-keras-import-examples also mention the Python filename, which was used for training, e.g:

deeplearning4j-examples\tensorflow-keras-import-examples\src\main\java\org\deeplearning4j\modelimportexamples\tf\quickstart\MNISTMLP.java

says

/**

  • Shows tensorflow import using mnist.
  • For the trained graph, please look at the python files under
  • Mnist/
  • mnist_tf.py was used to train the graph
  • @author Fariz Rahman
    */

or

deeplearning4j-examples\tensorflow-keras-import-examples\src\main\java\org\deeplearning4j\modelimportexamples\tf\quickstart\ModifyMNISTMLP.java

says

//Python code for this can be found in ~/dl4j-examples-data/dl4j-examples/modelimport/tensorflow under generate_model.py and freeze_model_after.py

How do you think I could access these Python scripts…?

Any pointer would be most welcome

@franzm64 could you clarify what your issue is? You’re saying import results are different? That’s by definition a bug and should not be debugged by you unless it’s just to verify the problem. The framework should be compatible. Could you file an issue with more explanation including your version you’re using and why you think it’s wrong at Issues · eclipse/deeplearning4j · GitHub ?

@agibsonccc Hi, sorry for this misunderstanding — perhaps I should have started a new thread.

To cut a long story short, I’m after importing a model (MLP and also CNN) trained and saved in Python into DL4J. I got this Lecture 7 | Import a Keras Neural Net Model into Deeplearning4j - YouTube old example working from begin (in Python) to end (inference in Java). But then I failed reading in a CNN and I have not found a detailed documentation of this process – yet.

I can see from the ModifyMNISTMLP.java example that you are reading in a file called frozen_model.pb, but I’d be interested in how it was created in Python and what is in it.

So, I’d be very grateful for pairs of Python/Java files which do this trick.

PS. You see this may not be an issue at all, just my ignorance, which is rooted in my finding no documentation.

@franzm64 could you just use the newest versions of everything? Those tutorials are very old and should not be used as a reference beyond maybe explaining the concepts.
Import should “just work” and if not it’s likely a version issue or a bug. There’s no need for you to debug the internals of the framework.