void openDatabase(){ pixelData.clear(); for (int i = 0; i < total-1; i++){ lines = loadStrings("database/"+(i)+".txt"); lineCount = i; // println("there are " + lines.length + " lines"); // println(i); float[] vectorArray = new float[lines.length]; for (int j=0; j < lines.length; j++) { String[] splitLines = splitTokens(lines[j]); String f = splitLines[1]; float k = Float.valueOf(f).floatValue(); lineString[j] = k; binaryPixels[j] = k; vectorArray[j] = k; //pixelData.add(binaryPixels[i]); //println(binaryPixels[i]); // println(vectorArray[j]); } pixelData.add(vectorArray); } } void welcome() { textFont(f); textAlign(CENTER); fill(0); text("This is a gesture recognation demo. \n" + "You can record gestures or. \n" + "you can make a gesture and see its name.",width/2,height/2); recordButton.render(); recordButton.rollover(mouseX,mouseY); guessButton.render(); guessButton.rollover(mouseX,mouseY); } // Train the network void train() { openDatabase(); // Adjust this number to make training appear to be faster / slower int cyclesPerFrame = 50; for (int i = 0; i < cyclesPerFrame; i++) { // Pick a number int num = (int) random(total); // Look at the pixels for that number //////////////////////////////////////////////////////////////////////////////////////////////// //// this needs to change with "look in to vector document" //println(lineCount); float[] pixies = binaryPixels; // Train the network according to those pixels nn.train(pixies, (float)num/total); // Increase the training iteration count trainingCount++; //println(trainingCount); } } // Display info about the training void showTraining() { pushMatrix(); translate(20,150); textFont(f); textAlign(LEFT); // How much training is complete float percentage = (float) trainingCount / maxTrainingIterations; // Draw status bar float statusBar = percentage*width/2; stroke(0); noFill(); rect(5,5,width/2,10); fill(0); rect(5,5,statusBar,10); text("Training. . .",5,30); // Now we'll show what the network is currently guessing for each input image fill(0); float mse = 0; for (int i = 0; i < pixelData.size(); i++) { // println((Float) pixelData.get(14)); float[] inp = (float[]) pixelData.get(i); float known = (float) i/total; float result = nn.feedForward(inp); text("My guess for image # " + i + " is " + nf((float)result * total,1,2),5,100+i*20); mse += (result - known)*(result - known); } // How many interations text("Total iterations: " + trainingCount,5,60); // Root mean squarted error // println(pixelData.size()); float rmse = sqrt(mse/pixelData.size()); text("Root mean squared error: " + nf(rmse,1,4), 5,80); // If we've finished training if (percentage >= 1.0) { trainingComplete = true; text("I'm done training! Press the space bar\nto draw a shape for me to guess.",5,-50); } popMatrix(); } // What to do with the user's input image void guess() { // If it's not time to guess yet just give the user some instructions // and show submit button if (!guessing) { textFont(f); fill(50); textAlign(CENTER); text("Draw something and submit!",width/2,20); // submit.rollover(mouseX,mouseY); // submit.render(); // Otherwise, show the result of the guess! } else { //noStroke(); //fill(255); // rect(0,400,width,height); //fill(0); //textAlign(CENTER); //textSize(14); // println((int)(round(guess))); text("My output is " + nf(guess,1,2) + " so I guess " + (int)(round(guess)) + "\n Please type the correct # to help train me.",460,420); //println( (int)(round(guess))); } } // Get an array of floats 0 to 1 from an input image //////////////////////////////////////////////////////////////////////////////////////////////// //////// this should be change for vector file ///////// guessing is accordin to file number. but it is working now, // next: make training work, interface, get more then one input, get input name, match the guessing number(file name) with the input