Skip to content
This repository was archived by the owner on Jan 20, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from transform import Transform

print('1 - Train\n2 - Test')
x = int(raw_input('Option:'))
x = int(input('Option:'))

if x is 1:
NeuralNetwork()
Expand Down
15 changes: 9 additions & 6 deletions src/nn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'''base da classe neuralnetwork'''
import tensorflow as tf
import numpy as np
import time
#
from dataset.train import *
import convert
import neural
import test
from .dataset.train import *
from . import neural
from . import test

class NeuralNetwork:
def __init__(self):
Expand All @@ -15,14 +15,17 @@ def __init__(self):

print('desfrdgthygju', len(data_input))

[to_train, to_test, res_to_train, res_to_test] = convert.dataset_matrix_to_lists(data_input, data_output, 75, 30)
[to_train,
to_test,
res_to_train,
res_to_test] = convert.dataset_matrix_to_lists(data_input, data_output, 75, 30)

for x in range(0, 1):
[epoch, err] = neural.train(to_train, res_to_train)
print('epoch:', epoch, 'mse:', err)
if err < target:
test_success = test_success + 1
test.test_neural(epoch, to_test, res_to_test);
test.test_neural(epoch, to_test, res_to_test)

print('time', time.time() - start)
print('success ', test_success)
Expand Down
12 changes: 8 additions & 4 deletions src/nn/confusion.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
''' '''
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
#
import convert
from . import convert

def build_matrix_array(matrix, desired_results, obtained_results):
''' D '''
for position in range(0, len(desired_results)):
#
desired = int(convert.convert_binary_to_int(desired_results[position]))
Expand All @@ -16,9 +18,11 @@ def build_matrix_array(matrix, desired_results, obtained_results):
return matrix

def confusion_matrix_graphic(array):
df_cm = pd.DataFrame(array, index = [i for i in '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'],
columns = [i for i in '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
plt.figure(figsize = (10,7))
''' creates confusion matrix graphic '''
df_cm = pd.DataFrame(array,
index=[i for i in '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'],
columns=[i for i in '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
plt.figure(figsize=(10, 7))
sn.heatmap(df_cm, annot=True)
# Display matrix
plt.matshow(array)
Expand Down
13 changes: 10 additions & 3 deletions src/nn/convert.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import numpy as np
''' # convert the shit ou of here! '''

# convert the shit ou of here!
# only 6bits
import numpy as np


def convert_binary_to_int(binary_value):

result = binary_value[5] * 1 + binary_value[4] * 2 + binary_value[3] * 4 + binary_value[2] * 8 + binary_value[1] * 16 + binary_value[0] * 32
result = (binary_value[5] * 1
+ binary_value[4] * 2
+ binary_value[3] * 4
+ binary_value[2] * 8
+ binary_value[1] * 16
+ binary_value[0] * 32)

if result < 36 and result > -1:
return result
Expand Down
25 changes: 13 additions & 12 deletions src/nn/dataset/train.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from numbers.zero import *
from numbers.one import *
from numbers.two import *
from numbers.three import *
from numbers.four import *
from numbers.five import *
from numbers.six import *
from numbers.seven import *
from numbers.eight import *
from numbers.nine import *
''' Train data into a input and a output '''
from .numbers.zero import *
from .numbers.one import *
from .numbers.two import *
from .numbers.three import *
from .numbers.four import *
from .numbers.five import *
from .numbers.six import *
from .numbers.seven import *
from .numbers.eight import *
from .numbers.nine import *
#
from chars.ca import *
from chars.cb import *
from .chars.ca import *
from .chars.cb import *

data_input = [
input_zero,
Expand Down
4 changes: 2 additions & 2 deletions src/nn/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tensorflow as tf
import numpy as np
#
import confusion
from . import confusion

meta_graph_src = './nn/tmp/my_test_model.meta'
checkpoint_src = './nn/tmp'
Expand All @@ -21,7 +21,7 @@ def test_neural(epoch, data_input, data_output):

with tf.Session() as sess:
saver = tf.train.import_meta_graph(meta_graph_src)
saver.restore(sess,tf.train.latest_checkpoint(checkpoint_src))
saver.restore(sess, tf.train.latest_checkpoint(checkpoint_src))
graph = tf.get_default_graph()
w1 = sess.run(graph.get_tensor_by_name("w1:0"))
b1 = sess.run(graph.get_tensor_by_name("b1:0"))
Expand Down
15 changes: 12 additions & 3 deletions src/transform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ def __init__(self):

# make it black and white
gray = col.convert('L')
bw = gray.point(lambda x: 0 if x<128 else 255, '1')
bw = gray.point(lambda x: 0 if x < 128 else 255, '1')

# get transformed data
pixels = list(bw.getdata())
width, height = bw.size

# make a matrix
pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]
pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]

# update values
pixels = [[1. if pixels[i][g] == 0 else 0. for g in xrange(width)] for i in xrange(height)]
pixels = [[1. if pixels[i][g] == 0 else 0. for g in range(width)] for i in range(height)]
pixels2 = [[' ' if pixels[i][g] == 0 else '@' for g in range(width)] for i in range(height)]


print('Matriz Resultado:')

for h in range(0, len(pixels)):
print(pixels[h])

print('Matriz visual:')

for h in range(0, len(pixels2)):
print(pixels2[h])

# test with trained neural network

def __del__(self):
Expand Down