-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectf.py
More file actions
40 lines (35 loc) · 1.06 KB
/
detectf.py
File metadata and controls
40 lines (35 loc) · 1.06 KB
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
import networkf as network
import mnist_loader
import numpy as np
import matplotlib.pyplot as plt
import cv2
from PIL import Image
# imgc = Image.open('num2.jpg')
# nimgc = imgc.resize((28,28))
# nimgc.save('numtest.jpg')
# img.show()
img_org = cv2.imread('numtest.jpg')
img_gray = cv2.cvtColor(img_org, cv2.COLOR_BGR2GRAY)
(thresh, img_bw) = cv2.threshold(img_gray, 172, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
plt.imshow(img_bw)
plt.show()
print(thresh)
# print(type(img_gray))
# print((np.shape(img_gray)))
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
training_data_l = [x for x in training_data]
test_data_l = [x for x in test_data]
img = np.reshape(img_bw,(784,1))
net = network.Network([784, 15, 10])
w = np.load('trainedw.npy', allow_pickle=True)
b = np.load('trainedb.npy', allow_pickle=True)
net.biases = b
net.weights = w
# net.SGD(training_data_l, 30, 10, 10.0, test_data=test_data_l)
res = net.feedforward(img)
print(res)
print(np.argmax(res))
# print((np.shape(img)))
# plt.subplot(1,1,1)
# plt.imshow(img_gray)
# plt.show()