Search in sources :

Example 1 with Node

use of boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node in project BoofCV by lessthanoptimal.

the class LearnHierarchicalTree method processLevel.

/**
 * Cluster each branch in the tree for the set of points in the node
 *
 * @param pointsInParent Points that are members of the parent
 * @param tree The tree that's being learned
 * @param level Level in the HierarchicalVocabularyTree
 * @param parentNodeIdx Array index for the parent node
 */
private void processLevel(PackedArray<Point> pointsInParent, HierarchicalVocabularyTree<Point> tree, int level, int parentNodeIdx) {
    // Stop here if we are at the maximum number of levels or there are too few points
    if (level >= tree.maximumLevel || pointsInParent.size() <= pointsRequiredForChildren)
        return;
    // Get k-means for this level
    StandardKMeans<Point> kmeans = listKMeans.get(level);
    // Cluster the input points
    kmeans.process(pointsInParent, tree.branchFactor);
    DogArray_I32 assignments = kmeans.getAssignments();
    List<Point> clusterMeans = kmeans.getBestClusters().toList();
    // and this "might" reduce cache misses in searching
    for (int label = 0; label < clusterMeans.size(); label++) {
        tree.addNode(parentNodeIdx, label, clusterMeans.get(label));
    }
    if (verbose != null)
        verbose.println("level=" + level + " kmeans.score=" + kmeans.getBestClusterScore());
    // Load the points that are in the child sub region
    Node parent = tree.nodes.get(parentNodeIdx);
    // Create pyramid nodes from the children
    PackedArray<Point> pointsInBranch = listPoints.get(level);
    pointsInBranch.reserve(pointsInParent.size() / (tree.branchFactor - 1));
    processChildren(tree, level, parent, pointsInParent, clusterMeans, assignments, pointsInBranch);
}
Also used : Node(boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node) DogArray_I32(org.ddogleg.struct.DogArray_I32) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 2 with Node

use of boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node in project BoofCV by lessthanoptimal.

the class LearnNodeWeights method fixate.

/**
 * Call when done. This will compute the weight using an entropy like function: weight[i] = log(N/N[i]) where
 * N[i] is the number of times a specific node/work appears at least once in the images.
 */
public void fixate() {
    // root is always zero since all images are in it
    tree.nodes.get(0).weight = 0;
    // Compute the threshold relative to the total number of images
    int maxImagesInNode = maximumNumberImagesInNode.computeI(totalImages);
    for (int i = 1; i < tree.nodes.size; i++) {
        Node n = tree.nodes.get(i);
        int totalImagesFoundInsideOf = numberOfImagesWithNode.get(n.index);
        // become part of the image descriptor
        if (totalImagesFoundInsideOf > maxImagesInNode) {
            n.weight = 0;
            continue;
        }
        if (totalImagesFoundInsideOf == 0) {
            // never observed.
            if (checkEveryNodeSeenOnce)
                throw new BoofCheckFailure("Every node should have been seen by at least 1 image if feed the " + "same images the tree was trained from.");
            n.weight = 0;
        } else {
            n.weight = Math.log(totalImages / (double) totalImagesFoundInsideOf);
        }
    }
}
Also used : BoofCheckFailure(boofcv.errors.BoofCheckFailure) Node(boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node)

Aggregations

Node (boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node)2 BoofCheckFailure (boofcv.errors.BoofCheckFailure)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 VerbosePrint (org.ddogleg.struct.VerbosePrint)1