2
0
forked from s444420/AL-2020

fun created

This commit is contained in:
shaaqu 2020-05-20 07:36:18 +02:00
parent f1ce998628
commit ddb652119b
2 changed files with 37 additions and 33 deletions

View File

@ -3,27 +3,29 @@ from PIL import Image
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import cv2 import cv2
img = cv2.cvtColor(cv2.imread('test.jpg'), cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img, (15, 15), 0) # poprawia jakosc
img = cv2.resize(img, (8, 8), interpolation=cv2.INTER_AREA)
print(type(img)) def image():
print(img.shape) img = cv2.cvtColor(cv2.imread('test.jpg'), cv2.COLOR_BGR2GRAY)
print(img) img = cv2.GaussianBlur(img, (15, 15), 0) # poprawia jakosc
plt.imshow(img ,cmap='binary') img = cv2.resize(img, (8, 8), interpolation=cv2.INTER_AREA)
plt.show()
data = [] print(type(img))
print(img.shape)
print(img)
plt.imshow(img, cmap='binary')
plt.show()
rows, cols = img.shape data = []
for i in range(rows):
for j in range(cols):
k = img[i, j]
if k > 200:
k = 0 # brak czarnego
else:
k = 1
data.append(k) rows, cols = img.shape
for i in range(rows):
for j in range(cols):
k = img[i, j]
if k > 200:
k = 0 # brak czarnego
else:
k = 1
print(data) data.append(k)
print(data)

View File

@ -6,22 +6,24 @@ from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score from sklearn.metrics import accuracy_score
from PIL import Image from PIL import Image
#recznie napisane cyfry
digits = datasets.load_digits()
y = digits.target def train():
x = digits.images.reshape((len(digits.images), -1)) # recznie napisane cyfry
digits = datasets.load_digits()
x_train = x[:1000000] y = digits.target
y_train = y[:1000000] x = digits.images.reshape((len(digits.images), -1))
x_test = x[1000:]
y_test = y[1000:]
mlp = MLPClassifier(hidden_layer_sizes=(15,), activation='logistic', alpha=1e-4, x_train = x[:1000000]
solver='sgd', tol=1e-4, random_state=1, y_train = y[:1000000]
learning_rate_init=.1, verbose=True) x_test = x[1000:]
y_test = y[1000:]
mlp.fit(x_train, y_train) mlp = MLPClassifier(hidden_layer_sizes=(15,), activation='logistic', alpha=1e-4,
solver='sgd', tol=1e-4, random_state=1,
learning_rate_init=.1, verbose=True)
predictions = mlp.predict(x_test) mlp.fit(x_train, y_train)
print(accuracy_score(y_test, predictions))
predictions = mlp.predict(x_test)
print(accuracy_score(y_test, predictions))