4

I am doing a project for which I need to detect the rear of a car using HOG features. Once I calculated the HOG features I trained the cvsvm using positive and negative samples. cvsvm is correctly classifying the new data. Here is my code that I used to train cvsvm.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
#include "opencv2/opencv.hpp"  
#include "LinearSVM.h" 


using namespace cv;
using namespace std;



int main(void)
{
    LinearSVM *s = new LinearSVM;
    vector<float> values, values1, values2, values3, values4;

    FileStorage fs2("/home/ubuntu/Desktop/opencv-svm/vecSupport.yml",  FileStorage::READ);
    FileStorage fs3("/home/ubuntu/Desktop/opencv-svm/vecSupport1.yml", FileStorage::READ);
    FileStorage fs4("/home/ubuntu/Desktop/opencv-svm/vecSupport2.yml", FileStorage::READ);
    FileStorage fs5("/home/ubuntu/Desktop/opencv-svm/vecSupport3.yml", FileStorage::READ);
    FileStorage fs6("/home/ubuntu/Desktop/opencv-svm/vecSupport4.yml", FileStorage::READ);

    fs2["vector"]>>values;
    fs3["vector"]>>values1;
    fs4["vector"]>>values2;
    fs5["vector"]>>values3;
    fs6["vector"]>>values4;

    //fill with data
    values.insert(values.end(), values1.begin(), values1.end());
    values.insert(values.end(), values2.begin(), values2.end());


    fs2.release();
    fs3.release();
    fs4.release();

    float arr[188496];
    float car[2772];
    float noncar[2772];

    // move positive and negative to arr
    std::copy(values.begin(), values.end(), arr);
    std::copy(values3.begin(), values3.end(), car);
    std::copy(values4.begin(), values4.end(), noncar);



    float labels[68];
    for (unsigned int s = 0; s < 68; s++)
    {
     if (s<34)
     labels[s] = +1;
     else
     labels[s] = -1;
    }

    Mat labelsMat(68, 1, CV_32FC1, labels);
    Mat trainingDataMat(68,2772, CV_32FC1, arr);


    // Set up SVM's parameters
    CvSVMParams params;
    params.svm_type    = CvSVM::C_SVC;
    params.kernel_type = CvSVM::LINEAR;
    params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);

    // Train the SVM
    LinearSVM SVM;
    SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);

    Mat matinput(1,2772,CV_32FC1,noncar);
    //cout<<matinput;

    float response = SVM.predict(matinput);
    cout<<"Response : "<<response<<endl;

    SVM.save("Classifier.xml");

    vector<float>primal;

      //  LinearSVM s;
    //s.getSupportVector(primal);
    SVM.getSupportVector(primal);

    FileStorage fs("/home/ubuntu/Desktop/opencv-svm/test.yml", FileStorage::WRITE);
    fs << "dector" << primal;
    fs.release();

}

// LinearSVM cpp file 
#include "LinearSVM.h"   
void LinearSVM::getSupportVector(std::vector<float>& support_vector) const {

    int sv_count = get_support_vector_count();
    const CvSVMDecisionFunc* df = decision_func;
    const double* alphas = df[0].alpha;
    double rho = df[0].rho;
    int var_count = get_var_count();
    support_vector.resize(var_count, 0);
    for (unsigned int r = 0; r < (unsigned)sv_count; r++) {
      float myalpha = alphas[r];
      const float* v = get_support_vector(r);
      for (int j = 0; j < var_count; j++,v++) {
        support_vector[j] += (-myalpha) * (*v);
      }
    }
    support_vector.push_back(rho);
}

// LinearSVM head file

#ifndef LINEAR_SVM_H_
#define LINEAR_SVM_H_
#include <opencv2/core/core.hpp>
#include <opencv2/ml/ml.hpp>

class LinearSVM: public CvSVM {
public:
  void getSupportVector(std::vector<float>& support_vector) const;
};  

#endif /* LINEAR_SVM_H_ */

After this step I got the vector file that I can fed into setsvmdetector method. Here is my code. I have used window size of 96 x 64 and scale of 1.11

#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <stdexcept>
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

bool help_showed = false;

class Args
{
public:
    Args();
    static Args read(int argc, char** argv);

    string src;
    bool src_is_video;
    bool src_is_camera;
    int camera_id;

    bool write_video;
    string dst_video;
    double dst_video_fps;

    bool make_gray;

