示例#1
0
def hog_train():
    # features = []
    # labels = []

    svm = svm_config()

    # get hog features
    features, labels = generate_hog_data(batch_size=10000)
    print(features.shape, labels.shape)
    # svm training
    print('svm training...')
    svm_train(svm, features, labels)
    print('svm training complete...')

    svm_save(svm, "../../models/HOGSVM_Digits.bin")
示例#2
0

#hog训练
def hog_train(svm):
    features = []
    labels = []

    hog = cv.HOGDescriptor()

    #get hog features
    get_features(features, labels)

    #svm training
    print('svm training...')
    svm_train(svm, features, labels)
    print('svm training complete...')

    hog.setSVMDetector(get_svm_detector(svm))
    hog.save('myHogDector.bin')

    print('hard samples training...')
    get_hard_samples(svm, features, labels)
    print('hard samples complete...')


if __name__ == '__main__':
    #svm config
    svm = svm_config()

    #hog training
    hog_train(svm)
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()])
            scores = []
            pbar.update(100 / len(step)**2)
    result1 = sorted(result, key=lambda x: x[2])
    print('complete!')
    for i in result1:
        print(i)