Esempio n. 1
0
fc_layer_t* make_fc_layer(int in_sx, int in_sy, int in_depth,
                          int num_neurons) {
  fc_layer_t* l = (fc_layer_t*)malloc(sizeof(fc_layer_t));

  // required
  l->out_depth = num_neurons;
  l->in_depth = in_depth;
  l->in_sx = in_sx;
  l->in_sy = in_sy;
    
  // optional
  l->l1_decay_mul = 0.0;
  l->l2_decay_mul = 1.0;

  // computed
  l->num_inputs = l->in_sx * l->in_sy * l->in_depth;
  l->out_sx = 1;
  l->out_sy = 1;

  l->filters = (vol_t**)malloc(sizeof(vol_t*)*num_neurons);
  for (int i = 0; i < l->out_depth; i++) {
    l->filters[i] = make_vol(1, 1, l->num_inputs, 0.0);
  }

  l->bias = 0.0;
  l->biases = make_vol(1, 1, l->out_depth, l->bias);

  return l;
}
Esempio n. 2
0
conv_layer_t* make_conv_layer(int in_sx, int in_sy, int in_depth,
                              int sx, int filters, int stride, int pad) {
  conv_layer_t* l = (conv_layer_t*)malloc(sizeof(conv_layer_t));

  // required
  l->out_depth = filters;
  l->sx = sx;
  l->in_depth = in_depth;
  l->in_sx = in_sx;
  l->in_sy = in_sy;
    
  // optional
  l->sy = l->sx;
  l->stride = stride;
  l->pad = pad;
  l->l1_decay_mul = 0.0;
  l->l2_decay_mul = 1.0;

  // computed
  l->out_sx = floor((l->in_sx + l->pad * 2 - l->sx) / l->stride + 1);
  l->out_sy = floor((l->in_sy + l->pad * 2 - l->sy) / l->stride + 1);

  l->filters = (vol_t**)malloc(sizeof(vol_t*)*filters);
  for (int i = 0; i < filters; i++) {
    l->filters[i] = make_vol(l->sx, l->sy, l->in_depth, 0.0);
  }

  l->bias = 0.0;
  l->biases = make_vol(1, 1, l->out_depth, l->bias);

  return l;
}
Esempio n. 3
0
int main() {

  unsigned int cpt = 0, i;

  /* init hardware */
  if(!init_hardware(HW_CONFIG)){
    perror("Initialization error\n");
    exit(EXIT_FAILURE);
  }

  /* Interreupt handlers */
  for(i=0; i<16; i++)
    IRQVECTOR[i] = empty_it;

  /* Allows all IT */
  _mask(1);

  /* chargement du mbr */
  if(!load_mbr()){
    perror("Erreur lors du chargement du Master Boot Record.");
    exit(EXIT_FAILURE);
  }

  /* creation d'un volume bidon */
  if(!make_vol(1, 1, 10)) {
    perror("Erreur a la creation d'un volume bidon.");
    exit(EXIT_FAILURE);
  }

  /* initialise le super du premier volume */
  init_super(CURRENT_VOLUME);

  /* charge le super du premier volume dans la variable globale */
  load_super(CURRENT_VOLUME);

  /* creation de nouveau bloc jusqu'a ce qu'il y est une erreur */
  while(new_bloc());

  if(is_full()) {
    free_bloc(2);
    free_bloc(5);
    free_bloc(6);

    printf("nombre de bloc libre = %d\n", get_nb_free_bloc());

    while(new_bloc()) cpt++;

    printf("le nombre de bloc alloué est %d\n", cpt);
				
  } else {
    printf("le disque n'est pas encore rempli\n");
  }

  exit(EXIT_SUCCESS);
}
Esempio n. 4
0
batch_t* make_batch(network_t* old_net, int size) {
  batch_t* out = (batch_t*)malloc(sizeof(vol_t**)*(LAYERS+1));
  for (int i = 0; i < LAYERS+1; i++) {
    out[i] = (vol_t**)malloc(sizeof(vol_t*)*size);
    for (int j = 0; j < size; j++) {
      out[i][j] = make_vol(old_net->v[i]->sx, old_net->v[i]->sy, old_net->v[i]->depth, 0.0);
    }
  }

  return out;
}
Esempio n. 5
0
// Load an entire batch of images from the gtsrb data set (which is divided
// into 5 batches with 10,000 images each).
void load_gtsrb_data(vol_t** data, label_t* label, int size) {
  fprintf(stderr, "Loading Data \n");

  assert(size <= 7830);  // the size must be smaller than 7830
  
  FILE *meanf = fopen("data/gtsrb/mean.binaryproto","rb");
  float mean_buffer[6912];
  FILE *dataf = fopen("data/gtsrb/test.bin","rb");
  uint8_t data_buffer[6913];
  FILE *aftrf = fopen("data/gtsrb/gtsrb_after_mean.bin","rb");
  float aftr_buffer[6912];
  FILE *lablf = fopen("data/gtsrb/gtsrb_test_labels.bin","rb");

  assert(fread(mean_buffer,1,12,meanf) == 12);
  assert(fread(mean_buffer,sizeof(float),6912,meanf) == 6912);

  fclose(meanf);

//  assert(fread(label,sizeof(uint8_t),size,lablf) == size);

  for (int i = 0; i < size; i++) {
    int outp = 0;
    data[i] = make_vol(48, 48, 3, 0.0);

    assert(fread(data_buffer,sizeof(uint8_t),6913,dataf) == 6913);
    label[i] = data_buffer[0];

    for (int z = 0; z < 3; z++)
      for (int y = 0; y < 48; y++)
        for (int x = 0; x < 48; x++) {
          set_vol(data[i], y, x, z, (storage_t)data_buffer[outp+1]
                                    -(storage_t)mean_buffer[outp]);
          outp++;
        }

//    assert(fread(aftr_buffer,sizeof(float),6912,aftrf) == 6912);
//
//    for (int z = 0; z < 3; z++)
//      for (int y = 0; y < 48; y++)
//        for (int x = 0; x < 48; x++) {
//          set_vol(data[i], y, x, z, (storage_t)aftr_buffer[outp++]);
//        }
  }
  
  fclose(dataf);
  fclose(aftrf);
  fclose(lablf);

  fprintf(stderr, "input batch loaded successfully \n");
}
Esempio n. 6
0
int main(int argc, char**argv){

  unsigned int i;
  unsigned fc = 0;
  unsigned fs = 1;
  unsigned nb_bloc = 10;

  /* init hardware */
  if(!init_hardware(HW_CONFIG)) {
    fprintf(stderr, "Initialization error\n");
    exit(EXIT_FAILURE);
  }

  /* Interreupt handlers */
  for(i=0; i<NB_EMPTY_FUNCTION; i++)
    IRQVECTOR[i] = empty_it;

  /* Allows all IT */
  _mask(1);

  /* chargement du mbr */
  if(!load_mbr()){
    fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n");
    exit(EXIT_FAILURE);
  }

  if(mbr.mbr_n_vol < 1) {

    /* creation d'un volume bidon */
    if(!make_vol(fc, fs, nb_bloc)) {
      fprintf(stderr, "Erreur a la creation d'un volume bidon.\n");
      exit(EXIT_FAILURE);
    }

    /* initialise le super du volume 1 */
    init_super(CURRENT_VOLUME);

    printf("Le volume principale a été créé avec succès.\n");

    /* sauvegarde de tous les changements effectué sur le mbr */
    save_mbr();
  } else {
    printf("Le volume principale a déjà été créé!\n");
  }

  exit(EXIT_SUCCESS);
}
Esempio n. 7
0
network_t* make_network() {
  network_t* net = (network_t*)malloc(sizeof(network_t));
  net->v[0] = make_vol(32, 32, 3, 0.0);
  net->l0 = make_conv_layer(32, 32, 3, 5, 16, 1, 2);
  net->v[1] = make_vol(net->l0->out_sx, net->l0->out_sy, net->l0->out_depth, 0.0);
  net->l1 = make_relu_layer(net->v[1]->sx, net->v[1]->sy, net->v[1]->depth);
  net->v[2] = make_vol(net->l1->out_sx, net->l1->out_sy, net->l1->out_depth, 0.0);
  net->l2 = make_pool_layer(net->v[2]->sx, net->v[2]->sy, net->v[2]->depth, 2, 2);
  net->v[3] = make_vol(net->l2->out_sx, net->l2->out_sy, net->l2->out_depth, 0.0);
  net->l3 = make_conv_layer(net->v[3]->sx, net->v[3]->sy, net->v[3]->depth, 5, 20, 1, 2);
  net->v[4] = make_vol(net->l3->out_sx, net->l3->out_sy, net->l3->out_depth, 0.0);
  net->l4 = make_relu_layer(net->v[4]->sx, net->v[4]->sy, net->v[4]->depth);
  net->v[5] = make_vol(net->l4->out_sx, net->l4->out_sy, net->l4->out_depth, 0.0);
  net->l5 = make_pool_layer(net->v[5]->sx, net->v[5]->sy, net->v[5]->depth, 2, 2);
  net->v[6] = make_vol(net->l5->out_sx, net->l5->out_sy, net->l5->out_depth, 0.0);
  net->l6 = make_conv_layer(net->v[6]->sx, net->v[6]->sy, net->v[6]->depth, 5, 20, 1, 2);
  net->v[7] = make_vol(net->l6->out_sx, net->l6->out_sy, net->l6->out_depth, 0.0);
  net->l7 = make_relu_layer(net->v[7]->sx, net->v[7]->sy, net->v[7]->depth);
  net->v[8] = make_vol(net->l7->out_sx, net->l7->out_sy, net->l7->out_depth, 0.0);
  net->l8 = make_pool_layer(net->v[8]->sx, net->v[8]->sy, net->v[8]->depth, 2, 2);
  net->v[9] = make_vol(net->l8->out_sx, net->l8->out_sy, net->l8->out_depth, 0.0);
  net->l9 = make_fc_layer(net->v[9]->sx, net->v[9]->sy, net->v[9]->depth, 10);
  net->v[10] = make_vol(net->l9->out_sx, net->l9->out_sy, net->l9->out_depth, 0.0);
  net->l10 = make_softmax_layer(net->v[10]->sx, net->v[10]->sy, net->v[10]->depth);
  net->v[11] = make_vol(net->l10->out_sx, net->l10->out_sy, net->l10->out_depth, 0.0);
  return net;
}