1 | initial version |
hmmm, there are differences between libsvm and opencv's SVM.
e.g. coef0 is a single constant, and it's not even used in the case of a linear SVM
while you can get at the data, you would be doing something else in the prediction pass, than in the training pass.
it's probably a better idea, to implement a custom kernel:
2 | No.2 Revision |
hmmm, there are differences between libsvm and opencv's SVM.
e.g. coef0 is a single constant, and it's not even used in the case of a linear SVM
while you can get at the data, you would be doing something else in the prediction pass, than in the training pass.
it's probably a better idea, to implement a custom kernel:kernel:
struct XKernel : public ml::SVM::Kernel
{
virtual ~XKernel() {}
//! your distance metric between one of the support vecs(sample)
// and your query(another) goes here
virtual float per_elem(int var_count, const float* sample, const float* another) = 0;
//! post-process results array (if nessecary, e.g. apply bias)
virtual void post(int vcount, float* results) {}
void calc(int vcount, int var_count, const float* vecs, const float* another, float* results)
{
for (int j=0; j<vcount; j++)
{
const float* sample = &vecs[j*var_count];
results[j] = per_elem(var_count, sample, another);
}
post(vcount, result);
}
int getType(void) const
{
return -1; // we're special.
}
};
Ptr<ml::SVM> svm = ml::SVM::create();
Ptr<XKernel> kern = makePtr<XKernel>();
svm->setKernel(kern);
3 | No.3 Revision |
hmmm, there are differences between libsvm and opencv's SVM.
e.g. coef0 is a single constant, and it's not even used in the case of a linear SVM
while you can get at the data, you would be doing something else in the prediction pass, than in the training pass.
it's probably a better idea, to implement a custom kernel:
struct XKernel : public ml::SVM::Kernel
{
virtual ~XKernel() {}
//! your distance metric between one of the support vecs(sample)
// and your query(another) goes here
virtual float per_elem(int var_count, const float* sample, const float* another) = 0;
{}
//! post-process results array (if nessecary, e.g. apply bias)
virtual void post(int vcount, float* results) {}
void calc(int vcount, int var_count, const float* vecs, const float* another, float* results)
{
for (int j=0; j<vcount; j++)
{
const float* sample = &vecs[j*var_count];
results[j] = per_elem(var_count, sample, another);
}
post(vcount, result);
}
int getType(void) const
{
return -1; // we're special.
}
};
Ptr<ml::SVM> svm = ml::SVM::create();
Ptr<XKernel> kern = makePtr<XKernel>();
svm->setKernel(kern);