1
if it's a cat,
-1
if not
[?,?,?,...]
48x48
canvas -> HOG of length 1176
1000
s of random non-cat crops1000
s of cat head crops48x48
var hog = require("hog-descriptor");
var svm = require("svm");
var SVM = new svm.SVM();
function train(pics) {
var inputs = [], labels = [];
for (var i in pics) {
inputs[i] = hog.extractHOG(pics[i].canvas);
labels[i] = pics[i].isCat ? 1 : -1;
}
SVM.train(inputs, labels);
}
SVM.toJSON()
{
"N": 200,
"D": 1176,
"b": -1.9007738283614,
"kernelType": "linear",
"w": [-0.039986109425303, -0.10320175974183, 0.047456416498616, -0.059351675560768, 0.058363533996746, -0.030757724103858, -0.077885096059827,-0.10909238884521, -0.027176815631789, 0.011213708955119,0.11097928973275, 0.02171080491539, 0.087237563435941, -0.011851994166769, -0.083436869138139,0.03666910365707, -0.04060984443935, 0.018076869381974, -0.030717675854092, -0.053448579335487
,...]
}
It finds the best values for b
and w
^
How, you ask?
function isCat(canvas) {
var descriptor = hog.extractHOG(canvas);
var result = SVM.predictOne(descriptor);
return result == 1;
}