import java.io.FileNotFoundException; import java.util.ArrayList; /** * Course material for the "Konenako 2010" course. */ /** Computes a sum of all pixels in a grayscale image. */ class BlackAreaExtractor extends AbstractDumbGrayscaleFeatureExtractor{ public BlackAreaExtractor(int height, int width) { super(height,width); } @Override double[] extractFromGrayscale(double[][] image) { double[] sumFeature = new double[1]; for(int row=0;row extractors = new ArrayList(); /* Here you add instances of your feature extractors: */ extractors.add(new BlackAreaExtractor(28,28)); // extractors.add(new NumberOfColorChangeExtractor(28,28)); // extractors.add(new CoarseResampleExtractor(28,28)); /* And here they are applied to each of the MNIST digit images: */ DataSet mnist = mnistRaw.createNewByFeatureExtractors(extractors); // In our reduced set, we took 750/250 first samples from the real MNIST mnist.splitToTrainAndTest(.75); mnist.normalize(-1.0,1.0); int[] layerSizes = new int[]{mnist.getVecSize(),10,mnist.getNumOfClasses()}; SimpleMLP mlp = new SimpleMLP(layerSizes); for(int i=0;i<100;i++){ mlp.trainGD(mnist.trainInputs(), mnist.trainTargets(), 0.1, 200); System.out.println("Training set:"); int[] outclasses = mlp.classifyMatrix(mnist.trainInputs()); DataSet.printConfusion(outclasses,mnist.trainTargets()); System.out.println("Test set:"); outclasses = mlp.classifyMatrix(mnist.testInputs()); DataSet.printConfusion(outclasses,mnist.testTargets()); } } }