jacobian

a basic keras-like neural network library for c++/python
Log | Files | Refs | README

example.cpp (1285B)


      1 #include "src/bpnn.hpp"
      2 #include "src/utils.hpp"
      3 #include "unistd.h"
      4 #include <ctime>
      5 #include <chrono>
      6 
      7 double bench(int batch_sz, int epochs)
      8 {
      9     auto start = std::chrono::high_resolution_clock::now();
     10     Jacobian::Network net ("./data_banknote_authentication.txt", batch_sz, 0.0155,
     11                            0.03, Jacobian::Regularization::L2, 0, 0.9);
     12     net.add_layer(4, Jacobian::activations::linear, Jacobian::activations::linear_deriv);
     13     net.add_layer(5, Jacobian::activations::lecun_tanh, Jacobian::activations::lecun_tanh_deriv);
     14     net.add_layer(2, Jacobian::activations::linear, Jacobian::activations::linear_deriv);
     15     net.init_optimizer(Jacobian::optimizers::momentum(0.1));
     16     net.initialize();
     17     for (int i = 0; i < epochs; i++) {
     18         net.train();
     19     }
     20     auto end = std::chrono::high_resolution_clock::now();
     21     return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() / pow(10,9);
     22 }
     23 
     24 int main(int argc, char** argv)
     25 {
     26     if (argc < 2) {
     27         std::cout << "usage: jacobian_cli [batch_size] [epoch] [time to sleep before starting]"      << "\n";
     28         exit(1);
     29     }
     30     else {
     31         sleep(strtol(argv[3], NULL, 10));
     32         std::cout << bench(strtol(argv[1], NULL, 10), strtol(argv[2], NULL, 10)) << "\n";
     33     }
     34 }