jeffheaton / encog-java-core

http://www.heatonresearch.com/encog
Other
744 stars 268 forks source link

org.encog.examples.neural.image.ImageNeuralNetwork doesen't work #207

Open GeneaF opened 9 years ago

GeneaF commented 9 years ago

The problem is in the SimpleIntensityDownsample class.

I modified TestImageDataSet test class I see (afther downsampling) the same result for different images also with non changes in image resolution (please sees the example below).

My TestImageDataSet is the following:

public void testImageDataSet() {
    try {
        ///////////////////////////////////////////////////////////////
        JFrame frame1 = new JFrame();
        frame1.setVisible(true);

        Image image1 = frame1.createImage(100, 100);
        Graphics g1 = image1.getGraphics();
        g1.setColor(Color.BLACK);
        g1.fillRect(0, 0, 100, 100);
        g1.setColor(Color.WHITE);
        g1.fillRect(0, 0, 50, 50);
        g1.dispose();

        ///////////////////////////////////////////////////////////////
        JFrame frame2 = new JFrame();
        frame2.setVisible(true);

        Image image2 = frame2.createImage(100, 100);
        Graphics g2 = image2.getGraphics();
        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, 100, 100);
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, 25, 25);
        g2.dispose();

        ///////////////////////////////////////////////////////////////
        JFrame frame3 = new JFrame();
        frame3.setVisible(true);

        Image image3 = frame3.createImage(100, 100);
        Graphics g3 = image3.getGraphics();
        g3.setColor(Color.BLACK);
        g3.fillRect(0, 0, 100, 100);
        g3.setColor(Color.WHITE);
        g3.fillRect(0, 0, 75, 75);
        g3.dispose();

        //////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Downsample downsample = new SimpleIntensityDownsample();
        ImageMLDataSet set = new ImageMLDataSet(downsample, true, -1, 1);

        BasicMLData ideal1 = new BasicMLData(1);
        ImageMLData input1 = new ImageMLData(image1);
        set.add(input1, ideal1);

        BasicMLData ideal2 = new BasicMLData(2);
        ImageMLData input2 = new ImageMLData(image2);
        set.add(input2, ideal2);

        BasicMLData ideal3 = new BasicMLData(3);
        ImageMLData input3 = new ImageMLData(image3);
        set.add(input3, ideal3);

        set.downsample(100, 100);

        for (int t1 = 0; t1 < set.size(); t1++) {
            System.out.println("t1  " + t1);
            MLDataPair ot1 = set.get(t1);
            for (int t2 = t1 + 1; t2 < set.size(); t2++) {
                MLDataPair ot2 = set.get(t2);
                int hd = 0;
                for (int i = 0; i < ot1.getInput().size(); i++) {
                    if (ot1.getInput().getData(i) != ot2.getInput().getData(i)) {
                        hd++;
                    }
                }
                System.out.println(":" + ot1.getInput().size() + ":HD(" + t1 + "," + t2 + ")=" + hd);
            }
        }

        //Assert.assertEquals(d[0],-1.0, 0.1);
        //Assert.assertEquals(d[5],1, 0.1);
        // just "flex" these for no exceptions
        input1.toString();
        input1.setImage(input1.getImage());
    } catch (HeadlessException ex) {
        // ignore if we are running headless (i.e. the build server)
    }
}

Regards Fabio