Dl4jMlpClassifier in java code

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Dl4jMlpClassifier in java code

Tarfa
I am trying to use Dl4jMlpClassifier in java code. I have written this line
only:

Dl4jMlpClassifier DL = new Dl4jMlpClassifier();

But it is giving me this run-time error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/optimize/api/BaseTrainingListener
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at
javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:39)
        at javaapplication1.JavaApplication1.main(JavaApplication1.java:91)
Caused by: java.lang.ClassNotFoundException:
org.deeplearning4j.optimize.api.BaseTrainingListener
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 14 more
-------------
So, could you please help in getting this classifier working in java? I did
import the package at the beginning.
BTW: The classifier is working fine in weka GUI.



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Dl4jMlpClassifier in java code

Eibe Frank-2
Administrator
It is best to use any learning schemes that come in separate WEKA packages (like Dl4jMlpClassifier) through reflection, loading the package .jar files using the package manager's loadPackages() method rather than explicitly adding them to the Java CLASSPATH.

Below is an example based on a filter that we have written for Dl4j, but the same principle applies to classifiers. For classifiers, getting an object is slightly simpler by calling forName() in AbstractClassifier rather than the more general forName() in Utils.

Cheers,
Eibe

// Load all packages so that Dl4jMlpFilter class can be found using forName("weka.filters.unsupervised.attribute.Dl4jMlpFilter")

weka.core.WekaPackageManager.loadPackages(true);

// Load the dataset
weka.core.Instances instances = new weka.core.Instances(new FileReader("/Users/eibe/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist.meta.minimal.arff"));
instances.setClassIndex(1);
String[] filterOptions = weka.core.Utils.splitOptions("-iterator \".ImageInstanceIterator -imagesLocation /Users/eibe/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist-minimal -bs 12\" -poolingType AVG -layer-extract \".DenseLayer -name res4a_branch2b\" -layer-extract \".DenseLayer -name flatten_1\" -isZoo true -zooModel \".Dl4JResNet50\"");
weka.filters.Filter myFilter = (weka.filters.Filter)weka.core.Utils.forName(weka.filters.Filter, "weka.filters.unsupervised.attribute.Dl4jMlpFilter", filterOptions);
myFilter.setOptions();

// Run the filter, using the model as a feature extractor
myFilter.setInputFormat(instances);
weka.core.Instances transformedInstances = weka.filters.Filter.useFilter(instances, myFilter);

// You could save the instances at this point to an arff file to be used with other classifiers via:
// https://waikato.github.io/weka-wiki/formats_and_processing/save_instances_to_arff/

// CV our Random Forest classifier on the extracted features
weka.classifiers.evaluation.Evaluation evaluation = new weka.classifiers.evaluation.Evaluation(transformedInstances);
int numFolds = 10;
evaluation.crossValidateModel(new weka.classifiers.trees.RandomForest(), transformedInstances, numFolds, new Random(1));
System.out.println(evaluation.toSummaryString());
System.out.println(evaluation.toMatrixString());

On 22/05/2020, at 10:00 AM, Tarfa <[hidden email]> wrote:

I am trying to use Dl4jMlpClassifier in java code. I have written this line
only:

Dl4jMlpClassifier DL = new Dl4jMlpClassifier();

But it is giving me this run-time error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/optimize/api/BaseTrainingListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at
javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:39)
at javaapplication1.JavaApplication1.main(JavaApplication1.java:91)
Caused by: java.lang.ClassNotFoundException:
org.deeplearning4j.optimize.api.BaseTrainingListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more
-------------
So, could you please help in getting this classifier working in java? I did
import the package at the beginning.
BTW: The classifier is working fine in weka GUI.



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html


_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Dl4jMlpClassifier in java code

Tarfa
Thank you Eibe,
I modified your code in this way:
------------------------------------
weka.core.WekaPackageManager.loadPackages(true);
            data.setClassIndex(data.numAttributes()-1);
String[] filterOptions = weka.core.Utils.splitOptions("-iterator
\".ImageInstanceIterator -imagesLocation
/Users/Malak/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist-minimal
"
        + "-bs 12\" -poolingType AVG -layer-extract \".DenseLayer -name
res4a_branch2b\" -layer-extract \".DenseLayer -name flatten_1\" "
        + "-isZoo true -zooModel \".Dl4JResNet50\"");

weka.classifiers.AbstractClassifier myclassifier =
(weka.classifiers.AbstractClassifier)weka.classifiers.AbstractClassifier.forName(weka.classifiers.functions.Dl4jMlpClassifier,
"weka.classifiers.functions.Dl4jMlpClassifier", filterOptions);
myclassifier.setOptions(filterOptions);
--------------------------------------
but it is giving me this compilation error:
error: cannot find symbol
weka.classifiers.AbstractClassifier myclassifier =
(weka.classifiers.AbstractClassifier)weka.classifiers.AbstractClassifier.forName(weka.classifiers.functions.Dl4jMlpClassifier,
"weka.classifiers.functions.Dl4jMlpClassifier", filterOptions);
  symbol:   class functions
  location: package weka.classifiers
