X-Git-Url: https://piware.de/gitweb/?p=handwriting-recognition.git;a=blobdiff_plain;f=train.py;h=b294ce1dba98765e2a1559f200a221eb54c96513;hp=5ff76669709f1d2a9549dd25b1f16a7b4c97f632;hb=d986cacf7fc94fb78904f01e11128d666efff804;hpb=72f90468f63b736bca28d0fc5ebf3f7d1989de4f diff --git a/train.py b/train.py index 5ff7666..b294ce1 100755 --- a/train.py +++ b/train.py @@ -14,9 +14,9 @@ nnet_batch = 10000 # (input)--> [Linear->Sigmoid] -> [Linear->Sigmoid] -->(output) # handle 10,000 vectors at a time Z1 = nnet.LinearLayer(input_shape=(rows * cols, nnet_batch), n_out=80) -A1 = nnet.SigmoidLayer(Z1.Z.shape) -ZO = nnet.LinearLayer(input_shape=A1.A.shape, n_out=10) -AO = nnet.SigmoidLayer(ZO.Z.shape) +A1 = nnet.SigmoidLayer(Z1.shape) +ZO = nnet.LinearLayer(input_shape=A1.shape, n_out=10) +AO = nnet.SigmoidLayer(ZO.shape) net = (Z1, A1, ZO, AO) res = nnet.forward(net, test_images[:, 0:10000]) @@ -28,7 +28,7 @@ print(f'correctly recognized images after initialization: {nnet.accuracy(net, te train_y = nnet.label_vectors(train_labels, 10) for i in range(100): for batch in range(0, num_train, nnet_batch): - cost = nnet.train(net, train_images[:, batch:(batch + nnet_batch)], train_y[:, batch:(batch + nnet_batch)], learning_rate=1) + cost = nnet.train(net, train_images[:, batch:(batch + nnet_batch)], train_y[:, batch:(batch + nnet_batch)], learning_rate=(100-i)/100) print(f'cost after training round {i}: {cost}') print(f'correctly recognized images after training: {nnet.accuracy(net, test_images, test_labels)}%')