private boolean checkForNegativeValueFeatures(Classifier classifier) { if (classifier instanceof ValueClassifier) { if (((ValueClassifier) classifier).value < 0) return true; } else { if (checkForNegativeValueFeatures(((HaarFeatureClassifier) classifier).left)) return true; if (checkForNegativeValueFeatures(((HaarFeatureClassifier) classifier).right)) return true; } return false; }
final StageNode node = stageNodes.get(i); stages[i] = new Stage(node.threshold, buildClassifiers(node.trees), null, null);
/** * Recursively update the caches of all the stages to reflect the current * scale. * * @param s * the stage to update */ private void updateCaches(Stage s) { s.updateCaches(this); if (s.successStage != null) updateCaches(s.successStage); if (s.failureStage != null) updateCaches(s.failureStage); }
Stage stage = root; while (true) { // until success or failure if (stage.pass(sat, wvNorm, x, y)) { matches++; stage = stage.successStage;
final StageNode node = stageNodes.get(i); stages[i] = new Stage(node.threshold, buildClassifiers(node.trees), null, null);
/** * Recursively update the caches of all the stages to reflect the current * scale. * * @param s * the stage to update */ private void updateCaches(Stage s) { s.updateCaches(this); if (s.successStage != null) updateCaches(s.successStage); if (s.failureStage != null) updateCaches(s.failureStage); }
Stage stage = root; while (true) { // until success or failure if (stage.pass(sat, wvNorm, x, y)) { matches++; stage = stage.successStage;
/** * Create a {@link Stage} from a trained ensemble. * * @param ensemble * the ensemble * @return the stage */ private Stage createStage(final List<ObjectFloatPair<StumpClassifier>> ensemble) { final HaarFeatureClassifier[] trees = new HaarFeatureClassifier[ensemble.size()]; for (int i = 0; i < trees.length; i++) { final ObjectFloatPair<StumpClassifier> wc = ensemble.get(i); final StumpClassifier c = wc.first; final float alpha = wc.second; final float threshold = c.threshold; final float leftValue = c.sign > 0 ? -alpha : alpha; final HaarFeature feature = features.get(c.dimension); final ValueClassifier left = new ValueClassifier(leftValue); final ValueClassifier right = new ValueClassifier(-leftValue); trees[i] = new HaarFeatureClassifier(feature, threshold, left, right); } final Stage root = new Stage(0, trees, null, null); return root; }
private boolean checkForNegativeValueFeatures(Classifier classifier) { if (classifier instanceof ValueClassifier) { if (((ValueClassifier) classifier).value < 0) return true; } else { if (checkForNegativeValueFeatures(((HaarFeatureClassifier) classifier).left)) return true; if (checkForNegativeValueFeatures(((HaarFeatureClassifier) classifier).right)) return true; } return false; }
/** * Create a {@link Stage} from a trained ensemble. * * @param ensemble * the ensemble * @return the stage */ private Stage createStage(final List<ObjectFloatPair<StumpClassifier>> ensemble) { final HaarFeatureClassifier[] trees = new HaarFeatureClassifier[ensemble.size()]; for (int i = 0; i < trees.length; i++) { final ObjectFloatPair<StumpClassifier> wc = ensemble.get(i); final StumpClassifier c = wc.first; final float alpha = wc.second; final float threshold = c.threshold; final float leftValue = c.sign > 0 ? -alpha : alpha; final HaarFeature feature = features.get(c.dimension); final ValueClassifier left = new ValueClassifier(leftValue); final ValueClassifier right = new ValueClassifier(-leftValue); trees[i] = new HaarFeatureClassifier(feature, threshold, left, right); } final Stage root = new Stage(0, trees, null, null); return root; }
private boolean checkForNegativeValueFeatures() { for (int i = 0; i < ensemble.length; i++) { if (checkForNegativeValueFeatures(ensemble[i])) return true; } return false; }
private boolean checkForNegativeValueFeatures() { for (int i = 0; i < ensemble.length; i++) { if (checkForNegativeValueFeatures(ensemble[i])) return true; } return false; }
/** * Construct a new stage. * * @param threshold * the threshold for the stage to pass * @param trees * the classifier trees in the stage * @param successStage * the next stage after this one, or null if this is the last * @param failureStage * the failure stage (for trees rather than cascades) */ public Stage(float threshold, Classifier[] trees, Stage successStage, Stage failureStage) { this.threshold = threshold; this.ensemble = trees; this.successStage = successStage; this.failureStage = failureStage; this.hasNegativeValueFeatures = checkForNegativeValueFeatures(); }
/** * Construct a new stage. * * @param threshold * the threshold for the stage to pass * @param trees * the classifier trees in the stage * @param successStage * the next stage after this one, or null if this is the last * @param failureStage * the failure stage (for trees rather than cascades) */ public Stage(float threshold, Classifier[] trees, Stage successStage, Stage failureStage) { this.threshold = threshold; this.ensemble = trees; this.successStage = successStage; this.failureStage = failureStage; this.hasNegativeValueFeatures = checkForNegativeValueFeatures(); }