Java Code Examples for org.neuroph.core.NeuralNetwork#load()
The following examples show how to use
org.neuroph.core.NeuralNetwork#load() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerceptronSample.java From NeurophFramework with Apache License 2.0 | 6 votes |
/** * Runs this sample */ public static void main(String args[]) { // create training set (logical AND function) DataSet trainingSet = new DataSet(2, 1); trainingSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0})); trainingSet.add(new DataSetRow(new double[]{0, 1}, new double[]{0})); trainingSet.add(new DataSetRow(new double[]{1, 0}, new double[]{0})); trainingSet.add(new DataSetRow(new double[]{1, 1}, new double[]{1})); // create perceptron neural network NeuralNetwork myPerceptron = new Perceptron(2, 1); // learn the training set myPerceptron.learn(trainingSet); // test perceptron System.out.println("Testing trained perceptron"); testNeuralNetwork(myPerceptron, trainingSet); // save trained perceptron myPerceptron.save("mySamplePerceptron.nnet"); // load saved neural network NeuralNetwork loadedPerceptron = NeuralNetwork.load("mySamplePerceptron.nnet"); // test loaded neural network System.out.println("Testing loaded perceptron"); testNeuralNetwork(loadedPerceptron, trainingSet); }
Example 2
Source File: SingleImageAnalyzerController.java From FakeImageDetection with GNU General Public License v3.0 | 6 votes |
@FXML private void startCheck(ActionEvent event) throws IOException { if (nnetSrc == null || imgSrc == null) { Calert.showAlert("Invalid Data", "Select Required Files", Alert.AlertType.ERROR); return; } try { nnet = NeuralNetwork.load(new FileInputStream(nnetSrc)); // load trained neural network saved with Neuroph Studio System.out.println("Learning Rule = " + nnet.getLearningRule()); ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the HashMap<String, Double> output = imageRecognition.recognizeImage(ImageIO.read(imgSrc)); if (output == null) { System.err.println("Image Recognition Failed"); } double real = output.get("real"); double fake = output.get("faked"); System.out.println(output.toString()); Calert.showAlert("Result", "Real = " + real + "\nFake = " + fake, Alert.AlertType.INFORMATION); } catch (FileNotFoundException ex) { Logger.getLogger(SingleImageAnalyzerController.class.getName()).log(Level.SEVERE, null, ex); } }
Example 3
Source File: NeuralNetProcessor.java From FakeImageDetection with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { try { System.out.println("usage java -jar nn.jar image_to_be_processed file_of_neural_network"); System.out.println("Loading Image...."); image = ImageIO.read(new File(args[0])); System.out.println("Loading NN...."); File NNetwork = new File(args[1]); if (!NNetwork.exists()) { System.err.println("Cant Find NN"); return; } nnet = NeuralNetwork.load(new FileInputStream(NNetwork)); // load trained neural network saved with Neuroph Studio System.out.println("Load Image Recog Plugin...."); imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network System.out.println("Recognize Image...."); HashMap<String, Double> output = imageRecognition.recognizeImage(image); System.out.println("Output is...."); System.out.println(output.toString()); } catch (IOException ex) { Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null, ex); } }
Example 4
Source File: OcrSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
public static void main(String[]args) { NeuralNetwork nnet = NeuralNetwork.load("C:\\Users\\zoran\\Desktop\\nn.nnet"); OcrPlugin ocrPlugin = (OcrPlugin) nnet.getPlugin(OcrPlugin.class); // load letter images Image charImage = ImageFactory.getImage("C:\\Users\\zoran\\Desktop\\Letters\\A.png"); Character ch = ocrPlugin.recognizeCharacter(charImage); System.out.println(ch); }
Example 5
Source File: MetricTestMNIST.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * @param args command line arguments which represent paths to persisted neural network * [0] - location of neural network */ public static void main(String[] args) throws IOException { DataSet testSet = MNISTDataSet.createFromFile(MNISTDataSet.TEST_LABEL_NAME, MNISTDataSet.TEST_IMAGE_NAME, 10000); NeuralNetwork nn = NeuralNetwork.load(new FileInputStream(args[0])); Evaluation.runFullEvaluation(nn, testSet); }
Example 6
Source File: NeuralNetProcessor.java From FakeImageDetection with GNU General Public License v3.0 | 5 votes |
@Override public void doRun() { try { //Bypass network reload during comeback through home button if (nnet == null) { File NNetwork = new File(ConstantObjects.neuralNetworkPath); System.out.println("Nueral network loaded = " + NNetwork.getAbsolutePath()); if (!NNetwork.exists()) { notifyUser(); return; } nnet = NeuralNetwork.load(new FileInputStream(NNetwork)); // load trained neural network saved with Neuroph Studio System.out.println("Learning Rule = " + nnet.getLearningRule()); imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network } HashMap<String, Double> output = imageRecognition.recognizeImage(image); if (output == null) { System.err.println("Image Recognition Failed"); } System.out.println(output.toString()); listener.neuralnetProcessCompleted(output); } catch (Exception ex) { Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null, ex); listener.neuralnetProcessCompleted(null); } }
Example 7
Source File: BatchImageTrainer.java From FakeImageDetection with GNU General Public License v3.0 | 5 votes |
@Override public void doRun() { try { System.out.println("Starting training thread....." + sampleDimension.toString() + " and " + imageLabels.toString()); HashMap<String, BufferedImage> imagesMap = new HashMap<String, BufferedImage>(); for (File file : srcDirectory.listFiles()) { imageLabels.add(FilenameUtils.removeExtension(file.getName())); if (sampleDimension.getWidth() > 0 && sampleDimension.getHeight() > 0) { Double w = sampleDimension.getWidth(); Double h = sampleDimension.getHeight(); imagesMap.put(file.getName(), ImageUtilities.resizeImage(ImageUtilities.loadImage(file), w.intValue(), h.intValue())); } } Map<String, FractionRgbData> imageRgbData = ImageUtilities.getFractionRgbDataForImages(imagesMap); DataSet learningData = ImageRecognitionHelper.createRGBTrainingSet(imageLabels, imageRgbData); nnet = NeuralNetwork.load(new FileInputStream(nnFile)); //Load NNetwork MomentumBackpropagation mBackpropagation = (MomentumBackpropagation) nnet.getLearningRule(); mBackpropagation.setLearningRate(learningRate); mBackpropagation.setMaxError(maxError); mBackpropagation.setMomentum(momentum); System.out.println("Network Information\nLabel = " + nnet.getLabel() + "\n Input Neurons = " + nnet.getInputsCount() + "\n Number of layers = " + nnet.getLayersCount() ); mBackpropagation.addListener(this); System.out.println("Starting training......"); nnet.learn(learningData, mBackpropagation); //Training Completed listener.batchImageTrainingCompleted(); } catch (FileNotFoundException ex) { System.out.println(ex.getMessage() + "\n" + ex.getLocalizedMessage()); } }
Example 8
Source File: FIDNetworkAnalyser.java From FakeImageDetection with GNU General Public License v3.0 | 4 votes |
public FIDNetworkAnalyser(String nSourceFile) throws FileNotFoundException { nnet = NeuralNetwork.load(new FileInputStream(nSourceFile)); // load trained neural network saved with Neuroph Studio }
Example 9
Source File: McNemarTestMNIST.java From NeurophFramework with Apache License 2.0 | 3 votes |
/** * @param args command line arguments which represent paths to persisted neural networks * [0] - location of first neural network * [1] - location of second neural network */ public static void main(String[] args) throws IOException { DataSet testSet = MNISTDataSet.createFromFile(MNISTDataSet.TEST_LABEL_NAME, MNISTDataSet.TEST_IMAGE_NAME, 10000); NeuralNetwork nn1 = NeuralNetwork.load(new FileInputStream(args[0])); NeuralNetwork nn2 = NeuralNetwork.load(new FileInputStream(args[1])); new McNemarTest().evaluateNetworks(nn1, nn2, testSet); }