You are here

Image Recongination

Hello,

i am creating application where user loads image do some training on it that add some noise over that image after user can recall the original image. i have seen image example given by seema and i am following the same example but hen i tried to run my program it is giving me nullpointerexception.

here is my code :

// for creating image on jpanel

public void setImage(File imageFile) throws IOException {
this.imageFile = imageFile;
image = getToolkit().getImage("Image Files//" + imageFile.getName());
createNetwork();
repaint();
}

//createNetwork()

public void createNetwork() throws IOException{
downsampleWidth = 16;
downsampleHeight = 16;
downsample = new RGBDownsample();
training = new ImageMLDataSet(downsample, false, 1, -1);
System.out.println("traning is created");
processNetwork();
}

//for process network()


public void processNetwork() throws IOException{
System.out.println("Downsampling images...");
final MLData ideal = new BasicMLData(0);
final Image img = ImageIO.read(this.imageFile);
final ImageMLData data = new ImageMLData(img);
this.training.add(data, ideal);
this.training.downsample(this.downsampleHeight, this.downsampleWidth);
this.network = EncogUtility.simpleFeedForward(
this.training.getInputSize(), 100, 0,
this.training.getIdealSize(), true);
System.out.println("Created network: " + this.network.toString());
}


public void processTrain() throws IOException {
String strMode = "x";
System.out.println("Training Beginning... Output patterns = " + 0);
final ResilientPropagation train = new ResilientPropagation(this.network, this.training);
train.addStrategy(new ResetStrategy(0.25, 50 ));
if (strMode.equalsIgnoreCase("gui")) {
TrainingDialog.trainDialog(train, this.network, this.training);
} else {
EncogUtility.trainConsole(train, this.network, this.training, 1);
}
System.out.println("Training Stopped...");
}

here is printstacktrace:


traning is created
Downsampling images...
Created network: [BasicNetwork: Layers=3]
Added input image:1001_941581367_375330851_H080042_L.jpg
Training Beginning... Output patterns = 0
Beginning training...
Exception in thread "AWT-EventQueue-0" org.encog.EncogError: java.lang.NullPointerException
at org.encog.neural.networks.training.propagation.Propagation.iteration(Propagation.java:227)
at org.encog.neural.networks.training.propagation.Propagation.iteration(Propagation.java:178)
at org.encog.util.simple.EncogUtility.trainConsole(EncogUtility.java:234)
at org.beproject.neuralnetwork.input.IOImage.processTrain(IOImage.java:127)
at org.beproject.neuralnetwork.ui.ApplicationGraphicalInterface$17.actionPerformed(ApplicationGraphicalInterface.java:377)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.NullPointerException
at org.encog.mathutil.error.ErrorCalculation.updateError(ErrorCalculation.java:183)
at org.encog.neural.networks.training.propagation.GradientWorker.process(GradientWorker.java:205)
at org.encog.neural.networks.training.propagation.GradientWorker.run(GradientWorker.java:266)
at org.encog.neural.networks.training.propagation.Propagation.calculateGradients(Propagation.java:302)
at org.encog.neural.networks.training.propagation.Propagation.iteration(Propagation.java:206)
... 29 more

i am using exactly same code with by requirement. please help out

thanks

Neural Network Forums: 

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer