diff --git a/coder/image.py b/coder/image.py index 9f832ee..50114d1 100644 --- a/coder/image.py +++ b/coder/image.py @@ -3,27 +3,29 @@ from PIL import Image import matplotlib.pyplot as plt 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)) -print(img.shape) -print(img) -plt.imshow(img ,cmap='binary') -plt.show() +def image(): + 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) -data = [] + print(type(img)) + print(img.shape) + print(img) + plt.imshow(img, cmap='binary') + plt.show() -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 + data = [] - 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) \ No newline at end of file + data.append(k) + + print(data) diff --git a/coder/train.py b/coder/train.py index f659b20..4c8abd1 100644 --- a/coder/train.py +++ b/coder/train.py @@ -6,22 +6,24 @@ from sklearn.neural_network import MLPClassifier from sklearn.metrics import accuracy_score from PIL import Image -#recznie napisane cyfry -digits = datasets.load_digits() -y = digits.target -x = digits.images.reshape((len(digits.images), -1)) +def train(): + # recznie napisane cyfry + digits = datasets.load_digits() -x_train = x[:1000000] -y_train = y[:1000000] -x_test = x[1000:] -y_test = y[1000:] + y = digits.target + x = digits.images.reshape((len(digits.images), -1)) -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) + x_train = x[:1000000] + y_train = y[:1000000] + 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) -print(accuracy_score(y_test, predictions)) + mlp.fit(x_train, y_train) + + predictions = mlp.predict(x_test) + print(accuracy_score(y_test, predictions))