    bool resize_src;
    int width, height;

    double scale;
    int nlevels;
    int gr_threshold;

    double hit_threshold;
    bool hit_threshold_auto;

    int win_width;
    int win_stride_width, win_stride_height;

    bool gamma_corr;
};


class App
{
public:
    App(const Args& s);
    void run();

    void handleKey(char key);

    void hogWorkBegin();
    void hogWorkEnd();
    string hogWorkFps() const;

    void workBegin();
    void workEnd();
    string workFps() const;

    string message() const;

private:
    App operator=(App&);

    Args args;
    bool running;

    bool use_gpu;
    bool make_gray;
    double scale;
    int gr_threshold;
    int nlevels;
    double hit_threshold;
    bool gamma_corr;

    int64 hog_work_begin;
    double hog_work_fps;

    int64 work_begin;
    double work_fps;
};

static void printHelp()
{
    cout << "Histogram of Oriented Gradients descriptor and detector sample.\n"
         << "\nUsage: hog_gpu\n"
         << "  (<image>|--video <vide>|--camera <camera_id>) # frames source\n"
         << "  [--make_gray <true/false>] # convert image to gray one or not\n"
         << "  [--resize_src <true/false>] # do resize of the source image or not\n"
         << "  [--width <int>] # resized image width\n"
         << "  [--height <int>] # resized image height\n"
         << "  [--hit_threshold <double>] # classifying plane distance threshold (0.0 usually)\n"
         << "  [--scale <double>] # HOG window scale factor\n"
         << "  [--nlevels <int>] # max number of HOG window scales\n"
         << "  [--win_width <int>] # width of the window (48 or 64)\n"
         << "  [--win_stride_width <int>] # distance by OX axis between neighbour wins\n"
         << "  [--win_stride_height <int>] # distance by OY axis between neighbour wins\n"
         << "  [--gr_threshold <int>] # merging similar rects constant\n"
         << "  [--gamma_correct <int>] # do gamma correction or not\n"
         << "  [--write_video <bool>] # write video or not\n"
         << "  [--dst_video <path>] # output video path\n"
         << "  [--dst_video_fps <double>] # output video fps\n";
    help_showed = true;
}

int main(int argc, char** argv)
{
    try
    {
        if (argc < 2)
            printHelp();
        Args args = Args::read(argc, argv);
        if (help_showed)
            return -1;
        App app(args);
        app.run();
    }
    catch (const Exception& e) { return cout << "error: "  << e.what() << endl, 1; }
    catch (const exception& e) { return cout << "error: "  << e.what() << endl, 1; }
    catch(...) { return cout << "unknown exception" << endl, 1; }
    return 0;
}


Args::Args()
{
    src_is_video = false;
    src_is_camera = false;
    camera_id = 0;

    write_video = false;
    dst_video_fps = 24.;

    make_gray = false;

    resize_src = false;
    width = 640;
    height = 480;

    scale = 1.11;
    nlevels = 13;
    gr_threshold = 1;
    hit_threshold = 1.4;
    hit_threshold_auto = true;

    win_width = 64;
    win_stride_width = 8;
    win_stride_height = 8;

    gamma_corr = true;
}


Args Args::read(int argc, char** argv)
{
    Args args;
    for (int i = 1; i < argc; i++)
    {
        if (string(argv[i]) == "--make_gray") args.make_gray = (string(argv[++i]) == "true");
        else if (string(argv[i]) == "--resize_src") args.resize_src = (string(argv[++i]) == "true");
        else if (string(argv[i]) == "--width") args.width = atoi(argv[++i]);
        else if (string(argv[i]) == "--height") args.height = atoi(argv[++i]);
        else if (string(argv[i]) == "--hit_threshold")
        {
            args.hit_threshold = atof(argv[++i]);
            args.hit_threshold_auto = false;
        }
        else if (string(argv[i]) == "--scale") args.scale = atof(argv[++i]);
        else if (string(argv[i]) == "--nlevels") args.nlevels = atoi(argv[++i]);
        else if (string(argv[i]) == "--win_width") args.win_width = atoi(argv[++i]);
        else if (string(argv[i]) == "--win_stride_width") args.win_stride_width = atoi(argv[++i]);
        else if (string(argv[i]) == "--win_stride_height") args.win_stride_height = atoi(argv[++i]);
        else if (string(argv[i]) == "--gr_threshold") args.gr_threshold = atoi(argv[++i]);
        else if (string(argv[i]) == "--gamma_correct") args.gamma_corr = (string(argv[++i]) == "true");
        else if (string(argv[i]) == "--write_video") args.write_video = (string(argv[++i]) == "true");
        else if (string(argv[i]) == "--dst_video") args.dst_video = argv[++i];
        else if (string(argv[i]) == "--dst_video_fps") args.dst_video_fps = atof(argv[++i]);
        else if (string(argv[i]) == "--help") printHelp();
        else if (string(argv[i]) == "--video") { args.src = argv[++i]; args.src_is_video = true; }
        else if (string(argv[i]) == "--camera") { args.camera_id = atoi(argv[++i]); args.src_is_camera = true; }
        else if (args.src.empty()) args.src = argv[i];
        else throw runtime_error((string("unknown key: ") + argv[i]));
    }
    return args;
}


