March 2020
Intermediate to advanced
366 pages
9h 8m
English
OpenCV provides all the training and predicting methods, so we have to figure out how to format our data to fit the OpenCV requirements.
First, we split the data into train/test, and featurize the training data, as follows:
train, test = train_test_split(len(data), 0.8) x_train, pca_args = pca_featurize(np.array(data)[train])
Here, pca_args are the arguments that we will need to store if we wanted to featurize any future data (for example, live frames during the demo).
Because the train method of the cv2.ANN_MLP module does not allow integer-valued class labels, we need to first convert y_train into one-hot encoding, consisting only of 0s and 1s, which can then be fed to the train method, as follows:
encoded_targets, index_to_label ...