rightAnswers = np.array([[0, 1]]) elif 6 < number < 16 or number == 17: rightAnswers = np.array([[1, 1]]) elif number == 0 or number == 16: rightAnswers = np.array([[0, 0]]) # print('rightAnswers = ', rightAnswers) image = cv2.imread("dataset/test/" + str(number) + ".png", 0).flatten() / 255 if pro == 15 and i % 25 == 0: ppi = np.vstack((ppi, n.train(image, rightAnswers).T)) plt.clf() plt.xlabel(i * 17) plt.plot(ppi) plt.draw( ) # Должно быть это, а в итоге не это, приходится каждый раз открывать картинку plt.pause(0.0000000000000000000001) else: n.train(image, rightAnswers) plt.title('lr = ' + str(learning_rate)) plt.ioff() plt.show() for i in range(18): image = cv2.imread("dataset/test/" + str(i) + ".png", 0).flatten() / 255 print(n.query(image)) np.save('./weights/example_1', n.synaptic_weight1) np.save('./weights/example_2', n.synaptic_weight2)
from Network import NeuralNetwork import cv2 import numpy as np import matplotlib.pyplot as plt n = NeuralNetwork(9, 5, 2, 0.3) n.synaptic_weight1 = np.load('./weights/example_1.npy') n.synaptic_weight2 = np.load('./weights/example_2.npy') image = cv2.imread("dataset/test/test2.0.png", 0) inputs = image.flatten() inputs = np.asfarray(inputs / 255.0 * 0.99) + 0.01 answers = n.query(inputs) print(str(answers[0]) + str(answers[1])) plt.imshow(image) plt.xlabel('test2.0.png') plt.title(str(answers[0]) + ' -- ' + str(answers[1])) plt.show() for i in range(18): image = cv2.imread("dataset/test/" + str(i) + ".png", 0) inputs = image.flatten() inputs = np.asfarray(inputs / 255.0 * 0.99) + 0.01 answers = n.query(inputs) print(str(answers[0]) + str(answers[1]))