App::App(const Args& s)
{
    cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());

    args = s;
    cout << "\nControls:\n"
         << "\tESC - exit\n"
         << "\tm - change mode GPU <-> CPU\n"
         << "\tg - convert image to gray or not\n"
         << "\t1/q - increase/decrease HOG scale\n"
         << "\t2/w - increase/decrease levels count\n"
         << "\t3/e - increase/decrease HOG group threshold\n"
         << "\t4/r - increase/decrease hit threshold\n"
         << endl;

    use_gpu = true;
    make_gray = args.make_gray;
    scale = args.scale;
    gr_threshold = args.gr_threshold;
    nlevels = args.nlevels;

    if (args.hit_threshold_auto)
        args.hit_threshold = args.win_width == 48 ? 1.4 : 0.;
    hit_threshold = args.hit_threshold;

    gamma_corr = args.gamma_corr;
/*
    if (args.win_width != 64 && args.win_width != 48)
        args.win_width = 64;*/

    cout << "Scale: " << scale << endl;
    if (args.resize_src)
        cout << "Resized source: (" << args.width << ", " << args.height << ")\n";
    cout << "Group threshold: " << gr_threshold << endl;
    cout << "Levels number: " << nlevels << endl;
    cout << "Win width: " << args.win_width << endl;
    cout << "Win stride: (" << args.win_stride_width << ", " << args.win_stride_height << ")\n";
    cout << "Hit threshold: " << hit_threshold << endl;
    cout << "Gamma correction: " << gamma_corr << endl;
    cout << endl;
}


