Now that we have a classifier for predicting individual letters, we now move onto the next step in our plan - predicting words. To do this, we want to predict each letter from each of these segments, and put those predictions together to form the predicted word from a given CAPTCHA.
Our function will accept a CAPTCHA and the trained neural network, and it will return the predicted word:
def predict_captcha(captcha_image, neural_network): subimages = segment_image(captcha_image) # Perform the same transformations we did for our training data dataset = np.array([np.resize(subimage, (20, 20)) for subimage in subimages]) X_test = dataset.reshape((dataset.shape[0], dataset.shape[1] * dataset.shape[2])) # Use predict_proba and ...