# Same model has different results in python and java

**URL:** <https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860>\
**Category:** DL4J\
**Created:** [September 17, 2020, 3:20pm UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860 "2020-09-17T15:20:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic97](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@Dominic97](https://community.konduit.ai/u/Dominic97)\
**Post date:** [September 17, 2020, 3:20pm UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/1 "2020-09-17T15:20:40Z")

</div>

![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/d9f5bbcd28ba2907ba7f4f64f2ef5d80d4d21061.png)  
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!

---

<div class="post-metadata">

**Author:** ![Dominic97](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@Dominic97](https://community.konduit.ai/u/Dominic97)\
**Post date:** [September 18, 2020, 6:29am UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/2 "2020-09-18T06:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [September 18, 2020, 6:42am UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/3 "2020-09-18T06:42:32Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![franzm64](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@franzm64](https://community.konduit.ai/u/franzm64)\
**Post date:** [August 12, 2022, 11:14pm UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/4 "2022-08-12T23:14:30Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 13, 2022, 1:04am UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/5 "2022-08-13T01:04:02Z")

</div>

@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](https://github.com/eclipse/deeplearning4j/issues) ?

---

<div class="post-metadata">

**Author:** ![franzm64](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@franzm64](https://community.konduit.ai/u/franzm64)\
**Post date:** [August 13, 2022, 1:55pm UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/6 "2022-08-13T13:55:46Z")

</div>

@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 [https://www.youtube.com/watch?v=bI1aR1Tj2DM](https://www.youtube.com/watch?v=bI1aR1Tj2DM) 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.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 16, 2022, 7:52am UTC](https://community.konduit.ai/t/same-model-has-different-results-in-python-and-java/860/7 "2022-08-16T07:52:03Z")

</div>

@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.
