Я начал работать с deeplearning4j в Android, но у меня есть проблема, которая не имела решения в последние дни.
Когда я определяю нейронную сеть, я не вижу проблем, связанных с отсутствиемклассы или что-то подобное.
DenseLayer inputLayer = new DenseLayer.Builder()
.nIn(n_inputs)
.nOut(45)
.name("Input")
.build();
DenseLayer hiddenLayer = new DenseLayer.Builder()
.nIn(45)
.nOut(45)
.name("Hidden")
.build();
OutputLayer outputLayer = new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nIn(45)
.nOut(n_outputs)
.name("Output")
.activation(Activation.SOFTMAX)
.build();
NeuralNetConfiguration.Builder nncBuilder = new NeuralNetConfiguration.Builder();
Однако, когда я запускаю свое приложение, я сталкиваюсь с ошибкой типа java.lang.NoClassDefFoundError и java.lang.RuntimeException. Класс распознается при разработке кода, но не после компиляции. Проблема находится в строке определения OutputLayer.
2019-10-04 09:06:28.404 15477-15554/com.example.behavioursim E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.behavioursim, PID: 15477
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/nd4j/linalg/lossfunctions/LossFunctions$LossFunction;
at com.example.behavioursim.ia.BehaviourNeuralNetwork.createNetwork(BehaviourNeuralNetwork.java:122)
at com.example.behavioursim.ia.BehaviourNeuralNetwork.generateModel(BehaviourNeuralNetwork.java:73)
at com.example.behavioursim.ui.simulacion.SimulacionFragment$InitModelTask.doInBackground(SimulacionFragment.java:255)
at com.example.behavioursim.ui.simulacion.SimulacionFragment$InitModelTask.doInBackground(SimulacionFragment.java:247)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.nd4j.linalg.lossfunctions.LossFunctions$LossFunction" on path: DexPathList[[zip file "/data/app/com.example.behavioursim-98U7cM9-8aCsBoLJTZm2Wg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.behavioursim-98U7cM9-8aCsBoLJTZm2Wg==/lib/arm64, /data/app/com.example.behavioursim-98U7cM9-8aCsBoLJTZm2Wg==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.example.behavioursim.ia.BehaviourNeuralNetwork.createNetwork(BehaviourNeuralNetwork.java:122)
at com.example.behavioursim.ia.BehaviourNeuralNetwork.generateModel(BehaviourNeuralNetwork.java:73)
at com.example.behavioursim.ui.simulacion.SimulacionFragment$InitModelTask.doInBackground(SimulacionFragment.java:255)
at com.example.behavioursim.ui.simulacion.SimulacionFragment$InitModelTask.doInBackground(SimulacionFragment.java:247)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
2019-10-04 09:06:28.497 15477-15554/com.example.behavioursim I/Process: Sending s
Это мой файл gradle (плагин gradle версии 3.5.1, но я пробовал несколько версий, но он все еще не работает):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.behavioursim"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion = '29.0.2'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
//implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
//implementation 'org.tensorflow:tensorflow:1.14.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'org.apache.commons:commons-lang3:3.9'
//for retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'androidx.multidex:multidex:2.0.0'
//OPTION 3
implementation (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta5') {
exclude group: 'org.bytedeco', module: 'opencv-platform'
exclude group: 'org.bytedeco', module: 'leptonica-platform'
exclude group: 'org.bytedeco', module: 'hdf5-platform'
exclude group: 'org.nd4j', module: 'nd4j-base64'
}
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5'
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm"
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-arm64"
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86"
implementation group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta5', classifier: "android-x86_64"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.6-1.5.1'
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.6-1.5.1', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.6-1.5.1', classifier: "android-arm64"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.6-1.5.1', classifier: "android-x86"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.6-1.5.1', classifier: "android-x86_64"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.0-1.5.1'
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.0-1.5.1', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.0-1.5.1', classifier: "android-arm64"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.0-1.5.1', classifier: "android-x86"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.0-1.5.1', classifier: "android-x86_64"
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5.1'
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5.1', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5.1', classifier: "android-arm64"
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5.1', classifier: "android-x86"
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.78.0-1.5.1', classifier: "android-x86_64"
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}