-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb.py
38 lines (34 loc) · 1.06 KB
/
b.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
import os
from sklearn.preprocessing import StandardScaler
import PIL.Image
import cv2
from PIL import Image
from matplotlib import pyplot
import numpy
from sklearn.neural_network import MLPClassifier
import joblib
path = os.getcwd()
digits = []
lables = []
basewide = 50
for index in range(0,11):
os.chdir(path + '/data/{}'.format(index))
print(os.getcwd())
#print(os.listdir())
for counter in range(0,101):
image = Image.open('{}.jpg'.format(counter))
img = image.resize((19,15), PIL.Image.Resampling.LANCZOS)
digits.append([pixel for pixel in iter(img.getdata())])
lables.append(index)
digit_ary = numpy.array(digits)
#print(digit_ary.shape)
scalar = StandardScaler()
scalar.fit(digit_ary)
x_scalar = scalar.transform(digit_ary)
mlp = MLPClassifier(activation='logistic',max_iter=10000)
mlp.fit(x_scalar,lables)
predicted = mlp.predict(x_scalar)
target = numpy.array(lables)
print('模型得分:{:.2f}'.format(mlp.score(x_scalar,target)))
os.chdir("path")
joblib.dump(mlp, 'kaptcha.pkl')