void App::run()
{

    FileStorage fs("/home/ubuntu/Desktop/implemenatation/vecSupport.yml", FileStorage::READ);

    vector<float> detector;
    int frameCount;
    fs["vector"] >> detector; 

    for (unsigned int i=0; i<detector.size(); i++)
    {
     std::cout << std::fixed << std::setprecision(10) << detector[i] << std::endl;
    }

    fs.release();

    running = true;
    cv::VideoWriter video_writer;

    Size win_size(96,64); //(64, 128) or (48, 96)
    Size win_stride(args.win_stride_width, args.win_stride_height);

    // Create HOG descriptors and detectors here
/*
    vector<float> detector;
    if (win_size == Size(64, 128))
        detector = cv::gpu::HOGDescriptor::getPeopleDetector64x128();
    else
        detector = cv::gpu::HOGDescriptor::getPeopleDetector48x96();*/


    cv::gpu::HOGDescriptor gpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9,
                                   cv::gpu::HOGDescriptor::DEFAULT_WIN_SIGMA, 0.2, gamma_corr,
                                   cv::gpu::HOGDescriptor::DEFAULT_NLEVELS);
    cv::HOGDescriptor cpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9, 1, -1,
                              HOGDescriptor::L2Hys, 0.2, gamma_corr, cv::HOGDescriptor::DEFAULT_NLEVELS);
    gpu_hog.setSVMDetector(detector);
    cpu_hog.setSVMDetector(detector);

    while (running)
    {
        VideoCapture vc;
        Mat frame;

        if (args.src_is_video)
        {
            vc.open(args.src.c_str());
            if (!vc.isOpened())
                throw runtime_error(string("can't open video file: " + args.src));
            vc >> frame;
        }
        else if (args.src_is_camera)
        {
            vc.open(args.camera_id);
            if (!vc.isOpened())
            {
                stringstream msg;
                msg << "can't open camera: " << args.camera_id;
                throw runtime_error(msg.str());
            }
            vc >> frame;
        }
        else
        {
            frame = imread(args.src);
            if (frame.empty())
                throw runtime_error(string("can't open image file: " + args.src));
        }

        Mat img_aux, img, img_to_show;
        gpu::GpuMat gpu_img;

        // Iterate over all frames
        while (running && !frame.empty())
        {
            workBegin();

            // Change format of the image
            if (make_gray) cvtColor(frame, img_aux, CV_BGR2GRAY);
            else if (use_gpu) cvtColor(frame, img_aux, CV_BGR2BGRA);
            else frame.copyTo(img_aux);

            // Resize image
            if (args.resize_src) resize(img_aux, img, Size(args.width, args.height));
            else img = img_aux;
            img_to_show = img;

            gpu_hog.nlevels = nlevels;
            cpu_hog.nlevels = nlevels;

            vector<Rect> found;

            // Perform HOG classification
            hogWorkBegin();
            if (use_gpu)
            {
                gpu_img.upload(img);
                gpu_hog.detectMultiScale(gpu_img, found, hit_threshold, win_stride,
                                         Size(0, 0), scale, gr_threshold);
            }
            else cpu_hog.detectMultiScale(img, found, hit_threshold, win_stride,
                                          Size(0, 0), scale, gr_threshold);
            hogWorkEnd();

            // Draw positive classified windows
            for (size_t i = 0; i < found.size(); i++)
            {
                Rect r = found[i];
                rectangle(img_to_show, r.tl(), r.br(), CV_RGB(0, 255, 0), 3);
            }

            if (use_gpu)
                putText(img_to_show, "Mode: GPU", Point(5, 25), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2);
            else
                putText(img_to_show, "Mode: CPU", Point(5, 25), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2);
            putText(img_to_show, "FPS (HOG only): " + hogWorkFps(), Point(5, 65), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2);
            putText(img_to_show, "FPS (total): " + workFps(), Point(5, 105), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2);
            imshow("opencv_gpu_hog", img_to_show);

            if (args.src_is_video || args.src_is_camera) vc >> frame;

            workEnd();

            if (args.write_video)
            {
                if (!video_writer.isOpened())
                {
                    video_writer.open(args.dst_video, CV_FOURCC('x','v','i','d'), args.dst_video_fps,
                                      img_to_show.size(), true);
                    if (!video_writer.isOpened())
                        throw std::runtime_error("can't create video writer");
                }

                if (make_gray) cvtColor(img_to_show, img, CV_GRAY2BGR);
                else cvtColor(img_to_show, img, CV_BGRA2BGR);

                video_writer << img;
            }

            handleKey((char)waitKey(3));
        }
    }
}


void App::handleKey(char key)
{
    switch (key)
    {
    case 27:
        running = false;
        break;
    case 'm':
    case 'M':
        use_gpu = !use_gpu;
        cout << "Switched to " << (use_gpu ? "CUDA" : "CPU") << " mode\n";
        break;
    case 'g':
    case 'G':
        make_gray = !make_gray;
        cout << "Convert image to gray: " << (make_gray ? "YES" : "NO") << endl;
        break;
    case '1':
        scale *= 1.11;
        cout << "Scale: " << scale << endl;
        break;
    case 'q':
    case 'Q':
        scale /= 1.11;
        cout << "Scale: " << scale << endl;
        break;
    case '2':
        nlevels++;
        cout << "Levels number: " << nlevels << endl;
        break;
    case 'w':
    case 'W':
        nlevels = max(nlevels - 1, 1);
        cout << "Levels number: " << nlevels << endl;
        break;
    case '3':
        gr_threshold++;
        cout << "Group threshold: " << gr_threshold << endl;
        break;
    case 'e':
    case 'E':
        gr_threshold = max(0, gr_threshold - 1);
        cout << "Group threshold: " << gr_threshold << endl;
        break;
    case '4':
        hit_threshold+=0.25;
        cout << "Hit threshold: " << hit_threshold << endl;
        break;
    case 'r':
    case 'R':
        hit_threshold = max(0.0, hit_threshold - 0.25);
        cout << "Hit threshold: " << hit_threshold << endl;
        break;
    case 'c':
    case 'C':
        gamma_corr = !gamma_corr;
        cout << "Gamma correction: " << gamma_corr << endl;
        break;
    }
}


inline void App::hogWorkBegin() { hog_work_begin = getTickCount(); }

