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 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)
data.append(k)
print(data)

View File

@ -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))