From 2be628552507f6b7413ac7360fd28157c3af7a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Hamy?= Date: Sun, 10 Feb 2019 20:52:19 +0100 Subject: [PATCH] Added support for json load of params in train Updated gitignore --- .gitignore | 3 +++ loulou.py | 2 ++ scripts/ffl.py | 2 +- scripts/train.py | 22 ++++++++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 loulou.py diff --git a/.gitignore b/.gitignore index 510c73d..6f1e0b0 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Others +testimage.png diff --git a/loulou.py b/loulou.py new file mode 100644 index 0000000..a94446f --- /dev/null +++ b/loulou.py @@ -0,0 +1,2 @@ +import scripts.train as train +import scripts.run as run diff --git a/scripts/ffl.py b/scripts/ffl.py index 056dd9e..5e7cf03 100644 --- a/scripts/ffl.py +++ b/scripts/ffl.py @@ -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): diff --git a/scripts/train.py b/scripts/train.py index 16fabd0..6fbe3e9 100644 --- a/scripts/train.py +++ b/scripts/train.py @@ -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)