Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

to use a neural network ,

  • decide on the layout of the net :

    1. how many inputs do i want ? sending in a HD image with a million pixels is not reasonable, so you have to rescale it , reduce to grayscale, etc.
    2. it needs hidden layers. start with one, do tests, increase if nessecary.
    3. the number of outputs is the number of your classes
  • prepare the input data:

    1. the trainmatrix will be N rows (one per image) x M cols (number of pixels_per_image) you'll have to flatten your images to 1 row (reshape(1,1)), and convert to float, (probably normalize to [0..1]), finally assemble a Mat from those rows.
    2. the trainlabels, or responses will be a similar float Matrix with N rows (again, one per image) x M cols (the expected output layer per image) the highest 'score' per row should be for the expected classid

dummy example(5 images, 4 input pixels, 2 classes):

_data_      _labels_
2 4 5 3      0 1
4 3 2 3      0 1
1 1 5 1      1 0
1 2 5 3      1 0
1 2 2 2      1 0
  • now you can train your net, and save the trained state to xml/yml.
  • later, you can reload that, and do predictions on test images. you'll have to process them in the very same way as for the training, only difference is, you only got one row as input, and will receive one output row as result. the index of the highest score in that output is your predicted classid.