Skip to content

Commit

Permalink
Added more logging and some null checking
Browse files Browse the repository at this point in the history
  • Loading branch information
trunerd committed Jul 2, 2016
1 parent 2d8350b commit e32fcf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ public void computeMetrics() {
public RecognitionMetric computeMetrics(List<RecognitionScore> recognitionScores) {
double averageScore = 0;
double averageScoreOfCorrect = 0;
int numberCorrect = 0;
double numberCorrect = 0;
double numTemplates = 0;
List<RecognitionScore> nonRecognizedIds = new ArrayList<>();
List<RecognitionScore> potentialMisRecognized = new ArrayList<>();
List<Exception> recognitionException = new ArrayList<>();
LOG.debug("Computing metrics");
for (RecognitionScore recognitionScore : recognitionScores) {
averageScore += recognitionScore.getScoreValue() / ((double) recognitionScores.size());
if (recognitionScore == null) {
LOG.debug("RECOGNITION SCORE IS NULL");
continue;
}
numTemplates++;
averageScore += recognitionScore.getScoreValue();
if (recognitionScore.isRecognized()) {
averageScoreOfCorrect += recognitionScore.getScoreValue();
numberCorrect++;
Expand All @@ -72,9 +78,10 @@ public RecognitionMetric computeMetrics(List<RecognitionScore> recognitionScores
recognitionException.add(recognitionScore.getException());
}
}
averageScoreOfCorrect /= (double) numberCorrect;
averageScore /= numTemplates;
averageScoreOfCorrect /= numberCorrect;
LOG.debug("Finished Computing metrics");
return new RecognitionMetric(averageScore, averageScoreOfCorrect,
numberCorrect, nonRecognizedIds, potentialMisRecognized, recognitionScores.size(), recognitionException);
(int) numberCorrect, nonRecognizedIds, potentialMisRecognized, (int) numTemplates, recognitionException);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ private List<RecognitionScoreMetrics> testAgainstTemplates(List<Sketch.Recogniti
return metrics;
}


private Map<RecognitionInterface, List<RecognitionScore>> recognizeAgainstTemplates(
List<Sketch.RecognitionTemplate> testTemplates) {
Map<RecognitionInterface, List<RecognitionScore>> scoreMap = new HashMap<>();

// For the specific number of theads needed
executor = Executors.newFixedThreadPool(Math.min(MAX_THREADS, Math.max(1, testTemplates.size() / 20)));
// For the specific number of threads needed
executor = Executors.newFixedThreadPool(Math.min(MAX_THREADS, Math.max(1, testTemplates.size() / 10)));

LOG.debug("Running recognition test for {} templates", testTemplates.size());
int percent = (int) Math.round(Math.max(1.0, testTemplates.size() / 100.0));
Expand All @@ -99,6 +98,7 @@ public Object call() throws Exception {
recognize = recognitionSystem.recognize(testTemplate.getTemplateId(), testTemplate);
if (recognize == null) {
score.setFailed(new NullPointerException("List of returned interpretations is null"));
recognitionScoreList.add(score);
return null;
}
generateScore(score, recognize, testTemplate.getInterpretation());
Expand All @@ -116,6 +116,7 @@ public Object call() throws Exception {
counter++;
}

LOG.debug("Waiting for all tasks to finish");
// Waits for the executor to finish
for (Future taskFuture : taskFutures) {
try {
Expand All @@ -126,7 +127,7 @@ public Object call() throws Exception {
LOG.debug("EXECUTION EXCEPTION", e);
}
}

LOG.debug("All recognition testing tasks have finished");
}
return scoreMap;
}
Expand Down

0 comments on commit e32fcf6

Please sign in to comment.