def classify_image(cc, img_idx, C=1.0, gamma=0.0, cls=None): """ Input: ClassifierConfig, img_idx Output: Score for given class; 20list of scores if cls=None """ feat_vect = get_feature_vector(cc, img_idx) if cls == None: score = {} for cls_idx, cls in enumerate(cc.d.classes): print '\tclassify %s for %s on %d'%(cc.d.images[img_idx].name, cls, comm_rank) path = config.get_classifier_svm_name(cls, C, gamma) if os.path.exists(path): clf = load_svm(path) score[cls_idx] = svm_predict(feat_vect, clf) else: clf = load_svm(config.get_classifier_svm_name(cls)) score = svm_predict(feat_vect, clf) return score
def classify_image(cc, img_idx, C=1.0, gamma=0.0, cls=None): """ Input: ClassifierConfig, img_idx Output: Score for given class; 20list of scores if cls=None """ feat_vect = get_feature_vector(cc, img_idx) if cls == None: score = {} for cls_idx, cls in enumerate(cc.d.classes): print '\tclassify %s for %s on %d' % (cc.d.images[img_idx].name, cls, comm_rank) path = config.get_classifier_svm_name(cls, C, gamma) if os.path.exists(path): clf = load_svm(path) score[cls_idx] = svm_predict(feat_vect, clf) else: clf = load_svm(config.get_classifier_svm_name(cls)) score = svm_predict(feat_vect, clf) return score
def classify_images(cc, images, C, gamma): res = np.zeros((images.shape[0], len(cc.d.classes))) for cls_idx, cls in enumerate(cc.d.classes): filename = config.get_classifier_svm_name(cls, C, gamma, cc.d.current_fold) if not os.path.exists(filename): continue clf = load_svm(filename, probability=False) for idx2, img_idx in enumerate(images): x = get_feature_vector(cc, img_idx) pred = svm_predict(x, clf) if pred.size > 0: res[idx2, cls_idx] = 1 return res*2-1
def classify_images(cc, images, C, gamma): res = np.zeros((images.shape[0], len(cc.d.classes))) for cls_idx, cls in enumerate(cc.d.classes): filename = config.get_classifier_svm_name(cls, C, gamma, cc.d.current_fold) if not os.path.exists(filename): continue clf = load_svm(filename, probability=False) for idx2, img_idx in enumerate(images): x = get_feature_vector(cc, img_idx) pred = svm_predict(x, clf) if pred.size > 0: res[idx2, cls_idx] = 1 return res * 2 - 1