How to import a pre-trained neural network into Flux.jl ?

I’m using the Flux library in Julia. How can I import an Inception neural network into it?

I’ve seen that the following can be done in Mocha.jl to import a pre-trained net.

using HDF5 
h5open("model/bvlc_reference_caffenet.hdf5", "r") do h5
load_network(h5, net)
end
init(net)

Is there some way I can import a pre-trained model in Flux?

1 Like

What models are you looking to load?

For models you trained in Flux itself, see loading and saving models in the docs.

For models trained in other frameworks there are fewer options, though it’s not that hard to write a parser for most model formats. We have ONNX.jl, which we used to load VGG19, but it’s pretty rough around the edges right now.

xref: neural network - How to use a pre-trained model in Flux.jl? - Stack Overflow

1 Like

I want to load the InceptionV3 model. Any way to do this?

https://keras.io/applications/#inceptionv3

You have two options:

(1) Write a keras model reader (which would be a great contribution!)
(2) Export the model to ONNX from keras, and then load it via ONNX.jl

2 Likes

Is there any documentation on using ONNX.jl to read in an onnx file into Flux?

Also, is there a way to go from flux → onnx? (If not, I’d be interesting in working on something like this and would welcome pointers on getting started)

3 Likes

@MikeInnes, could you provide a bit more info/pointers on creating a Keras model reader? :slight_smile: Sounds like an interesting project.

Sure. The steps are basically:

  • Read the Keras format into a Julia data structure
  • Turn the data structure into Julia code (probably via IRTools)
  • Either eval this code or turn it into a .jl script.

I’m not that familiar with the Keras format, but I think they may separate the weights and architecture into HDF5 and JSON files. If so that’d make step 1 pretty easy, since we have readers for both of those formats.

1 Like