Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Create a layer for artificial neural network of openCV2

According to this blog, it create the labels as this way

    cv::Mat layers = cv::Mat(4, 1, CV_32SC1); //create 4 layers

    layers.row(0) = cv::Scalar(2); //input layer accepts x and y
    layers.row(1) = cv::Scalar(10);//hidden layer
    layers.row(2) = cv::Scalar(15);//hidden layer
    layers.row(3) = cv::Scalar(1); //output layer returns 1 or -1

But in the book, it create the layers as following

Mat layers(1,3,CV_32SC1);
layers.at<int>(0)= TrainData.cols;
layers.at<int>(1)= nlayers;
layers.at<int>(2)= numCharacters;

1 : The blog use rows to save the parameters but the book use cols to save the parameters.Are they the same thing?Do I have to change the way of writing, reading the xml according to the way of saving the parameters(any issues I do not mention have to take care)?

2 : What is the order of the layers?As I guess

  1. The feature numbers of each sample
  2. number of layers
  3. ~ Last(assume 4 == last in this case) - 1
  4. Classes(The kinds of data want to classify. ex : '0', '1', ..., '9')

Create a layer for artificial neural network of openCV2

According to this blog, it create the labels as this way

    cv::Mat layers = cv::Mat(4, 1, CV_32SC1); //create 4 layers

    layers.row(0) = cv::Scalar(2); //input layer accepts x and y
    layers.row(1) = cv::Scalar(10);//hidden layer
    layers.row(2) = cv::Scalar(15);//hidden layer
    layers.row(3) = cv::Scalar(1); //output layer returns 1 or -1

But in the book, it create the layers as following

Mat layers(1,3,CV_32SC1);
layers.at<int>(0)= TrainData.cols;
layers.at<int>(1)= nlayers;
layers.at<int>(2)= numCharacters;

1 : The blog use rows to save the parameters but the book use cols to save the parameters.Are they the same thing?Do I have to change the way of writing, reading the xml according to the way of saving the parameters(any issues I do not mention have to take care)?

2 : What is the order of the layers?As I guessguess(uncertain)

  1. The feature numbers of each sample
  2. number of layers
  3. ~ Last(assume 4 == last in this case) - 1
  4. Classes(The kinds of data want to classify. ex : '0', '1', ..., '9')
click to hide/show revision 3
retagged

updated 2013-10-28 03:52:42 -0600

berak gravatar image

Create a layer for artificial neural network of openCV2

According to this blog, it create the labels as this way

    cv::Mat layers = cv::Mat(4, 1, CV_32SC1); //create 4 layers

    layers.row(0) = cv::Scalar(2); //input layer accepts x and y
    layers.row(1) = cv::Scalar(10);//hidden layer
    layers.row(2) = cv::Scalar(15);//hidden layer
    layers.row(3) = cv::Scalar(1); //output layer returns 1 or -1

But in the book, it create the layers as following

Mat layers(1,3,CV_32SC1);
layers.at<int>(0)= TrainData.cols;
layers.at<int>(1)= nlayers;
layers.at<int>(2)= numCharacters;

1 : The blog use rows to save the parameters but the book use cols to save the parameters.Are they the same thing?Do I have to change the way of writing, reading the xml according to the way of saving the parameters(any issues I do not mention have to take care)?

2 : What is the order of the layers?As I guess(uncertain)

  1. The feature numbers of each sample
  2. number of layers
  3. ~ Last(assume 4 == last in this case) - 1
  4. Classes(The kinds of data want to classify. ex : '0', '1', ..., '9')