Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Multiple Changes to the CNN implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Harnick Khera authored and Harnick Khera committed Aug 8, 2018
1 parent 5e49b60 commit 11d66fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
50 changes: 26 additions & 24 deletions Ki/Core/ConvolutionNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,58 @@

import numpy as np

def ConvolutionNetwork():
class ConvolutionNetwork():

Layers = []
LayerTypes = []
Activations = []
NumberOutputs = 0
InputSize = []
Fitness = 0

#get the hyper parameters ready
def __init__(self, _LayerSizes, _LayerTypes, _NumberOutputs):
def __init__(self, _LayerSizes, _LayerTypes, _InputSize, _NumberOutputs):

self.Layers = []
self.LayerTypes = []
self.Activations = []
self.Fitness = 0
self.NumberOutputs = _NumberOutputs
self.InputSize = _InputSize

self.CreateNetwork(_LayerSizes, _LayerTypes)

#need to make this more dynamic...
def CreateNetwork(self, _LayerSizes, _LayerTypes):

Layer1 = []
Layer2 = []
Layer3 = []
Layer4 = []
Layer5 = []
Layer6 = []
def AddLayers(self, FilterSize=[3,3], NumberFilters=8, NumberLayers=2):

for i in range(32):
for i in range(NumberLayers):
Layer = []

Layer1.append(Filter())

Layer2.append(Pooling())
for i in range(NumberFilters):
Layer.append(Filter(FilterSize))

for i in range(32):

Layer3.append(Filter())
self.Layers.append(Layer)
self.LayerTypes.append(0)

Layer4.append(Pooling())
Layer = [Pooling()]
self.Layers.append(Layer)
self.LayerTypes.append(1)

#Dynamically add Filter and Pooling Layers
def CreateNetwork(self, _LayerSizes, _LayerTypes):

for i in range(self.NumberOutputs):

Layer6.append(Node())
for i in range(2):
self.AddLayers([3+i,3+i], 16, 1)



def CalculateNumberNeurons(self):

zeros = np.zeros(self.InputSize)

#for i in range(self.LayerTypes):




CNN = ConvolutionNetwork(0,0, [256,256], 3)



Expand Down
8 changes: 4 additions & 4 deletions Ki/Core/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class Filter():
FilterSize = []
Stride = []
Padding = []
OutData = []

def __init__(self, _FilterSize=[3,3], _Stride=[1,1], _Padding=[1,1,1,1]):

self.FilterSize = _FilterSize
self.Stride = _Stride
self.Padding = _Padding

self.OutData = []
self.Filter = np.random.uniform(low =-1, high=1, size=[self.FilterSize[0], self.FilterSize[1]])

#Apply a filter to some input data
Expand Down Expand Up @@ -53,7 +54,7 @@ def ApplyActivation(self, Data):
for i in range(Data.shape[0]):
for j in range(Data.shape[1]):
Data[i,j] = a.Relu(Data[i,j])

'''
#Test Data of a Cube
data = [[1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,1],
Expand Down Expand Up @@ -84,7 +85,6 @@ def ApplyActivation(self, Data):


'''


6 changes: 4 additions & 2 deletions Ki/Core/Pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
class Pooling():

WindowSize = [2,2]
OutData = []

def __init__(self, _WindowSize=[2,2]):

self.WindowSize = _WindowSize
self.OutData = []

def MaxPoolData(self, Data):

Expand All @@ -35,7 +37,7 @@ def MaxPoolData(self, Data):
def Flatten(self, data):

return np.ravel(data)
'''
#Test Data of a Cube
data = [[1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,1],
Expand All @@ -54,5 +56,5 @@ def Flatten(self, data):
pooled2 = pool.MaxPoolData(pooled)
flat = pool.Flatten(pooled2)

'''

0 comments on commit 11d66fc

Please sign in to comment.