Hi all
I'm testing a neural network in Java. Unfortunately the compilation gives me a class not found error and I can't solve the problem. Can anyone help me?
Error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 43 (Main)
java.lang.ClassNotFoundException: org.deeplearning4j$nn$conf$NeuralNetConfiguration$Builder
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
at b4j.example.main._initializeneuralnetconfiguration(main.java:122)
at b4j.example.main._appstart(main.java:79)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at b4j.example.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
I'm testing a neural network in Java. Unfortunately the compilation gives me a class not found error and I can't solve the problem. Can anyone help me?
Error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 43 (Main)
java.lang.ClassNotFoundException: org.deeplearning4j$nn$conf$NeuralNetConfiguration$Builder
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
at b4j.example.main._initializeneuralnetconfiguration(main.java:122)
at b4j.example.main._appstart(main.java:79)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at b4j.example.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
trial model:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
#AdditionalJar: deeplearning4j-core-1.0.0-M2.1.jar
#AdditionalJar: nd4j-native-platform-1.0.0-M2.1.jar
#AdditionalJar: slf4j-api-2.1.0-alpha1.jar
#AdditionalJar: slf4j-simple-2.1.0-alpha1.jar
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
' Costruzione della configurazione della rete neurale
Dim nnConf As JavaObject
nnConf = InitializeNeuralNetConfiguration
If nnConf.IsInitialized Then
Log("Neural network configuration initialized successfully")
Else
Log("Failed to initialize neural network configuration")
End If
' Creazione del modello
Dim model As JavaObject
model.InitializeNewInstance("org.deeplearning4j.nn.multilayer.MultiLayerNetwork", Array(nnConf))
model.RunMethod("init", Null)
' Stampa del sommario del modello
Log(model.RunMethod("summary", Null))
' Esempio di addestramento con dati fittizi
TrainModel(model)
End Sub
Sub InitializeNeuralNetConfiguration As JavaObject
Dim nnConf As JavaObject
nnConf.InitializeNewInstance("org.deeplearning4j.nn.conf.NeuralNetConfiguration$Builder", Null)
nnConf = nnConf.RunMethod("seed", Array(12345)) ' Seed per la randomizzazione dei pesi
nnConf = nnConf.RunMethod("updater", Array(CreateUpdater("adam"))) ' Ottimizzatore Adam
nnConf = nnConf.RunMethod("list", Null)
nnConf = nnConf.RunMethod("layer", Array(0, CreateDenseLayer(8, 26, "relu"))) ' Primo layer
nnConf = nnConf.RunMethod("layer", Array(1, CreateDenseLayer(26, 26, "relu"))) ' Secondo layer
nnConf = nnConf.RunMethod("layer", Array(2, CreateDenseLayer(26, 26, "relu"))) ' Terzo layer
nnConf = nnConf.RunMethod("layer", Array(3, CreateDenseLayer(26, 8, "relu"))) ' Quarto layer
nnConf = nnConf.RunMethod("layer", Array(4, CreateOutputLayer(8, 8, "softmax"))) ' Output layer
nnConf = nnConf.RunMethod("build", Null)
Return nnConf
End Sub
Sub CreateDenseLayer(numInput As Int, numOutput As Int, activation As String) As JavaObject
Dim denseLayerBuilder As JavaObject
denseLayerBuilder.InitializeNewInstance("org.deeplearning4j.nn.conf.layers.DenseLayer$Builder", Null)
denseLayerBuilder = denseLayerBuilder.RunMethod("nIn", Array(numInput))
denseLayerBuilder = denseLayerBuilder.RunMethod("nOut", Array(numOutput))
denseLayerBuilder = denseLayerBuilder.RunMethod("activation", Array(activation))
denseLayerBuilder = denseLayerBuilder.RunMethod("weightInit", Array("xavier"))
Return denseLayerBuilder.RunMethod("build", Null)
End Sub
Sub CreateOutputLayer(numInput As Int, numOutput As Int, activation As String) As JavaObject
Dim outputLayerBuilder As JavaObject
outputLayerBuilder.InitializeNewInstance("org.deeplearning4j.nn.conf.layers.OutputLayer$Builder", Null)
outputLayerBuilder = outputLayerBuilder.RunMethod("nIn", Array(numInput))
outputLayerBuilder = outputLayerBuilder.RunMethod("nOut", Array(numOutput))
outputLayerBuilder = outputLayerBuilder.RunMethod("activation", Array(activation))
outputLayerBuilder = outputLayerBuilder.RunMethod("weightInit", Array("xavier"))
outputLayerBuilder = outputLayerBuilder.RunMethod("lossFunction", Array("negativeloglikelihood"))
Return outputLayerBuilder.RunMethod("build", Null)
End Sub
Sub CreateUpdater(updaterType As String) As JavaObject
Dim updater As JavaObject
updater.InitializeStatic("org.nd4j.linalg.learning.config." & updaterType.SubString2(0,1).ToUpperCase & updaterType.SubString(1).ToLowerCase)
Return updater
End Sub
Sub TrainModel(model As JavaObject)
' Esempio di dati fittizi per l'addestramento
Dim features(,) As Double = Array(Array(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Array(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0))
Dim labels(,) As Double = Array(Array(1.0, 0.0), Array(0.0, 1.0))
' Creazione delle matrici di input e output
Dim Nd4j As JavaObject
Nd4j.InitializeStatic("org.nd4j.linalg.factory.Nd4j")
Dim input As JavaObject = Nd4j.RunMethod("create", Array(features))
Dim output As JavaObject = Nd4j.RunMethod("create", Array(labels))
' Addestramento del modello
For i = 1 To 1000
model.RunMethod("fit", Array(input, output))
Next
' Predizione con il modello addestrato
Dim prediction As JavaObject = model.RunMethod("output", Array(input))
Log("Predictions: " & prediction)
End Sub
Sub MainForm_CloseRequest (EventData As Event)
MainForm.Close
End Sub