-
Notifications
You must be signed in to change notification settings - Fork 84
/
sigrecog.py
42 lines (33 loc) · 1.3 KB
/
sigrecog.py
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
38
39
40
41
42
import cv2
import os
import numpy as np
import network
import preprocessor
def main():
print('OpenCV version {} '.format(cv2.__version__))
current_dir = os.path.dirname(__file__)
author = '021'
training_folder = os.path.join(current_dir, 'data/training/', author)
test_folder = os.path.join(current_dir, 'data/test/', author)
training_data = []
for filename in os.listdir(training_folder):
img = cv2.imread(os.path.join(training_folder, filename), 0)
if img is not None:
data = np.array(preprocessor.prepare(img))
data = np.reshape(data, (901, 1))
result = [[0], [1]] if "genuine" in filename else [[1], [0]]
result = np.array(result)
result = np.reshape(result, (2, 1))
training_data.append((data, result))
test_data = []
for filename in os.listdir(test_folder):
img = cv2.imread(os.path.join(test_folder, filename), 0)
if img is not None:
data = np.array(preprocessor.prepare(img))
data = np.reshape(data, (901, 1))
result = 1 if "genuine" in filename else 0
test_data.append((data, result))
net = network.NeuralNetwork([901, 500, 500, 2])
net.sgd(training_data, 10, 50, 0.01, test_data)
if __name__ == '__main__':
main()