コード例 #1
0
def convert_leaves_all_probs_pred(image, leaves, all_probs, num_leaves):
    import imseg
    preds = []  # NOTE(brandyn): This has the ILP turned off
    preds = np.ascontiguousarray(preds, dtype=np.float64)
    out0 = imseg.convert_labels_to_integrals(leaves, num_leaves)
    out1 = imseg.convert_all_probs_to_integrals(all_probs)
    return preds, np.ascontiguousarray(np.dstack([out0, out1]))
コード例 #2
0
ファイル: leaves_to_probs.py プロジェクト: damian-666/imseg
def convert_leaves_all_probs_pred_old(image, leaves, all_probs, num_leaves, classifiers_fn=None):
    global CLASSIFIERS, CLASSIFIER_FEATURE
    if classifiers_fn is None:
        classifiers_fn = os.environ['CLASSIFIERS_FN']
    get_classifier_confidence = lambda x: x[0][0] * x[0][1]
    if CLASSIFIERS is None:
        all_classifiers = sorted(file_parse.load(classifiers_fn))
        name_classifiers = []
        for x in range(len(all_classifiers)):
            if x < len(all_classifiers):  # TODO(brandyn): Fix memory issue so that we can use the last classifier too
                name_classifiers.append((all_classifiers[x][0],
                                         classifiers.loads(all_classifiers[x][1])))
            else:
                name_classifiers.append((all_classifiers[x][0],
                                         name_classifiers[-1][1]))
            all_classifiers[x] = None  # NOTE(Brandyn): This is done to save memory
        print('ILP Classifiers %r' % ([x for x, _ in name_classifiers],))
        CLASSIFIERS = [x for _, x in name_classifiers]
    if CLASSIFIER_FEATURE is None:
        CLASSIFIER_FEATURE = features.select_feature('bovw_hog')
    feature = CLASSIFIER_FEATURE(np.ascontiguousarray(image[:, :, :3]))
    preds = np.ascontiguousarray([get_classifier_confidence(classifier.predict(feature))
                                  for classifier in CLASSIFIERS], dtype=np.float64)
    out0 = imseg.convert_labels_to_integrals(leaves, num_leaves)
    out1 = imseg.convert_all_probs_to_integrals(all_probs)
    return preds, np.ascontiguousarray(np.dstack([out0, out1]))
コード例 #3
0
ファイル: leaves_to_probs.py プロジェクト: damian-666/imseg
def convert_leaves_all_probs_pred(image, leaves, all_probs, num_leaves, classifiers_fn=None):
    global CLASSIFIER_FEATURE, ALL_CLASSIFIERS, CLASSIFIERS
    preds = []
    if classifiers_fn:
        get_classifier_confidence = lambda x: x[0][0] * x[0][1]
        if ALL_CLASSIFIERS is None:
            ALL_CLASSIFIERS = sorted(file_parse.load(classifiers_fn))
        if CLASSIFIER_FEATURE is None:
            CLASSIFIER_FEATURE = features.select_feature('bovw_hog')
        feature = CLASSIFIER_FEATURE(np.ascontiguousarray(image[:, :, :3]))
        for x in range(len(ALL_CLASSIFIERS)):
            try:
                classifier = CLASSIFIERS[x]
            except KeyError:
                classifier = classifiers.loads(ALL_CLASSIFIERS[x][1])
                if x < 14:
                    CLASSIFIERS[x] = classifier
            preds.append(get_classifier_confidence(classifier.predict(feature)))
    preds = np.ascontiguousarray(preds, dtype=np.float64)
    out0 = imseg.convert_labels_to_integrals(leaves, num_leaves)
    out1 = imseg.convert_all_probs_to_integrals(all_probs)
    return preds, np.ascontiguousarray(np.dstack([out0, out1]))
コード例 #4
0
ファイル: texton_to_integral.py プロジェクト: bwhite/imseg
    def map(self, k, v):
        """
        Args:
            k: Filename
            v: (image_data, label_points)

        Yields:
            (k, (integral, label_points))
        """
        image_data, label_points = v

        argmax, max_probs, leaves, all_probs = self.tp.predict(image_data, all_probs=True, leaves=True)
        print("Leaves[%s] AllProbs[%s]" % (str(leaves.shape), str(all_probs.shape)))
        if self.integral_type == "argmax":
            out = np.ascontiguousarray(imseg.convert_labels_to_integrals(argmax, self.tp.num_classes))
        elif self.integral_type == "argmax_prob":
            out = np.ascontiguousarray(imseg.convert_labels_probs_to_integrals(argmax, max_probs, self.tp.num_classes))
        elif self.integral_type == "all_prob":
            out = np.ascontiguousarray(imseg.convert_all_probs_to_integrals(all_probs))
        elif self.integral_type == "spatial":
            out = convert_leaves_all_probs_pred(image_data, leaves, all_probs, self.tp.num_leaves)
        yield k, (out, label_points)