DL4J on Android

Hi everyone, I am trying to import my keras model over to DL4J on android. However, I am stuck with “Platform “android-arm64” not supported by class org.bytedeco.javacpp.hdf5”. Is there a workaround to this? If not would anyone kindly advise me on alternatives that will allow me to import a python model and perform training on android? Thank you sooo much in advance

@saudet can help you here

Import the model from your development machine.

Unfortunately that was what threw the error that i mentioned previously on android studio using the DL4J dependency.

“android-arm64” -> That’s not your development machine. You’ll need a Linux, Mac, or Windows machine to develop applications for Android.

ahh i get what you mean. But is there no way to import it locally on the android app?

If you need to do that, please explain why you need to do that. There is probably a better way of doing what you’re doing.

In this case, I agree with @saudet if all you want to do is import a model, resaving in on another machine doesn’t really affect your workflow. Setup a util class that manages this process, document it in a readme, move on? It’s not like you’re running a python training workflow on your android phone.

Oh I am exploring ways to perform federated learning on a mobile. However, because I am more familiar with model creation using python, I want to export my python model over to my android to perform training on the device before sending the model back to the development machine for aggregation.

@achan021 it’s a bit old, but someone did this a few years back:

Even with model import, you’ll have to update your model using java/kotlin anyways.
All you would have to do is run a sub process that uses dl4j to export the model and then load it on mobile. You could do that in the same process. It’d be 1 or 2 lines of java code.

ahh so just to make sure that I am getting you correctly. I can convert my python model to DL4J format before exporting to the mobile platform, is that correct?

@achan021 yes that’s all you’d have to do. That’s what @saudet suggested as well:
train model -> import in to dl4j -> run on device load using dl4j.

The only thing that’s missing is running hdf5 on mobile is a bit obnoxious. It’s mainly supported on desktop OSes.

When the work around is fairly straightforward, there’s not a lot of ROI in trying to make that work.

Ahh I see, what about the conversion from DL4J format to possible keras model. Does DL4J support that feature?

@achan021 not directly, but it’s straightforward to export weights and load them in keras. We allow writing numpy arrays.

Alright, thank you soo much for your time!!