Captcha is image generated by chars randomly and proper voice to avoid the attack from the robot. Example captcha:
We can easily generate the captcha by the python package captcha.See the captcha_generator.py in details.
We can download the captcha from the Rosreestr website and process it using the rename_captcha function in rosreestr.py
I build the network with TensorFlow. We increase the neural network with each following symbol
# 3 conv layer
input_img = tf.keras.layers.Input(shape=IMG_SHAPE)
output_code = []
out = tf.keras.layers.Convolution2D(16, (3, 3), padding='same', activation='relu')(input_img)
out = tf.keras.layers.MaxPooling2D(padding='same')(out)
out = tf.keras.layers.Convolution2D(32, (3, 3), padding='same', activation='relu')(out)
out = tf.keras.layers.Convolution2D(32, (3, 3), padding='same', activation='relu')(out)
out = tf.keras.layers.MaxPooling2D(padding='same')(out)
out = tf.keras.layers.Convolution2D(64, (3, 3), padding='same', activation='relu')(out)
out = tf.keras.layers.Convolution2D(64, (3, 3), padding='same', activation='relu')(out)
out = tf.keras.layers.BatchNormalization()(out)
out = tf.keras.layers.MaxPooling2D(padding='same')(out)
out = tf.keras.layers.Flatten()(out)
for _ in range(NUM_CODE_CHARACTERS):
dense = tf.keras.layers.Dense(64, activation='relu')(out)
dropout = tf.keras.layers.Dropout(0.4)(dense)
prediction = tf.keras.layers.Dense(ALL_CHARS_LEN, activation='sigmoid')(dropout)
output_code.append(prediction)
For python captcha, i use 100 000 training samples and 5 000 test samples. After 150 epochs of training, the model obtains the correct rate of 75.62% on the test data.
For Rosreestr, i use 3 000 training samples and 200 test samples. After 60 epochs of training, the model obtains the correct rate of 88% on the test data.