Example #1
0
def get_features(features,labels):
    pos_imgs,pos_labels = read_pos_samples('F:/za/Model/pedestrain/INRIAPerson/pos_64x128')#==============================================
    computeHog(pos_imgs,features)  
    [labels.append(1) for _ in range(len(pos_imgs))]   
    neg_imgs,neg_labels = read_neg_samples('F:/za/Model/pedestrain/INRIAPerson/neg_64x128')
    computeHog(neg_imgs,features)    
    [labels.append(-1) for _ in range(len(neg_imgs))]

    #print('feature_shape = ',np.shape(features))
    return features,labels
Example #2
0
def get_features(features, labels):
    print('compute pos features...')
    pos_imgs, pos_labels = read_pos_samples('E:/pypj/pos')
    hog_compute(pos_imgs, features)

    [labels.append(1) for _ in range(len(pos_imgs))]
    print('compute negs features...')
    neg_imgs, neg_labels = read_neg_samples('E:/pypj/negs')
    hog_compute(neg_imgs, features)

    [labels.append(-1) for _ in range(len(neg_imgs))]
    print('features get!')
Example #3
0
def get_features(features, labels):
    print('get pos hog...')
    pos_imgs, pos_labels = read_pos_samples(
        'C:/Users/fyyk_whua/Desktop/python demo/MachineLearn/hog+svm/Img/pos_250x250/'
    )
    print('compute pos hog...')
    computeHog(pos_imgs, features)
    print('append pos labels...')
    [labels.append(1) for _ in range(len(pos_imgs))]

    print('get neg hog...')
    neg_imgs, neg_labels = read_neg_samples(
        'C:/Users/fyyk_whua/Desktop/python demo/MachineLearn/hog+svm/Img/neg_250x250/'
    )
    print('compute neg hog...')
    computeHog(neg_imgs, features)
    print('append neg labels...')
    [labels.append(-1) for _ in range(len(neg_imgs))]

    return features, labels
import cv2
import numpy as np
from get_data import read_pos_samples, read_neg_samples
from svm_train import svm_config, svm_train, svm_save, svm_load, get_svm_detector
from get_hog import hog_compute, hog_config, get_features
from tqdm import tqdm

if __name__ == '__main__':
    features = []
    labels = []
    pos_imgs, pos_labels = read_pos_samples('E:/pypj/res')
    get_features(features, labels)
    scores = []
    result = []
    print('start validate')
    pbar = tqdm(total=100)
    step = (-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5)
    for i in step:
        C = 2**i
        for j in step:
            G = 2**j
            svm = svm_config(C, G)
            svm_train(svm, features, labels)
            hog = hog_config()
            hog.setSVMDetector(get_svm_detector(svm))
            for pos_img in pos_imgs:
                rects, score = hog.detect(pos_img)
                if len(score) == 0:
                    score = np.array([0])
                scores.append(score.mean())
            result.append([C, G, np.array(scores).mean()])