Skip to content

Commit

Permalink
reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
sharababy committed May 14, 2018
1 parent 21ea47a commit 1bfdb69
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 21 deletions.
Binary file removed cifar/batches.meta
Binary file not shown.
Binary file removed cifar/data_batch_1
Binary file not shown.
Binary file removed cifar/data_batch_2
Binary file not shown.
Binary file removed cifar/data_batch_3
Binary file not shown.
Binary file removed cifar/data_batch_4
Binary file not shown.
Binary file removed cifar/data_batch_5
Binary file not shown.
1 change: 0 additions & 1 deletion cifar/readme.html

This file was deleted.

Binary file removed cifar/test_batch
Binary file not shown.
106 changes: 87 additions & 19 deletions net.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def unpickle(file):

classes = ["airplane","automobile","bird","cat","deer","dog","frog","horse","ship","truck"];

classcount = 10

p = 0

class NeuralNet:

def __init__(self):
Expand All @@ -18,33 +22,94 @@ def __init__(self):
np.random.ranf((10,1)) * np.random.ranf((1,10)),
np.random.ranf((10,1)) * np.random.ranf((1,10))]

def predictThis(self,image,c,correct):
out0 = np.matmul(self.layer[0] , image)
maxout0 = np.amax(out0)
out0 = [x/(maxout0+10) for x in out0]

pout1 = np.matmul(self.layer[1] , out0)
maxout1 = np.amax(pout1)
pout1 = [x/(maxout1+10) for x in pout1]

out2 = np.matmul(self.layer[2] , pout1)
maxout2 = np.amax(out2)
out2 = [x/(maxout2+10) for x in out2]

out2 = np.array(out2).ravel()


out3 = np.matmul(self.layer[3] , out2)
maxout3 = np.amax(out3)
out3 = [x/(maxout3+10) for x in out3]

# print(" predicted = ",np.argmax(out3)," class = ",c)

if(np.argmax(out3) == c):
correct+=1

return correct

def trainThis(self,image,c):
out1 = np.matmul(self.layer[0] , image)
out0 = np.matmul(self.layer[0] , image)
maxout0 = np.amax(out0)
out0 = [x/(maxout0+10) for x in out0]

out1 = np.matmul(self.layer[1] , out0)
maxout1 = np.amax(out1)
out1 = [x/(maxout1+10) for x in out1]

out2 = np.matmul(self.layer[2] , out1)
maxout2 = np.amax(out2)
out2 = [x/(maxout2+10) for x in out2]

out2 = np.array(out2).ravel()
out3 = np.matmul(self.layer[3] ,out2)
maxout3 = np.amax(out3)
out3 = [x/(maxout3+10) for x in out3]


ideal = np.zeros(10)
ideal.fill(0.1)
ideal[c] = 0.9

# print(" ideal: ",ideal)
# print(" error: ",error)
# print("Layer 4","\t\t\t","Error")
# [ print(out3[i],"\t\t",error[i]) for i in range(10) ]

# backprop for layer 3
layer3ideal = np.matmul(np.asmatrix(ideal).transpose(),np.asmatrix(out2))
l3diff = layer3ideal - self.layer[3]
self.layer[3] = self.layer[3] + (l3diff/5)

out1 = [x/10000 for x in out1]
out2 = np.matmul(self.layer[1] , out1)
out3 = np.matmul(self.layer[2] , out2)
out4 = np.matmul(self.layer[3] , out3)
out4 = [x/100 for x in out4]

# print(out1)
# print(out2)
# print(out3)
# print(out4)
print(" predicted = ",np.argmax(out4)," class = ",c)
print()
# ideal =
global p
p = net.predictThis(image,c,p)

return out4;
return out3;

def printLayer(self,n):
print(self.layer[n])


net = NeuralNet();

[net.trainThis(imgset[b'data'][i],imgset[b'labels'][i]) for i in range(10)]
trainCount = 1800

[net.trainThis(imgset[b'data'][i],imgset[b'labels'][i]) for i in range(trainCount)]

print("--------------------------------------------")
print("Now for the tests: ")

print(p)

correct = 0
total = 50

for i in range(2001,2001+total):
correct = net.predictThis(imgset[b'data'][i],imgset[b'labels'][i],correct)

print("\n\nAccuracy: ",correct,"/",total)


# print(flayer)
Expand All @@ -58,14 +123,17 @@ def printLayer(self,n):
# tp print image data
# print(imgset[b'data'])
[3072 x 3072][3072 x 1] = [3072 x 1] -- layer 1
[3072 x 3072][3072 x 1] = [3072 x 1] -- layer 0
[10 x 3072][3072 x 1] = [10 x 1] -- layer 2
[10 x 3072][3072 x 1] = [10 x 1] -- layer 1
[10 x 10][10 x 1] = [10 x 1] -- layer 3
[3072 x 10][10 x 1] = [3072 x 1]
[10 x 10][10 x 1] = [10 x 1] -- layer 4
[10 x 10][10 x 1] = [10 x 1] -- layer 2
[10 x 10] = [10 x 1] [10 x 1].T
[10 x 10][10 x 1] = [10 x 1] -- layer 3
[10 x 10] = [10 x 1] [1 x 10]t
'''

Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

4 changes: 4 additions & 0 deletions tf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

0 comments on commit 1bfdb69

Please sign in to comment.