inline void App::hogWorkEnd()
{
    int64 delta = getTickCount() - hog_work_begin;
    double freq = getTickFrequency();
    hog_work_fps = freq / delta;
}

inline string App::hogWorkFps() const
{
    stringstream ss;
    ss << hog_work_fps;
    return ss.str();
}


inline void App::workBegin() { work_begin = getTickCount(); }

inline void App::workEnd()
{
    int64 delta = getTickCount() - work_begin;
    double freq = getTickFrequency();
    work_fps = freq / delta;
}

inline string App::workFps() const
{
    stringstream ss;
    ss << work_fps;
    return ss.str();
}

Problem:

I am not able to detect anything. Can someone look at my work and can let me know what I am doing wrong. Any suggestions would be valuable. Thank you. From last four weeks I am doing these steps over and over again.

P.S: You can find yaml files here and test images along with the annotations here

shah
  • 311
  • 3
  • 20
  • what do you mean by "cvsvm is correctly classifying the new data" in combination with "I am not able to detect anything" ... which "new data" do you correctly classify while not detecting?!? Can you show sample images you used for training and sample images where you try to detect? – Micka Sep 01 '15 at 13:42
  • In the first code I obtained the HOG features for a `car` from a test image and HOG features of a negative images from my test image and it is correctly classifying the `car` and `noncar` using predict function of cvsvm. @Micka – shah Sep 01 '15 at 13:46
  • you mean your training is able to classify the input you used for training? Get more training data and only use half of it for training, use the rest for testing the generalization ability. When generalization is ok, then you might try to detect in new data. – Micka Sep 01 '15 at 13:48
  • yeah that is what I am doing. I also able to correctly classify the object for the test images which I didn't include for training. Can you please elaborate _Get more training data and only use half of it for training, use the rest for testing the generalization ability_ @Micka – shah Sep 01 '15 at 13:51
  • how many training images did you use and how many test images did you use that were not used in training? Can you post some of those training images, some of those test images and some images you failed to detect? – Micka Sep 01 '15 at 13:54
  • I used 200 training images and these 200 images contain **34** `rear car` and similarly I get the negative samples by randomly drawing the rectangle and check for the collision with the cars. Then for testing purposes I only used one test image for positive and negative classification to see if it is correctly classifying the new data. I am uploading the images for you along with annotations @Micka – shah Sep 01 '15 at 13:59
  • 1
    I have uploaded the test images along with annotations @Micka – shah Sep 01 '15 at 14:07
  • I am waiting for suggestions @Micka – shah Sep 01 '15 at 14:20
  • did you try to only use 17 rear cars for training and test the classifier on the other 17 ones (instead of only 1) + several images without rear cars? Not sure whether the error is in your training or in your detection algorithm. Can you reduce the detection algorithm to a minimum? (cpu version and no user input etc - only loading images from video/files)? – Micka Sep 01 '15 at 14:24
  • Yeah I can do that. @Micka – shah Sep 01 '15 at 14:48
  • Did you checked @Micka – shah Sep 02 '15 at 12:07
  • I tried your provided `vecSupport.yml` file loading, but `cpu_hog.setSVMDetector(detector);` failed (crashed) for that data on my system. Can you provide a minimum working sample (main function) with fixed parameter values: 1. load svm data from file, 2. create HoGDetector, 3. setSVMDetector – Micka Sep 02 '15 at 12:15
  • can you please check the path of `FileStorage fs("/home/ubuntu/Desktop/implemenatation/vecSupport.yml", FileStorage::READ);` on your computer because if you don't provide the correct path `setSVMDetector` would fail. @Micka – shah Sep 02 '15 at 12:21
  • Today I did the same process again but no luck. :( @Micka – shah Sep 02 '15 at 12:26
  • I'm using the right path. detector vector variable holds 69300 values after file reading. I'm getting error "assertion failed (checkDetectorSize()) ..." so I guess that the vector size doesn't match the win/block/cell sizes?!? I'm using `cv::Size win_size(96,64);` and `cv::HOGDescriptor cpu_hog(win_size, cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8),9);` before the `cpu_hog.setSVMDetector(detector);` can you confirm those values or present me working values? – Micka Sep 02 '15 at 12:35
  • in contrast, `cv::Size win_size(64,128); detector = cv::HOGDescriptor::getDefaultPeopleDetector(); cv::HOGDescriptor cpu_hog(win_size, cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8),9); cpu_hog.setSVMDetector(detector);` works without error – Micka Sep 02 '15 at 12:39
  • can you use this file. It is working for me [https://www.dropbox.com/s/83q2q5q2umj6qqh/test1.yml?dl=0] @Micka – shah Sep 02 '15 at 12:43
  • ok, using `vecSupport` doesnt work, so I tried using `test.yml` but I had to change a typo in that file you provided (`vector` instead of `dector`). .setSVM works, now I'll continue testing, but not just now... – Micka Sep 02 '15 at 12:44
  • I apologize for that. The file structure represent my messed up mind. Now use `test1.yml` and mapping key is `detector` – shah Sep 02 '15 at 12:46
  • using that file and calling .detectMultiscale I'll get plenty of detections in one Lenna image. Are you really detecting "nothing" or just nothing right? – Micka Sep 02 '15 at 12:48
  • you can can image 000003.png, 000037.png or 000095 for testing @Micka – shah Sep 02 '15 at 12:49
  • hit threshold is set to zero that's why you getting that. If you increase the hit threshold there is no detection – shah Sep 02 '15 at 12:52
  • what threshold should be chosen? according to http://docs.opencv.org/modules/gpu/doc/object_detection.html#gpu-hogdescriptor-detect it should be given in the trained data (and parameter set to zero)... so probably that parameter depends on the actual training?!? – Micka Sep 02 '15 at 13:01
  • 1
    But: rear view vehicles aren't detected at all, so most probably, the training isn't so well. May I ask how you do it? I think the win_size of (96,64) doesnt make much sense, because front/rear view vehicles are more like quadratic?!? From my intuition it should be done like this: 1. read from your labels the information where a car is in the image. 2. crop and scale (uniform in all directions) that part of the image so that it is 96x64 pixels sized. 3. compute HoG for that cropped and resized car. 4. collect those samples for many cars and many negatives. 5. use svm on those samples. – Micka Sep 02 '15 at 13:09
  • Can you please check the first code block that I posted in the question. I used that method for training @Micka – shah Sep 02 '15 at 13:09
  • you don't compute any HoG in that training part?!? – Micka Sep 02 '15 at 13:10
  • yeah as I computed the HOG feature of a complete and then from the label information I fetch the features for the object (rear car) and features of the randomly drawn square( I do checked for the collision if case there is a care) and then I fed these positive and negative features to the cvsvm. my supervisor asked me to do this way. @Micka – shah Sep 02 '15 at 13:16
  • Should I share you more data how I did it? @Micka – shah Sep 02 '15 at 13:24
  • was the label part scaled/cropped the right way? Otherwise I don't see how the detector windows will match the trained positives... but I'm neither expert for HoG nor for SVM, so that's just my intuition... – Micka Sep 02 '15 at 13:24
  • I calculated the HOG features for blocks only for 13 levels based on the scale of 1.11. You can see the answer of my post [http://stackoverflow.com/questions/31158790/hog-features-for-blocks-only] – shah Sep 02 '15 at 13:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88584/discussion-between-micka-and-shah). – Micka Sep 02 '15 at 13:36
  • Did you checked the traditional procedure. @Micka – shah Sep 04 '15 at 09:12
  • can I get some of your time please @Micka – shah Sep 04 '15 at 12:57
  • I have the results @Micka – shah Sep 07 '15 at 13:36
  • great, how did you do it? – Micka Sep 07 '15 at 13:37
  • Here you can see it. [https://www.dropbox.com/s/os0xbjuux87gd1b/Screenshot%20from%202015-09-07%2000%3A26%3A09.png?dl=0] – shah Sep 07 '15 at 13:51
  • There was a mistake in the pipeline when I calculate the HOG features for a complete image and save it to yml file it places a negative sign in front of each feature value. I adpoted the same procedure that we discussed in the group. Do you have some time? @Micka – shah Sep 07 '15 at 13:55

1 Answers1

1

First of all, partition your data for cross-validation as suggested already. Second thing is that it is a good idea to use RBF kernel rather than Linear kernel. I highly doubt that a linear kernel can learn complex objects. A brief explanation is given here. Finally, experiment with the parameters. To do that, you need to check the limits of the parameter space, it's been a while since I haven't used SVMs therefore I cannot provide any details but a grid search with 20% cross-validation is a good start.

karttinen
  • 122
  • 8