Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Approach to implement Multi class SVM classifier

I am trying to classify road signs which means i have classes and sub classes. For example i have a class for Speed sign limits and it includes sub classes (ex: 30 speed signs, 50 speed signs, 80 speed signs, etc...).

My problem what i am facing is how to proper model my system, i want to implement One vs All technique.

I already have implemented One class SVM as well as Multi class single SVM so i am not asking about how to code.

Should the model by like smth this:

For Red Speed limit signs super class i intialize one SVM and train it with more than one label that represents sub classes as a positives and put all the remaining data set as a negatives.

Then i intialize/create another instance of another SVM to represent another super class for an example lets say Blue Speed limit signs class, and so on?

In pseudo code would look like:

CvSVM svmClassONE = new CvSVM()
svmClassONE.train(redSigns,label(1,2,3,4),pos)
svmClassONE.train(!redSigns,label(0),neg)

CvSVM svmClassTWO = new CvSVM()
svmClassTWO.train(blueSigns,label(1,2,3,4),pos)
svmClassTWO.train(!blueSigns,label(0),neg)

Is that a proper way ? is it okay to create multiple instance of SVM's ?

I am using Java OpenCV btw Thanks

Approach to implement Multi class SVM classifier

I am trying to classify road signs which means i have classes and sub classes. For example i have a class for Speed sign limits and it includes sub classes (ex: 30 speed signs, 50 speed signs, 80 speed signs, etc...).

My problem what i am facing is how to proper model my system, i want to implement One vs All technique.

I already have implemented One class SVM as well as Multi class single SVM so i am not asking about how to code.

Should the model by like smth this:

For Red Speed limit signs super class i intialize one SVM and train it with more than one label that represents sub classes as a positives and put all the remaining data set as a negatives.

Then i intialize/create another instance of another SVM to represent another super class for an example lets say Blue Speed limit signs class, and so on?

In pseudo code would look like:

CvSVM svmClassONE = new CvSVM()
svmClassONE.train(redSigns,label(1,2,3,4),pos)
svmClassONE.train(!redSigns,label(0),neg)

CvSVM svmClassTWO = new CvSVM()
svmClassTWO.train(blueSigns,label(1,2,3,4),pos)
svmClassTWO.train(!blueSigns,label(0),neg)

Is that a proper way ? is it okay to create multiple instance of SVM's ?

I am using Java OpenCV btw Thanks

Approach to implement Multi class SVM classifier

I am trying to classify road signs which means i have classes and sub classes. For example i have a class for Speed sign limits and it includes sub classes (ex: 30 speed signs, 50 speed signs, 80 speed signs, etc...).

My problem what i am facing is how to proper model my system, i want to implement One vs All technique.

I already have implemented One class SVM as well as Multi class single SVM so i am not asking about how to code.

Should the model by like smth this:

For Red Speed limit signs super class i intialize one SVM and train it with more than one label that represents sub classes as a positives and put all the remaining data set as a negatives.

Then i intialize/create another instance of another SVM to represent another super class for an example lets say Blue Speed limit signs class, and so on?

In pseudo code would look like:

CvSVM svmClassONE = new CvSVM()
svmClassONE.train(redSigns,label(1,2,3,4),pos)
svmClassONE.train(!redSigns,label(0),neg)

CvSVM svmClassTWO = new CvSVM()
svmClassTWO.train(blueSigns,label(1,2,3,4),pos)
svmClassTWO.train(!blueSigns,label(0),neg)

Is that a proper way ? is it okay to create multiple instance of SVM's ?

I am using Java OpenCV btw Thanks

Approach to implement Multi class SVM classifier

I am trying to classify road signs which means i have classes and sub classes. For example i have a class for Speed sign limits and it includes sub classes (ex: 30 speed signs, 50 speed signs, 80 speed signs, etc...).

My problem what i am facing is how to proper model my system, i want to implement One vs All technique.

I already have implemented One class SVM as well as Multi class single SVM so i am not asking about how to code.

Should the model by be smth like smth this:

For Red Speed limit signs super class i intialize one SVM and train it with more than one label that represents sub classes as a positives and put all the remaining data set as a negatives.

Then i intialize/create another instance of another SVM to represent another super class for an example lets say Blue Speed limit signs class, and so on?

In pseudo code would look like:

CvSVM svmClassONE = new CvSVM()
svmClassONE.train(redSigns,label(1,2,3,4),pos)
svmClassONE.train(!redSigns,label(0),neg)

CvSVM svmClassTWO = new CvSVM()
svmClassTWO.train(blueSigns,label(1,2,3,4),pos)
svmClassTWO.train(!blueSigns,label(0),neg)

Is that a proper way ? is it okay to create multiple instance of SVM's ?

I am using Java OpenCV btw Thanks

Approach to implement Multi class SVM classifier

I am trying to classify road signs which means i have classes and sub classes. For example i have a class for Speed sign limits and it includes sub classes (ex: 30 speed signs, 50 speed signs, 80 speed signs, etc...).

My problem what i am facing is how to proper model my system, i want to implement One vs All technique.

I already have implemented One class SVM as well as Multi class single SVM so i am not asking about how to code.

Should the model be smth like this:

For Red Speed limit signs super class i intialize one SVM and train it with more than one label that represents sub classes as a positives and put all the remaining data set as a negatives.

Then i intialize/create another instance of another SVM to represent another super class for an example lets say Blue Speed limit signs class, and so on?

In pseudo code would look like:

CvSVM svmClassONE = new CvSVM()
svmClassONE.train(redSigns,label(1,2,3,4),pos)
svmClassONE.train(!redSigns,label(0),neg)

CvSVM svmClassTWO = new CvSVM()
svmClassTWO.train(blueSigns,label(1,2,3,4),pos)
svmClassTWO.train(!blueSigns,label(0),neg)

Is that a proper way ? is it okay to create multiple instance of SVM's ?

I am using Java OpenCV btw Thanks

UPDATE WITH CODE

for(int z = 1; z <= 3; z++) {

// Train positives

String p = "/Users/Desktop/ml/pos" + z; 
 File[] file = new File(p).listFiles();

 for(int i = 0; i < file.length; i++) {
  Mat img = Highgui.imread(file[i].getAbsolutePath(), Highgui.CV_LOAD_IMAGE_COLOR);
  Imgproc.resize(img, img, new Size(32,32));
  hog.compute(img, descriptors);

  trainingData.push_back(descriptors.reshape(1, 1));
  trainingLabels.push_back(new Mat(new Size(1,1),CvType.CV_32FC1,new Scalar(z)));
  }
 }

// Training Negatives

 File[] file2 = new File(PATH_NEGATIVE).listFiles();
 for(int i = 0; i < file2.length; i++) {
  Mat img = Highgui.imread(file2[i].getAbsolutePath(), Highgui.CV_LOAD_IMAGE_COLOR);
  Imgproc.resize(img, img, new Size(32,32));
  hog.compute(img, descriptors);

  trainingData.push_back(descriptors.reshape(1, 1));
  trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
 }