Skip to content

Commit

Permalink
Added support for json load of params in train
Browse files Browse the repository at this point in the history
Updated gitignore
  • Loading branch information
aunetx committed Feb 10, 2019
1 parent 552384e commit 2be6285
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Others
testimage.png
2 changes: 2 additions & 0 deletions loulou.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import scripts.train as train
import scripts.run as run
2 changes: 1 addition & 1 deletion scripts/ffl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def grads(X, Y, weights):
grads[i-1] = a[i-1].T.dot(delta) # calculating errors of weights and storing onto |grads|
return grads / len(X)

def train(weights, trX, trY, teX, teY, filename=False, epochs=30, batch=20, learning_rate=0.03):
def train(weights, trX, trY, teX, teY, filename, epochs, batch, learning_rate):
prediction = np.argmax(feed_forward(teX, weights)[-1], axis=1)
print(0, np.mean(prediction == np.argmax(teY, axis=1)))
for i in range(epochs):
Expand Down
22 changes: 18 additions & 4 deletions scripts/train.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import mnist
from ffl import *
import json

if __name__ == '__main__':
filename = 'four layers.npy'
filename = '../trains/' + filename
def runTrain(params, file='trained.npy'):
params = json.loads(params)
epochs = params['epochs']
batch = params['batch']
learning_rate = params['learning_rate']
file = '../trains/' + file
trX, trY, teX, teY = mnist.load_data()
weights = [np.random.randn(*w) * 0.1 for w in [(784, 400), (400,200), (200,100), (100, 10)]]
train(weights, trX, trY, teX, teY, filename=filename, epochs=0)
train(weights, trX, trY, teX, teY, 'trained.npy', epochs, batch, learning_rate)

if __name__ == '__main__':
params = {}
params['epochs'] = 30
params['batch'] = 20
params['learning_rate'] = 0.03
params = json.dumps(params)

filename = 'trained.npy'
runTrain(params, file=filename)

0 comments on commit 2be6285

Please sign in to comment.