将 HOG 输入 SVM:HOG 有 9 个 bin,但 SVM 接受一维矩阵
在 OpenCV 中,有一个 CvSVM 类,它采用样本矩阵来训练 SVM。该矩阵是二维的,样本位于行中。
我创建了自己的方法来从视频源生成定向梯度直方图 (HOG)。为此,我创建了一个 9 通道矩阵来存储 HOG,其中每个通道对应一个方向箱。所以最后我有一个 CV_32FC(9) 类型的 40x30 矩阵。
还为 HOG 做了一个可视化,它正在工作。
我不知道如何将该矩阵输入 OpenCV SVM,因为如果我将其展平,我不知道 SVM 应该如何从 1D 输入数据学习 9D 超平面。
In OpenCV, there is a CvSVM class which takes in a matrix of samples to train the SVM. The matrix is 2D, with the samples in the rows.
I created my own method to generate a histogram of oriented gradients (HOG) off of a video feed. To do this, I created a 9 channeled matrix to store the HOG, where each channel corresponds to an orientation bin. So in the end I have a 40x30 matrix of type CV_32FC(9)
.
Also made a visualisation for the HOG and it's working.
I don't see how I'm supposed to feed this matrix into the OpenCV SVM, because if I flatten it, I don't see how the SVM is supposed to learn a 9D hyperplane from 1D input data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SVM 总是为每个特征向量接收一行数据。因此,特征向量的维数就是行的长度。如果您处理的是 2D 数据,则每个特征向量有 2 个项目。二维数据示例位于此网页上:
http://www.csie.ntu。 edu.tw/~cjlin/libsvm/
OpenCV 中等效演示的代码 http://sites.google.com/site/btabibian/labbook/svmusingopencv
要点是,即使您将直方图视为具有 9-bin 单元的 2D,该功能向量实际上是它的扁平化版本。因此将其展平为长特征向量是正确的。对我来说,结果是长度为 2304 (16x16x9) 的特征向量,并且我在小型测试集上获得了 100% 的预测精度(即,它可能略低于 100%,但效果非常好)。
其工作原理是 SVM 工作在特征向量每一项的权重系统上。所以它与问题的维度没有任何关系,超平面始终与特征向量处于同一维度。另一种看待它的方法是忘记超平面,而只是将其视为特征向量中每个项目的一堆权重。在这种情况下,它需要为每个项目分配一个权重,然后将每个项目与其权重相乘并输出结果。
The SVM always takes in a single row of data per feature vector. The dimensionality of the feature vector is thus the length of the row. If you're dealing with 2D data, then there are 2 items per feature vector. Example of 2D data is on this webpage:
http://www.csie.ntu.edu.tw/~cjlin/libsvm/
code of an equivalent demo in OpenCV http://sites.google.com/site/btabibian/labbook/svmusingopencv
The point is that even though you're thinking of the histogram as 2D with 9-bin cells, the feature vector is in fact the flattened version of this. So it's correct to flatten it out into a long feature vector. The result for me was a feature vector of length 2304 (16x16x9) and I get 100% prediction accuracy on a small test set (i.e. it's probably slightly less than 100% but it's working exceptionally well).
The reason this works is that the SVM is working on a system of weights per item of the feature vector. So it doesn't have anything to do with the problem's dimension, the hyperplane is always in the same dimension as the feature vector. Another way of looking at it is to forget about the hyperplane and just view it as a bunch of weights for each item in the feature vector. In this case, it needs one weighting for every item, then it multiplies each item by its weighting and outputs the result.