text: /*
  * EDDL Library - European Distributed Deep Learning Library.
  * Version: 0.7
  * copyright (c) 2020, Universidad Politécnica de Valencia (UPV), PRHLT Research Centre
  * Date: April 2020
  * Author: PRHLT Research Centre, UPV, (rparedes@prhlt.upv.es), (jon@prhlt.upv.es)
  * All rights reserved
  */
  
  #include <cstdio>
  #include <cstdlib>
  #include <iostream>
  
  #include "eddl/apis/eddl.h"
  
  
  using namespace eddl;
  
  //////////////////////////////////
  // mnist_mlp_regularizer.cpp:
  // A very basic MLP for mnist
  // Playing with regularizers
  // Using fit for training
  //////////////////////////////////
  
  int main(int argc, char **argv) {
  
      // Download mnist
      download_mnist();
  
      // Settings
      int epochs = 5;
      int batch_size = 100;
      int num_classes = 10;
  
      // Define network
      layer in = Input({784});
      layer l = in;  // Aux var
  
      l = ReLu(L2(Dense(l, 1024),0.0001));
      l = ReLu(L1(Dense(l, 1024),0.0001));
      l = ReLu(L1L2(Dense(l, 1024),0.00001,0.0001));
  
      layer out = Activation(Dense(l, num_classes), "softmax");
      model net = Model({in}, {out});
      net->verbosity_level = 0;
  
      // dot from graphviz should be installed:
      plot(net, "model.pdf");
  
      // Build model
      build(net,
            sgd(0.01, 0.9), // Optimizer
            {"soft_cross_entropy"}, // Losses
            {"categorical_accuracy"}, // Metrics
            CS_GPU({1}) // one GPU
            //CS_GPU({1,1},100) // two GPU with weight sync every 100 batches
            //CS_CPU()
  	      //CS_FPGA({1})
      );
  
      // View model
      summary(net);
  
      // Load dataset
      Tensor* x_train = Tensor::load("mnist_trX.bin");
      Tensor* y_train = Tensor::load("mnist_trY.bin");
      Tensor* x_test = Tensor::load("mnist_tsX.bin");
      Tensor* y_test = Tensor::load("mnist_tsY.bin");
  
      // Preprocessing
      x_train->div_(255.0f);
      x_test->div_(255.0f);
  
      // Train model
      fit(net, {x_train}, {y_train}, batch_size, epochs);
  
      // Evaluate
      evaluate(net, {x_test}, {y_test});
  
  }
  