How to load with Julia a h5 file created from Keras in Python ? With Flux.jl or with another ML package?

Hi,

Is there a simple way to load with Julia a h5 file created with Python3-Keras without rebuilding this h5 model ?

More precisely, what should be the Julia version of this simple Python3 script :

# Python3 code of the load of a Python3-Keras h5 model :
import numpy as np
from keras.models import load_model
best_model = load_model('model.h5')
dim_1=24
dim_2=46
x=np.zeros((dim_1,dim_2))
simulation = best_model.predict(x)

Is there a way by using Flux.jl ? Or with another ML package such as onnx.jl ?

Thanks very much !

I think your best bet right now is to export the model to onnx in python unless you want to use Keras through pycall.

There are a few unmaintained packages for Keras h5 format and I think I have gotten one of them to work by just deving it and fixing all errors which popped up when trying to import.

If your model is simple enough it might be workable to just use hdf5.jl, explore the file and write a one off importer. Last time I checked the format was pretty straightforward.

1 Like