forked from fb1h2s/captcha-cracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaptcha_cracker.py
43 lines (30 loc) · 1.03 KB
/
captcha_cracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import glob
import os
import CaptchaCracker as cc
class CaptchaModel:
def __init__(self):
self.current_dir = os.path.dirname(os.path.abspath(__file__))
self.weights_path = os.path.join(self.current_dir, "models", "weights.h5")
self.img_width = 130
self.img_height = 35
self._learn()
img_length = 6
img_char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
self.apply_model = cc.ApplyModel(
self.weights_path,
self.img_width,
self.img_height,
img_length,
img_char,
)
def _learn(self):
img_path_list = glob.glob(os.path.join(self.current_dir, "samples", "*.png"))
model = cc.CreateModel(
img_path_list,
self.img_width,
self.img_height,
).train_model(epochs=128)
model.save_weights(self.weights_path)
def predict_from_bytes(self, buffer):
prediction = self.apply_model.predict_from_bytes(buffer)
return prediction