Blob Blame Raw

#include <ctime>
#include <cstdlib>

#include "nnlayer.inc.cpp"
#include "nnlayer.conv.inc.cpp"
#include "nnlayer.lnk.inc.cpp"
#include "nntrain.inc.cpp"


int main() {
  srand(time(NULL));

  const char *filename = "data/output/weights.bin"; // 28x28
  //const char *filename = "data/output/weights22.bin";

  printf("load training data\n");
  Trainer t(0.25);
  if (!t.loadSymbolMap("data/symbols-data.bin", 784, 10)) return 1;
  //if (!t.loadSymbolMap("data/symbols22-data.bin", 22*22, 10)) return 1;

  printf("create neural network\n");
  //Layer l(nullptr, 784);
  //new LayerSimple(l, 128);
  //new LayerSimple(l, 64);
  //new LayerSimple(l, 10);

  //Layer l(nullptr, 784);
  //new LayerConvolution<false, 6,2>(l, 12, 12, 4);
  //new LayerConvolution<false, 6,2>(l, 4, 4, 16);
  ////new LayerConvolution<false, 4>(l, 1, 1, 128);
  ////new LayerSimple(l, 64);
  //new LayerSimple(l, 10);

  //Layer l(nullptr, 784);
  //new LayerConvolution<false, 7>(l, 22, 22, 1);
  //new LayerConvolution<false, 9>(l, 14, 14, 1);
  //new LayerConvolution<false,11>(l, 4, 4, 1);
  //new LayerSimple(l, 10);

  Layer l(nullptr, 784);
  new LayerLinkConvolution(l, 28, 28, 1, 22, 22, 1,  60);
  new LayerLinkConvolution(l, 22, 22, 1, 14, 14, 1, 100);
  new LayerLinkConvolution(l, 14, 14, 1,  4,  4, 1, 140);
  new LayerSimple(l, 10);

  printf("  neurons: %d, links %d, memSize: %llu\n", l.totalSize(), l.totalLinks(), (unsigned long long)l.totalMemSize());

  //printf("try load previously saved network\n");
  //l.load(filename);

  printf("train\n");
  t.trainSimple(l, 1000, 0.5, 10000);
  //for(double q = 0.5; q > 0.05; q *= 0.5)
  //  t.trainBlock(l, 50, 20, q, 10000);
  //t.trainBlock(l, 50, 20, 0.5, 10000);
  //t.trainBlock(l, 10, 100, 0.5, 1);

  printf("save neural network weights\n");
  if (!l.save(filename)) return 1;

  return 0;
}