Getting Errors while saving model in .h5 in pytorch and loading in .DL4J

I have a model in .h5 and I was able load it and evaluate in pytorch. But when I am trying to load the same .h5 in DL4J I am getting this error
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:

#000: H5F.c line 511 in H5Fopen(): unable to open file

major: File accessibilty

minor: Unable to open file

#001: H5Fint.c line 1604 in H5F_open(): unable to read superblock

major: File accessibilty

minor: Read failed

#002: H5Fsuper.c line 413 in H5F__super_read(): file signature not found

major: File accessibilty

minor: Not an HDF5 file

Exception in thread “main” java.lang.RuntimeException: H5Fopen failed

at org.bytedeco.javacpp.hdf5$H5File.allocate(Native Method)

at org.bytedeco.javacpp.hdf5$H5File.(

at org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.(

at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.modelHdf5Filename(

at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasSequentialModelAndWeights(
and this how I save and load the model.,‘mod.h5’)
m = torch.load(‘mod.h5’)


It looks like you are trying to load a model saved in PyTorch with a Java wrapper for Keras models.
Keras does not support loading PyTorch models, so you won’t be able to load it.

Note that the file type (.h5 in this case) is just the filename extension.

Thanks a lot for your reply.I was told that .h5 models can be used in DL4J.But its throwing an error.