1 error

So, can you help fixing this error?
Thank you

Tarfa



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Dl4jMlpClassifier in java code

Eibe Frank-2
Administrator
I think it should just be

weka.classifiers.Classifier myclassifier = weka.classifiers.AbstractClassifier.forName("weka.classifiers.functions.Dl4jMlpClassifier", filterOptions)

Cheers,
Eibe

> On 23/05/2020, at 8:52 AM, Tarfa <[hidden email]> wrote:
>
> Thank you Eibe,
> I modified your code in this way:
> ------------------------------------
> weka.core.WekaPackageManager.loadPackages(true);
>            data.setClassIndex(data.numAttributes()-1);
> String[] filterOptions = weka.core.Utils.splitOptions("-iterator
> \".ImageInstanceIterator -imagesLocation
> /Users/Malak/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist-minimal
> "
>        + "-bs 12\" -poolingType AVG -layer-extract \".DenseLayer -name
> res4a_branch2b\" -layer-extract \".DenseLayer -name flatten_1\" "
>        + "-isZoo true -zooModel \".Dl4JResNet50\"");
>
> weka.classifiers.AbstractClassifier myclassifier =
> (weka.classifiers.AbstractClassifier)weka.classifiers.AbstractClassifier.forName(weka.classifiers.functions.Dl4jMlpClassifier,
> "weka.classifiers.functions.Dl4jMlpClassifier", filterOptions);
> myclassifier.setOptions(filterOptions);
> --------------------------------------
> but it is giving me this compilation error:
> error: cannot find symbol
> weka.classifiers.AbstractClassifier myclassifier =
> (weka.classifiers.AbstractClassifier)weka.classifiers.AbstractClassifier.forName(weka.classifiers.functions.Dl4jMlpClassifier,
> "weka.classifiers.functions.Dl4jMlpClassifier", filterOptions);
>  symbol:   class functions
>  location: package weka.classifiers
> 1 error
>
> So, can you help fixing this error?
> Thank you
>
> Tarfa
>
>
>
> --
> Sent from: https://weka.8497.n7.nabble.com/
> _______________________________________________
> Wekalist mailing list -- [hidden email]
> Send posts to [hidden email]
> To unsubscribe send an email to [hidden email]
> To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Dl4jMlpClassifier in java code

Tarfa
Thank you Eibe,
I modified the code in this way:
----------------------------------------------------------
 weka.core.WekaPackageManager.loadPackages(true);
            data.setClassIndex(data.numAttributes()-1);
String[] filterOptions = weka.core.Utils.splitOptions("-iterator
\".ImageInstanceIterator -imagesLocation
/Users/Malak/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist-minimal
"
        + "-bs 12\" -poolingType AVG -layer-extract \".DenseLayer -name
res4a_branch2b\" -layer-extract \".DenseLayer -name flatten_1\" "
        + "-isZoo true -zooModel \".Dl4JResNet50\"");

weka.classifiers.Classifier myclassifier =
weka.classifiers.AbstractClassifier.forName("weka.classifiers.functions.Dl4jMlpClassifier",
filterOptions);
-----------------------------------------------------------
But it is giving me this run-time error:
and it is pointing to this line:
weka.core.WekaPackageManager.loadPackages(true);
-----------------------------------------------------------
Registering weka.classifiers.meta.ensembleSelection.EnsembleSelectionLibrary
weka.gui.EnsembleSelectionLibraryEditor
Registering weka.classifiers.functions.loss.LossFunction
weka.gui.GenericObjectEditor
Registering weka.classifiers.functions.activation.ActivationFunction
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.multisearch.AbstractSearch
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.multisearch.AbstractSearch[]
weka.gui.GenericArrayEditor
Registering weka.core.setupgenerator.AbstractParameter
weka.gui.GenericObjectEditor
Registering weka.core.setupgenerator.AbstractParameter[]
weka.gui.GenericArrayEditor
Registering weka.classifiers.meta.generators.NominalAttributeGenerator
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.generators.NumericAttributeGenerator
weka.gui.GenericObjectEditor
Registering
weka.attributeSelection.ssf.distanceFunctions.DistanceFunctionForSSF
weka.gui.GenericObjectEditor
Registering
weka.attributeSelection.ssf.validationCriteria.ValidationCriteria
weka.gui.GenericObjectEditor
Registering weka.dl4j.iterators.instance.ImageInstanceIterator
weka.gui.GenericObjectEditor
Exception in thread "main" java.lang.NoClassDefFoundError:
org/datavec/api/io/labels/PathLabelGenerator
        java.lang.Class.forName0(Native Method)
        java.lang.Class.forName(Class.java:348)

weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:198)

weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:178)
        weka.gui.GenericObjectEditor.registerEditor(GenericObjectEditor.java:1131)

weka.core.WekaPackageManager.processGUIEditorsProps(WekaPackageManager.java:728)

weka.core.WekaPackageManager.processPackageDirectory(WekaPackageManager.java:802)
        weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1397)
        weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1305)
        javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:35)
        javaapplication1.JavaApplication1.main(JavaApplication1.java:101)

        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at
weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:198)
        at
weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:178)
        at
weka.gui.GenericObjectEditor.registerEditor(GenericObjectEditor.java:1131)
        at
weka.core.WekaPackageManager.processGUIEditorsProps(WekaPackageManager.java:728)
        at
weka.core.WekaPackageManager.processPackageDirectory(WekaPackageManager.java:802)
        at weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1397)
        at weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1305)
        at
javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:35)
        at javaapplication1.JavaApplication1.main(JavaApplication1.java:101)
Caused by: java.lang.ClassNotFoundException:
org.datavec.api.io.labels.PathLabelGenerator
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 11 more
C:\Users\Malak\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1
---------------------------------------------------------------------------------------------------------------------
So, what do you think the problem this time is please?
Thank you,

Tarfa



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Dl4jMlpClassifier in java code

Tarfa
In reply to this post by Eibe Frank-2
Thank you Eibe,
I modified the code in this way:
----------------------------------------------------------
 weka.core.WekaPackageManager.loadPackages(true);
            data.setClassIndex(data.numAttributes()-1);
String[] filterOptions = weka.core.Utils.splitOptions("-iterator
\".ImageInstanceIterator -imagesLocation
/Users/Malak/wekafiles/packages/wekaDeeplearning4j/datasets/nominal/mnist-minimal
"
        + "-bs 12\" -poolingType AVG -layer-extract \".DenseLayer -name
res4a_branch2b\" -layer-extract \".DenseLayer -name flatten_1\" "
        + "-isZoo true -zooModel \".Dl4JResNet50\"");

weka.classifiers.Classifier myclassifier =
weka.classifiers.AbstractClassifier.forName("weka.classifiers.functions.Dl4jMlpClassifier",
filterOptions);
-----------------------------------------------------------
But it is giving me this run-time error:
and it is pointing to this line:
weka.core.WekaPackageManager.loadPackages(true);
-----------------------------------------------------------
Registering weka.classifiers.meta.ensembleSelection.EnsembleSelectionLibrary
weka.gui.EnsembleSelectionLibraryEditor
Registering weka.classifiers.functions.loss.LossFunction
weka.gui.GenericObjectEditor
Registering weka.classifiers.functions.activation.ActivationFunction
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.multisearch.AbstractSearch
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.multisearch.AbstractSearch[]
weka.gui.GenericArrayEditor
Registering weka.core.setupgenerator.AbstractParameter
weka.gui.GenericObjectEditor
Registering weka.core.setupgenerator.AbstractParameter[]
weka.gui.GenericArrayEditor
Registering weka.classifiers.meta.generators.NominalAttributeGenerator
weka.gui.GenericObjectEditor
Registering weka.classifiers.meta.generators.NumericAttributeGenerator
weka.gui.GenericObjectEditor
Registering
weka.attributeSelection.ssf.distanceFunctions.DistanceFunctionForSSF
weka.gui.GenericObjectEditor
Registering
weka.attributeSelection.ssf.validationCriteria.ValidationCriteria
weka.gui.GenericObjectEditor
Registering weka.dl4j.iterators.instance.ImageInstanceIterator
weka.gui.GenericObjectEditor
Exception in thread "main" java.lang.NoClassDefFoundError:
org/datavec/api/io/labels/PathLabelGenerator
        java.lang.Class.forName0(Native Method)
        java.lang.Class.forName(Class.java:348)

weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:198)

weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:178)
        weka.gui.GenericObjectEditor.registerEditor(GenericObjectEditor.java:1131)

weka.core.WekaPackageManager.processGUIEditorsProps(WekaPackageManager.java:728)

weka.core.WekaPackageManager.processPackageDirectory(WekaPackageManager.java:802)
        weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1397)
        weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1305)
        javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:35)
        javaapplication1.JavaApplication1.main(JavaApplication1.java:101)

        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at
weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:198)
        at
weka.core.WekaPackageClassLoaderManager.forName(WekaPackageClassLoaderManager.java:178)
        at
weka.gui.GenericObjectEditor.registerEditor(GenericObjectEditor.java:1131)
        at
weka.core.WekaPackageManager.processGUIEditorsProps(WekaPackageManager.java:728)
        at
weka.core.WekaPackageManager.processPackageDirectory(WekaPackageManager.java:802)
        at weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1397)
        at weka.core.WekaPackageManager.loadPackages(WekaPackageManager.java:1305)
        at
javaapplication1.JavaApplication1.Deep_learning(JavaApplication1.java:35)
        at javaapplication1.JavaApplication1.main(JavaApplication1.java:101)
Caused by: java.lang.ClassNotFoundException:
org.datavec.api.io.labels.PathLabelGenerator
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 11 more
C:\Users\Malak\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1
---------------------------------------------------------------------------------------------------------------------
So, what do you think the problem this time is please?
Thank you,

Tarfa



--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html