What are the requirements to load the trained model by Keras in Java?

I checked that DeepLearning4J supports Keras models, network architecture and weights can be easily loaded. The only cons are probably that we need to use ND4J backend or it does not matter?

If there is a created model using keras and tensorflow, what is the best way to load it in Java ecosystem?

I tried to use frozen graph script to save tensorflow model, but it cannot be loaded with SavedModel.load. Loading model as a Tensor Graph object seems to be common way, but available examples in Java are chaos especially when input is an image.

  • $\begingroup$ what format is your model in? Onnx? $\endgroup$
    – ngopal
    Feb 7, 2020 at 22:59
  • $\begingroup$ are you using CPU or GPU? $\endgroup$
    – Donald S
    Jun 14, 2020 at 4:52

1 Answer 1


Giving you some links which have worked:

deploying-keras-deep-learning-models-with-java : this uses DeepLearning4J, ND4J which supposedly you have tried already.


And same question is asked here - converting-keras-in-python-to-java . It uses KerasModelImport.importKerasSequentialModelAndWeight

You should give HDF5 file operation java examples: hdf-java . It would be helpful if you want to change the weights yourself

Please comment if you have already tried all these already.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.