Obtianing output of NeurophStudio - import error (java) - java

I am trying to abtain the output (for example: cat: 0,988; dog: 0.012) from NeurophStudio using java. The neural net recognises the images well. I found the code below. I get errors in the first two import lines. Does anyone know where I can find/download these packages? I searched through all my directories already and didn't find it.
import org.neuroph.core.NeuralNetwork; // ! error
import org.neuroph.contrib.imgrec.ImageRecognitionPlugin; // ! error
import java.util.HashMap;
import java.io.File;
import java.io.IOException;
public class ImageRecognitionSample {
public static void main(String[] args) {
// load trained neural network saved with Neuroph Studio (specify some existing neural network file here)
NeuralNetwork nnet = NeuralNetwork.load("Neural Networks/Iconnet25-8.nnet"); // load trained neural network saved with Neuroph Studio
// get the image recognition plugin from neural network
ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network
try {
// image recognition is done here (specify some existing image file)
HashMap<String, Double> output = imageRecognition.recognizeImage(new File("testimage.png"));
System.out.println(output.toString());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
source : http://neuroph.sourceforge.net/image_recognition.html
I found the package code here : https://github.com/neuroph/neuroph/tree/master/neuroph-2.9/Core/src/main/java/org/neuroph/core
Problem: this is not downloadable and I will probably need multiple files/entire package.
Does anyone have experience with this? Any solutions?

download neuroph.jar
then locate it to your project
like this
right click on your project
properties
Libraries
add jar/folder
then show the path where you put the neuroph.jar
hope it will help you!!!!

Related

IBM Watson Visual Recognition in Java training classifier error

So I want to make a java application in eclipse which the user i will be able to import .zip files. Each .zip file will represent a cat breed. I will click on a "train" button and my program will contact IBM Watson services and create a classifier. Then from a different window, i will import random cat images and the program will show what cat breed is in the image. Everything with the SDKs is fine since I ran some examples from the official Watson site and everything ran smoothly. Problem comes when I try to create my own classifiers. The code you are about to see is also from their site. For some reason the createClassifier method won't take the CreateClassifierOptions object as an argument.
import java.io.File;
import com.ibm.watson.developer_cloud.http.ServiceCall;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionCallback;
import com.ibm.watson.developer_cloud.visual_recognition.v3.*;
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.*;
public class TrainningClassifier{
public static void main(String[] args) {
VisualRecognition service = new VisualRecognition(
VisualRecognition.VERSION_DATE_2016_05_20
);
service.setApiKey("aca4433597018de62edafdeebceb2bdc1482496a");
CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder()
.name("dogs")
.addClass("beagle", new File("./beagle.zip"))
.addClass("goldenretriever",new File("./golden-retriever.zip"))
.addClass("husky", new File("./husky.zip"))
.negativeExamples(new File("./cats.zip"))
.build();
Classifier dogs = service.createClassifier(createClassifierOptions).execute();
System.out.println(dogs); /*error is in the above line.
the createClassifier method.*/
}
}
Error: Exception in thread "main" java.lang.Error: Unresolved
compilation problem: The method createClassifier(ClassifierOptions)
in the type VisualRecognition is not applicable for the arguments
(CreateClassifierOptions)
at testVisualRec.ForAssignment.main(ForAssignment.java:31)
Any ideas?
Found the solution. For some reason eclipse wouldn't recommend this solution I had to experiment. I just added throws IOException in main method. I also put inside the main method System.out.println(new File(".").getAbsoluteFile()); to make sure the path was correct, and it was. (SDK used for this project is 4.0.0, not the newest one. SDK found here: https://github.com/watson-developer-cloud/java-sdk/releases)

WEKA API LibSVM ClassPath not found

I'm trying to use LibSVM with Weka API.
My System:
Win7
Weka 3.7.12
LibSVM 1.0.6 (Installed via Package Manager)
My Code:
import java.io.File;
import java.util.Random;
import javax.swing.JOptionPane;
import weka.classifiers.Evaluation;
import weka.classifiers.functions.LibSVM;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
public class LibSVMClassifier {
// Method to build a SVM classifier with a given data file
public static double buildModel(File dataSet){
// new instance of LibSVM
LibSVM clsSVM = new LibSVM();
try {
Instances data = DataSource.read(dataSet.getAbsolutePath());
// Sets the label feature
data.setClassIndex(data.numAttributes()-1);
String opts = "-S 0 -K 0 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 40.0 -C 1.0 -E 0.0010 -P 0.1";
// set the options for the algorithm
clsSVM.setOptions(weka.core.Utils.splitOptions(opts));
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(clsSVM, data, 2, new Random(1));
return eval.pctIncorrect();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
}
return 100;
}
}
Code is called from here:
double error = LibSVMClassifier.buildModel(trainDataSet);
My problem:
When I run my code and first use my J48 classifier (code at the end) and afterwards the LibSVM everything works fine.
If I run the LibSVM first I get the following error:
java.lang.Exception: libsvm classes not in CLASSPATH!
weka.classifiers.functions.LibSVM.buildClassifier(LibSVM.java:1636)
weka.classifiers.evaluation.Evaluation.crossValidateModel(Evaluation.java:764)
weka.classifiers.Evaluation.crossValidateModel(Evaluation.java:374)
totd.BuildModel.LibSVMClassifier.buildModel(LibSVMClassifier.java:34)
totd.GUI.Gui$5.actionPerformed(Gui.java:215)
If I export the project to a runable jar and use it on another machine without weka installed the error will also occur if I run the J48 algorithm first. So no matter what I can't use the LibSVM on another machine.
I have read through all the other questions regarding this problem, but there was no solution for me. In order to prevent answers that will not help me here some things that wont work:
Explanation how to add a library to the project: Ive used the package
manager from weka to install LibSVM and I added the resulting jar
file for LIBSVM AS WELL AS weka jar file to my build path
Explanation how to use LibSVM with weka gui: I want to use LibSVM together with the weka api in a programmatic way, it already works in weka gui I dont need that!!!
Explanation how to change the classpath for your system: I want to export my project to a jar file and run it on any system I dont have access to the system class path
Possible solutions that I didnt understand but that I think might work if someone explains in detail:
https://stackoverflow.com/a/13766120/5006670 In this post it is mentioned to obtain the .class files from SVNLib (I suppose SVM?) and adding these to my buildpath. I do not understand which files he is speaking about and how I would compile the make file if I were to find it. But it sounds like my error message.
https://weka.wikispaces.com/LibSVM talks about using reflection. Im not sure how this is used
using a batch file to start the jar file together with the LibSVM.jar with -classpath command
J48 Code:
import java.io.File;
import javax.swing.JOptionPane;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.trees.J48;
import weka.classifiers.Evaluation;
import java.util.Random;
public class J48Classifier {
// Method to build a J48 classifier with a given data file
public static double buildModel(File dataSet){
// new instance of tree
J48 clsJ48 = new J48();
try {
Instances data = DataSource.read(dataSet.getAbsolutePath());
// Sets the label feature
data.setClassIndex(data.numAttributes()-1);
String[] options = new String[1];
// unpruned tree
options[0] = "-U";
// set the options for the algorithm
clsJ48.setOptions(options);
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(clsJ48, data, 2, new Random(1));
return eval.pctIncorrect();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
}
return 100;
}
}
My build path
Okay, steps how magic work:
Search for hours and fail
Ask on a forum
Try for 5 more minutes and succeed
SOLUTION:
There are 2! LibSVM.jar files in the weka package folder and you need BOTH.
So for all that try to use LibSVM using weka package manager go to:
(HOME)\wekafiles\packages\LibSVM
There you find the first FIRST LibSVM.jar
now go to:
(HOME)\wekafiles\packages\LibSVM\lib
here you will find libsvm.jar
ADD BOTH OF THESE JAR TO YOUR BUILD PATH!!!
Greetings

How can I add java client library in java on netbeans?

Hello i read that I have to use the java client library in java to get the revisions list in google drive using google api. I use netbeans. I search for this question and I try to add the bib but i haven't get success. To download the library i visited this link and downloaded the "latest". but after add the jar files I get the message error that the package doesnt exist. Please someone help me!
Yes! I try this but it show the same erros. I add the lib but netbeans (8) show the error in the three lines code: "package [name] doesn't exist".
The three lines are these:
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
obs: the full code, taken in the google developers site is:
package javaapplication8;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
import java.io.IOException;
import java.util.List;
public class MyClass {
private static List<Revision> retrieveRevisions(Drive service,
String fileId) {
fileId = "1XpNdeTFBr2KygyfPtlowBvkpcaJJzjgLckrGjp5oOhg0";
try {
RevisionList revisions = service.revisions().list(fileId).execute();
return revisions.getItems();
} catch (IOException e) {
System.out.println("An error occurred: " + e);
}
return null;
}
}
If it is the error like package is missing, please check whether you have created a folder named com in your project or not. Also, every dot (.) indicates the levels of packages that you use in your project. Please check that com folder followed by the other folder names after every dot are present or not. I think this might help you. I answered your question based on my understanding (i.e, package issue which will be resolved by creating folders in your project. folders means packages). I am sorry if I gave you the wrong answer.

how to attach my mp3 file with generated jar file?

in this code i select mp3 path is "D:/camera.wav". when i make jar file of this code, it play in only my system. please tell me how to add camera.wav file to my project and give that url to my project. because i want same music should play for all systems, even though they don't have that music.
import java.io.File;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;
public class maintest
{
public static void main(String[] args)
{
//float v=1;
Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
Format input2 = new AudioFormat(AudioFormat.MPEG);
Format output = new AudioFormat(AudioFormat.LINEAR);
PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder",
new Format[]{input1, input2},
new Format[]{output},
PlugInManager.CODEC );
try
{
Player player = Manager.createPlayer(new MediaLocator(new File("D:/camera.wav").toURI().toURL()));
//player.getGainControl().setLevel(v);
player.start();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
JMF is .. ancient. it hasn't been maintained/updated for years, so especially if you want to have some "modern" code, JMF is not the best option.
personally, I once created (al be it a simple one) a small mp3 player, using the JLayer library which you can find here
it has plenty of documentation and examples so it shouldn't take too long to get you going.
You need the MP3 Plugin. Or if that doesn't work, this plugin is also a good resource.
You can also use JavaFX for playing MP3's. If you use Netbeans just create a new project and select JavaFX project instaed of a normal Java project

OpenCV + Java = UnsatisfiedLinkError

I need capture a video stream from my USB webcam, for this i use Opencv 2.4.6 for developing in Java. I follow the steps listed in here
I add the "C:\opencv\build\java\x64" dir to my System PATH and include the "opencv-246.jar" file into my libraries on ECLIPSE. When y run the explame
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
i get
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
OK =)
but when i run
import org.opencv.highgui.VideoCapture;
public class Main {
public static void main(String[] args) {
VideoCapture vc = new VideoCapture(0);
if(vc.isOpened()){
System.out.println("Works!");
}
}
}
i get
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.VideoCapture.n_VideoCapture(I)J
at org.opencv.highgui.VideoCapture.n_VideoCapture(Native Method)
at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:113)
at Main.main(Main.java:5)
i add all the routes containes in:
C:\opencv\build\x64\vc10
one by one,but doesn`t work.
Finally i create a variable called OPENCV_DIR with C:\opencv\build\x64\vc10 but still getting UnsatisfiedLinkError.
PLEASE HELP ME!
in your second example , you skipped this line
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
so the opencv libs werent loaded, UnsatisfiedLinkError, etc...
[edit]:
thanks to #Jishnu Prathap for highlighting the java.library path issue, if you run into problems setting that, you can still try to use an absolute path to the java wrapper so/dll/dylib like:
System.load("/path to/our/java_wrapper");
I had a similar error while using OpenCV with java.I did 2 things to resolve it.
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
I added the path to OpenCV dll or .so to javalibpath or path. which actually didnt work for some reason and i ended up putting the OpenCV dll in the system32 folder.
Try the below code
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import nu.pattern.OpenCV;
public class OpencvMain
{
public static void main( String[] args )
{
OpenCV.loadLocally();
Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
System.out.println( "mat = " + mat.dump() );
}
}
For general users using opencv3.x:
HighGUI module does not exist anymore in Java for opencv 3.0 and above.
import org.opencv.videoio.VideoCapture;
instead of
import org.opencv.highgui.VideoCapture;
videoio includes VideoCapture, VideoWriter.
Similarly:
imgcodecs includes imread/imwrite and friends
Example:
Highgui.imread(fileName)
-->
Imgcodecs.imread(fileName)
So, I was having this problem too and I did what you all suggested, it worked fine in my x64 windows, but in a x86 couldn't make it work.
At last I found a solution by changing:
VideoCapture capture = new VideoCapture(0);
for
VideoCapture capture = new VideoCapture();
capture.open("resources/vid.MP4");
I don't know why this worked but I hope it may help somebody with my same problem.
I tried a lot of tutorials online for the resolution, only one of them have helped me.
There are two steps that are different in this method,
Firstly, while importing the java project from Opencv SDK into the Android studio, make sure to uncheck all the checkboxes presented in the import dialog.
Secondly, make sure you import the OpenCV.mk file that is in the native/jdk of the SDK..
The System.loadLibrary() seems to return true after this, which was a huge relief for me as it took me several hours to figure this out
Here's the link to the tutorial that helped me
https://medium.com/#rdeep/android-opencv-integration-without-opencv-manager-c259ef14e73b

Categories

Resources