-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Cannot use reflections - Keras and custom layers can't be used as a result #4504
Comments
Still fails when trying to import the model though. Opened up an issue on DL4J here: deeplearning4j/deeplearning4j#4504
Looks like TensorFlowCnnToFeedForwardPreProcessor is missing from the list here: |
Probably not, unfortunately - they are in different modules - hence we can't reference the Keras classes in InputPreProcessor annotations. |
Ah, reflection. @coolioasjulio You might need to disable ProGuard on these classes to get reflection to work properly. |
If that doesn't work, I can probably work out a manual (and ugly) workaround to manually register the Keras classes for JSON (de)serialization. But I'd recommend trying to get reflection working properly first :) |
@saudet How do you disable proguard? I added this to proguard-rules.pro:
However, the same error showed up. Then I tried setting this in the build.gradle in android > buildTypes > release:
Even with this on, the same error persists. Am I disabling proguard correctly? |
Probably safe to say it's disabled. Is there anything in the log that shows something related to errors with reflection? |
@saudet No, it doesn't say anything about reflection or proguard. It just says: It then prints out the entire JSON structure of the model, and then references some classes. After disabling proguard the stack trace hasn't changed at all from before, even after cleaning and rebuilding. The full stack trace is at the top in the original issue, if you want to read the whole thing. |
Use Logback, Log4j, or something to display debug messages from DL4J and see what it says. |
@saudet I set up logback and this is what I got: (these are only the lines printed by logback)
So it looks like it has something to do with reflection. What does it mean |
I'm not 100% sure, but I suspect this indicates that the reflections library can't find (or access?) JARs on the classpath. Normally it'll get a list of dependency JARs to scan, and then scan all of them for classes/resources. It's not something that the user should be messing with, generally. |
I've already turned off proguard to see if that helps with the reflections. What else can I do? Is this a fix that would have to be implemented in the library? (not on my end) |
That is something we can do to fix it, but it's not a simple/easy fix... Beyond that, I'm not sure why reflections is having trouble here. As to the ugly workaround that I mentioned previously - you can try this before loading your network:
Note that I have not tested this, but in theory this (or something close) should work. |
Looks like Reflections doesn't work so well on Android, so yeah we shouldn't be relying on it... |
@AlexDBlack Yeah, that works! I needed to add Thanks so much, I was having a hell of a time trying to get this to work! |
Great. I'll re-open this actually, until we have a confirmed real/proper solution for it (i.e., no more reflections required) |
Still fails when trying to import the model though. Opened up an issue on DL4J here: deeplearning4j/deeplearning4j#4504
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I trained a model in keras 1.2.2, and I'm trying to load it into DL4J 0.9.1 on Android.
I've followed the steps at #3261 to convert the model into a zip file using
ModelSerializer
. I was able to import the keras model and export it into the DL4J format on desktop. However, when I try to import it on android, it fails, talking about aTensorFlowCnnToFeedForwardPreProcessor
.This is the relevant line in the stacktrace:
Caused by: java.lang.RuntimeException: org.nd4j.shade.jackson.databind.JsonMappingException: Could not resolve type id 'TensorFlowCnnToFeedForwardPreProcessor' into a subtype of [simple type, class org.deeplearning4j.nn.conf.InputPreProcessor]: known type ids = [InputPreProcessor, binomialSampling, cnnToFeedForward, cnnToRnn, composableInput, feedForwardToCnn, feedForwardToRnn, rnnToCnn, rnnToFeedForward, unitVariance, zeroMean, zeroMeanAndUnitVariance]
The full stacktrace is here: https://pastebin.com/ajTDzPS9
My build.gradle file is here: https://pastebin.com/HmhS9kJK
I'm trying to load the model using
ModelSerializer.restoreMultiLayerNetwork()
.The github repo with all the code is here: https://github.com/coolioasjulio/devanagari-excercise-app/tree/with-model-import
The text was updated successfully, but these errors were encountered: