主函数为
#!/usr/bin/python
import os
# Link to the UIUC Car Database
# http://l2r.cs.uiuc.edu/~cogcomp/Data/Car/CarData.tar.gz
# dataset_url = "http://l2r.cs.uiuc.edu/~cogcomp/Data/Car/CarData.tar.gz"
# dataset_path = "../data/dataset/CarData.tar.gz"
# Fetch and extract the dataset
# if not os.path.exists(dataset_path):
# os.system("wget {} -O {}".format(dataset_url, dataset_path))
# os.system("tar -xvzf {} -C {}".format(dataset_path, os.path.split(dataset_path)[0]))
# Extract the features
pos_path = "../data/dataset/CarData/pos"
neg_path = "../data/dataset/CarData/neg"
os.system("python ../object-detector/extract-features.py -p {} -n {}".format(pos_path, neg_path))
# Perform training
pos_feat_path = "../data/features/pos"
neg_feat_path = "../data/features/neg"
os.system("python ../object-detector/train-classifier.py -p {} -n {}".format(pos_feat_path, neg_feat_path))
# Perform testing
test_im_path = "../data/dataset/CarData/TestImages/test-18.pgm"
os.system("python ../object-detector/test-classifier.py -i {} -d {} --visualize".format(test_im_path,2))
参数为
[hog]
min_wdw_sz: [100, 40]
step_size: [10, 10]
orientations: 9
pixels_per_cell: [5, 5]
cells_per_block: [3, 3]
visualize: False
transform_sqrt:True
visualize_test: True
[nms]
threshold: 0.3
[paths]
pos_feat_ph: ../data/features/pos
neg_feat_ph: ../data/features/neg
model_path: ../data/models/svm.model
读取参数config
'''
Set the config variable.
'''
import ConfigParser as cp
import json
config = cp.RawConfigParser()
config.read('../data/config/config.cfg')
min_wdw_sz = tuple(json.loads(config.get("hog","min_wdw_sz")))
step_size = tuple(json.loads(config.get("hog", "step_size")))
orientations = config.getint("hog", "orientations")
pixels_per_cell = json.loads(config.get("hog", "pixels_per_cell"))
cells_per_block = json.loads(config.get("hog", "cells_per_block"))
visualize = config.getboolean("hog", "visualize")
visualize_test = config.getboolean("hog","visualize_test")
transform_sqrt = config.getboolean("hog", "transform_sqrt")
pos_feat_ph = config.get("paths", "pos_feat_ph")
neg_feat_ph = config.get("paths", "neg_feat_ph")
model_path = config.get("paths", "model_path")
threshold = config.getfloat("nms", "threshold")
HOG特征提取,在这里实现的步骤有些繁琐,可以实现的时候将HOG和SVM写在一起
# Import the functions to calculate feature descriptors
from skimage.feature import local_binary_pattern
from skimage.feature import hog
from skimage.io import imread
from sklearn.externals import joblib