commit 59271da9ceb7ddaa2475d924d0a763b9d8a450d9
parent 1f3f753317f0f5e2699b27a64fbff9e32d5e82af
Author: David Freifeld <freifeld.david@gmail.com>
Date: Wed, 1 Jul 2020 16:17:15 -0700
Some W&B tweaks
Diffstat:
4 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/bpnn.cpp b/bpnn.cpp
@@ -274,8 +274,6 @@ float Network::test(char* path)
void Network::train(int total_epochs)
{
- float epoch_cost = 1000;
- float epoch_accuracy = -1;
int epochs = 0;
//printf("Beginning train on %i instances for %i epochs...\n", instances, total_epochs);
double batch_time = 0;
@@ -293,18 +291,22 @@ void Network::train(int total_epochs)
batches++;
//t++;
}
- epoch_accuracy = 1.0/((float) instances/batch_size) * acc_sum;
- epoch_acc = epoch_accuracy;
+ epoch_acc = 1.0/((float) instances/batch_size) * acc_sum;
epoch_cost = 1.0/((float) instances/batch_size) * cost_sum;
- printf("Epoch %i/%i - cost %f - acc %f\n", epochs+1, total_epochs, epoch_cost, epoch_accuracy);
+ printf("Epoch %i/%i - cost %f - acc %f\n", epochs+1, total_epochs, epoch_cost, epoch_acc);
batches=1;
epochs++;
rewind(data);
}
}
-float Network::get_info()
+float Network::get_acc()
{
return epoch_acc;
}
+
+float Network::get_cost()
+{
+ return epoch_cost;
+}
diff --git a/bpnn.hpp b/bpnn.hpp
@@ -39,6 +39,7 @@ public:
int t;
float epoch_acc;
+ float epoch_cost;
float learning_rate;
float bias_lr;
int batch_size;
@@ -62,7 +63,8 @@ public:
float test(char* path);
void train(int total_epochs);
- float get_info();
+ float get_acc();
+ float get_cost();
};
void demo(int total_epochs);
diff --git a/example.py b/example.py
@@ -4,20 +4,30 @@ import numpy
import time
batch_sz = 10
-layers = 1
+layers = 2
+epochs = 50
+lr = 0.0155
+bias_lr = 0.03
+neurons = 3
-net = mrbpnn.Network("./data_banknote_authentication.txt", batch_sz, 0.0155, 0.03)
+net = mrbpnn.Network("./data_banknote_authentication.txt", batch_sz, lr, bias_lr)
net.add_layer(4, "linear")
for i in range(layers):
- net.add_layer(5, "relu")
+ net.add_layer(neurons, "lecun_tanh")
net.add_layer(1, "resig")
net.initialize()
import wandb
wandb.init(project="jacobian")
-wandb.config.update({"epochs": 50, "batch_size": batch_sz, "hidden_layers": layers})
-for i in range(50):
+wandb.config.update({"epochs": epochs,
+ "batch_size": batch_sz,
+ "learning_rate": lr,
+ "bias_lr": bias_lr,
+ "hidden_layers": layers,
+ "activation":"lecun_tanh",
+ "neurons": neurons})
+for i in range(epochs):
net.train(1)
- wandb.log({'accuracy': net.get_info()})
+ wandb.log({'accuracy': net.get_acc(), 'cost': net.get_cost()})
wandb.save('jacobian.h5')
diff --git a/mr_bpnn_2.cpp b/mr_bpnn_2.cpp
@@ -119,5 +119,6 @@ PYBIND11_MODULE(mrbpnn, m) {
.def("update_layer", &Network::update_layer, py::arg("vals"), py::arg("len"), py::arg("index"))
.def("next_batch", &Network::next_batch)
.def("train", &Network::train, py::arg("epochs"))
- .def("get_info", &Network::get_info);
+ .def("get_acc", &Network::get_acc)
+ .def("get_cost", &Network::get_cost);
}