[33097] | 1 | import java.io.File;
|
---|
| 2 | import java.io.BufferedReader;
|
---|
| 3 | import java.io.BufferedWriter;
|
---|
| 4 | import java.io.FileReader;
|
---|
| 5 | import java.io.FileWriter;
|
---|
| 6 | public class javaAccuracyCalculator{
|
---|
[33141] | 7 |
|
---|
| 8 | //Read in log.txt, grab first item in array of each line
|
---|
| 9 | //Counter for everytime have readline
|
---|
| 10 | //Calculate accuracy rate
|
---|
| 11 | public static void main(String[] args) {
|
---|
[33097] | 12 | try {
|
---|
| 13 | if (args.length != 3) {
|
---|
| 14 | System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>");
|
---|
| 15 | }
|
---|
| 16 | else {
|
---|
| 17 | String inputFilename = args[0];
|
---|
| 18 | String classifierType = args[1];
|
---|
| 19 | String outputFilename = args[2];
|
---|
| 20 | FileReader fileReader = new FileReader(inputFilename);
|
---|
| 21 | BufferedReader buf = new BufferedReader(fileReader);
|
---|
[33141] | 22 | FileWriter fw = new FileWriter(outputFilename,true);
|
---|
[33097] | 23 | String line = null;
|
---|
| 24 | String[] item;
|
---|
[33141] | 25 | float trueAccuracyRate =0;
|
---|
| 26 | float falseAccuracyRate =0;
|
---|
| 27 | int trueCount = 0;
|
---|
| 28 | int falseCount = 0;
|
---|
| 29 | int sheetMusicCount = 0;
|
---|
| 30 | int notSheetMusicCount = 0;
|
---|
[33097] | 31 | //Splits into each record, since readLine splits by "\n"
|
---|
| 32 | while ((line = buf.readLine()) != null) {
|
---|
[33141] | 33 | item = line.split("\t");
|
---|
| 34 | //Calculate AccuracyRates
|
---|
| 35 | if(item[1].contains("TestImages/SheetMusic/")){
|
---|
| 36 | sheetMusicCount++;
|
---|
| 37 | if(item[3].equals("true")){
|
---|
| 38 | trueCount++;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | if(item[1].contains("TestImages/NotSheetMusic/")){
|
---|
| 42 | notSheetMusicCount++;
|
---|
| 43 | if(item[3].equals("true")){
|
---|
| 44 | falseCount++;
|
---|
| 45 | }
|
---|
[33097] | 46 | }
|
---|
| 47 | }
|
---|
[33141] | 48 |
|
---|
| 49 | //Amount of sheetMusic classified images / total amount of images read
|
---|
| 50 | trueAccuracyRate = ((float)trueCount/(float)sheetMusicCount)*(float)100;
|
---|
| 51 | //Amount of notSheetMusic classified images / total amount of images read
|
---|
| 52 | falseAccuracyRate = ((float)falseCount/(float)notSheetMusicCount)*(float)100;
|
---|
| 53 |
|
---|
| 54 | fw.write("Classifier: " + classifierType + '\t' + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\t' + "NotSheetMusicAccuracyRate :" + falseAccuracyRate + "%" + "\n");
|
---|
[33097] | 55 | buf.close();
|
---|
[33141] | 56 | fw.close();
|
---|
[33097] | 57 | }
|
---|
| 58 | }
|
---|
| 59 | catch(Exception e){
|
---|
| 60 | System.err.println(e);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|