SVM 自定义对象检测器的正负样本分离
Separate Positive and Negative Samples for SVM Custom Object Detector
我正在尝试通过在 OpenCV 上使用 HOG+SVM 方法来训练自定义对象检测器。
我已经成功地使用下面的代码行从我的正样本和负样本中提取了 HOG 特征:
import cv2
hog = cv2.HOGDescriptor()
def poshoggify():
for i in range(1,20):
image = cv2.imread("/Users/munirmalik/cvprojek/cod/pos/" + str(i)+ ".jpg")
(winW, winH) = (500, 500)
for resized in pyramid(image, scale=1.5):
# loop over the sliding window for each layer of the pyramid
for (x, y, window) in sliding_window(resized, stepSize=32, windowSize=(winW, winH)):
# if the window does not meet our desired window size, ignore it
if window.shape[0] != winH or window.shape[1] != winW:
continue
img_pos = hog.compute(image)
np.savetxt('posdata.txt',img_pos)
return img_pos
负样本的等效函数。
如何格式化数据,使 SVM 知道哪个是正的,哪个是负的?
此外,我如何将此训练转化为 "test" 通过我的网络摄像头检测所需对象?
如何格式化数据,使 SVM 知道哪个是正的,哪个是负的?
您现在可以创建另一个名为 labels
的列表,该列表将存储与相应图像关联的 class 值。例如,如果您有一组如下所示的特征训练集:
features = [pos_features1, pos_features2, neg_features1, neg_features2, neg_features3, neg_features4]
你会有一个相应的标签class喜欢
labels = [1, 1, 0, 0, 0, 0]
然后您可以像这样将其提供给 classifier:
clf=LinearSVC(C=1.0, class_weight='balanced')
clf.fit(features,labels)
此外,我如何将此训练转化为 "test" 通过我的网络摄像头检测所需对象?
在训练之前,您应该将标记数据集 (groundtruth) 拆分为训练和测试数据集。您可以使用 skilearns KFold module.
执行此操作
我正在尝试通过在 OpenCV 上使用 HOG+SVM 方法来训练自定义对象检测器。
我已经成功地使用下面的代码行从我的正样本和负样本中提取了 HOG 特征:
import cv2
hog = cv2.HOGDescriptor()
def poshoggify():
for i in range(1,20):
image = cv2.imread("/Users/munirmalik/cvprojek/cod/pos/" + str(i)+ ".jpg")
(winW, winH) = (500, 500)
for resized in pyramid(image, scale=1.5):
# loop over the sliding window for each layer of the pyramid
for (x, y, window) in sliding_window(resized, stepSize=32, windowSize=(winW, winH)):
# if the window does not meet our desired window size, ignore it
if window.shape[0] != winH or window.shape[1] != winW:
continue
img_pos = hog.compute(image)
np.savetxt('posdata.txt',img_pos)
return img_pos
负样本的等效函数。
如何格式化数据,使 SVM 知道哪个是正的,哪个是负的?
此外,我如何将此训练转化为 "test" 通过我的网络摄像头检测所需对象?
如何格式化数据,使 SVM 知道哪个是正的,哪个是负的?
您现在可以创建另一个名为 labels
的列表,该列表将存储与相应图像关联的 class 值。例如,如果您有一组如下所示的特征训练集:
features = [pos_features1, pos_features2, neg_features1, neg_features2, neg_features3, neg_features4]
你会有一个相应的标签class喜欢
labels = [1, 1, 0, 0, 0, 0]
然后您可以像这样将其提供给 classifier:
clf=LinearSVC(C=1.0, class_weight='balanced')
clf.fit(features,labels)
此外,我如何将此训练转化为 "test" 通过我的网络摄像头检测所需对象?
在训练之前,您应该将标记数据集 (groundtruth) 拆分为训练和测试数据集。您可以使用 skilearns KFold module.
执行此操作