Skip to content

Commit

Permalink
Added a finish training method to clean up training resources
Browse files Browse the repository at this point in the history
  • Loading branch information
dtracers committed Jul 4, 2016
1 parent 64f9365 commit cfe42ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public interface RecognitionInterface {
*/
public void trainTemplate(Sketch.RecognitionTemplate template) throws TemplateException;

/**
* Called when Training is finished to show perform any cleanup that is needed.
*
* @throws RecognitionException Thrown if there is a recognition Problem.
*/
public void finishTraining() throws RecognitionException;

/**
* Recognizes the sketch as a list of changes producing a list of changes as a result.
*
Expand Down Expand Up @@ -117,5 +124,5 @@ public List<Sketch.SrlInterpretation> recognize(String sketchId, Sketch.Recognit
/**
* Called for an initialization or training to setup for recognition.
*/
public void initialize();
public void initialize() throws RecognitionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import coursesketch.recognition.framework.RecognitionInterface;
import coursesketch.recognition.framework.TemplateDatabaseInterface;
import coursesketch.recognition.framework.exceptions.RecognitionException;
import coursesketch.recognition.framework.exceptions.TemplateException;
import protobuf.srl.sketch.Sketch;

Expand Down Expand Up @@ -72,7 +73,7 @@ public List<RecognitionScoreMetrics> testAgainstTemplates(List<Sketch.Recognitio
return metrics;
}

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

Expand Down Expand Up @@ -106,7 +107,6 @@ public Object call() throws Exception {
}
generateScore(score, recognize, testTemplate.getInterpretation());
} catch (Exception e) {
LOG.error("Excpetion occured while recognizering", e);
score.setFailed(e);
}
recognitionScoreList.add(score);
Expand Down Expand Up @@ -158,7 +158,6 @@ public Object call() throws Exception {
try {
recognitionSystem.trainTemplate(template);
} catch (Exception e) {
LOG.error("Exception occured while training", e);
score.addException(new RecognitionTestException("Error with training template " + template.getTemplateId(),
e, recognitionSystem));
}
Expand Down Expand Up @@ -186,6 +185,11 @@ public Object call() throws Exception {
LOG.debug("EXECUTION EXCEPTION", e);
}
}
try {
recognitionSystem.finishTraining();
} catch (RecognitionException e) {
LOG.debug("EXCEPTION WHEN TRAINING", e);
}
LOG.debug("All trainings tasks have finished");
}
return scoreMap;
Expand Down

0 comments on commit cfe42ac

Please sign in to comment.