Creating an MLP classifier in OpenCV

The syntax to create an MLP in OpenCV is the same as for all the other classifiers:

In [4]: import cv2
... mlp = cv2.ml.ANN_MLP_create()

However, now we need to specify how many layers we want in the network and how many neurons there are per layer. We do this with a list of integers, which specify the number of neurons in each layer. Since the data matrix X has two features, the first layer should also have two neurons in it (n_input). Since the output has two different values, the last layer should also have two neurons in it (n_output).

In between these two layers, we can put as many hidden layers with as many neurons as we want. Let's choose a single hidden layer with an arbitrary number of 10 neurons in it (n_hidden):

In [5]: n_input = 2
... n_hidden = 10
... n_output = 2
... mlp.setLayerSizes(np.array([n_input, n_hidden, n_output]))

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.35.247