コード例 #1
0
ファイル: test_net.c プロジェクト: xindongzhang/deepnet-dsp
void test_net_state()
{
  printf("test net state\n");
  //-----------------------------------------------------//
  Array* net = new_net(7);
  Layer    * layer0 = new_conv_layer(5,5,1,20, 0,0,1,1);
  Layer    * layer1 = new_pool_layer(MaxPooling_T, 2,2, 0,0,2,2);
  Layer    * layer2 = new_conv_layer(5,5,20,50, 0,0,1,1);
  Layer    * layer3 = new_pool_layer(MaxPooling_T, 2,2, 0,0,2,2);
  Layer    * layer4 = new_conv_layer(4,4,50,500, 0,0,1,1);
  Layer    * layer5 = new_activate_layer(Relu_T);
  Layer    * layer6 = new_conv_layer(1,1,500,10, 0,0,1,1);
  net_add(net, layer0, del_layer);
  net_add(net, layer1, del_layer);
  net_add(net, layer2, del_layer);
  net_add(net, layer3, del_layer);
  net_add(net, layer4, del_layer);
  net_add(net, layer5, del_layer);
  net_add(net, layer6, del_layer);
  //-----------------------------------------------------//
  NetState* state = new_net_state(net->length);
  net_state_init(state, 28, 28, 1, 1);
  net_setup(state, net);
  net_state_print(state);
  net_forward(state, net);
  del_net_state(state);
  del_net(net);
}
コード例 #2
0
ファイル: cnn.c プロジェクト: cs61c-spring2015/proj3_starter
void net_classify_cats(network_t* net, vol_t** input, double* output, int n) {
  batch_t* batch = make_batch(net, 1);

  for (int i = 0; i < n; i++) {
    copy_vol(batch[0][0], input[i]);
    net_forward(net, batch, 0, 0);
    output[i] = batch[11][0]->w[CAT_LABEL]; 
  }

  free_batch(batch, 1);
}
コード例 #3
0
ファイル: cnn.c プロジェクト: MicBrain/Image-Classifier
void net_classify_cats(network_t* net, vol_t** input, double* output, int n) {
  

  #pragma omp parallel for
  for (int i = 0; i < n; i+=8) {
    batch_t* batch = make_batch(net, 8);
    copy_vol(batch[0][0], input[i]);
    copy_vol(batch[0][1], input[i+1]);
    copy_vol(batch[0][2], input[i+2]);
    copy_vol(batch[0][3], input[i+3]);
    copy_vol(batch[0][4], input[i + 4]);
    copy_vol(batch[0][5], input[i + 5]);
    copy_vol(batch[0][6], input[i + 6]);
    copy_vol(batch[0][7], input[i + 7]);

    net_forward(net, batch, 0, 7);
    output[i] = batch[11][0]->w[CAT_LABEL]; 
    output[i + 1] = batch[11][1]->w[CAT_LABEL]; 
    output[i + 2] = batch[11][2]->w[CAT_LABEL];
    output[i + 3] = batch[11][3]->w[CAT_LABEL]; 
    output[i + 4] = batch[11][4]->w[CAT_LABEL]; 
    output[i + 5] = batch[11][5]->w[CAT_LABEL];
    output[i + 6] = batch[11][6]->w[CAT_LABEL];
    output[i + 7] = batch[11][7]->w[CAT_LABEL];
    free_batch(batch, 1);
  }
  double time0 = (double)net->l0->myTime;
  double time1 = (double)net->l1->myTime;
  double time2 = (double)net->l2->myTime;
  double time3 = (double)net->l3->myTime;
  double time4 = (double)net->l4->myTime;
  double time5 = (double)net->l5->myTime;
  double time6 = (double)net->l6->myTime;
  double time7 = (double)net->l7->myTime;
  double time8 = (double)net->l8->myTime;
  double time9 = (double)net->l9->myTime;
  double time10 = (double)net->l10->myTime;

  double totalTime = time0 + time1+ time2 + time3 + time4 + time5 + time6 + time7 + time8 + time9 + time10;
  printf("%s %lf %s %lf \n","conv_layer1 in ms is ", time0/1000,"and of total time is ", time0/totalTime);
  printf("%s %lf %s %lf \n","relu layer1", time1/1000, "and of total time is ",time1/totalTime *100);
  printf("%s %lf %s %lf \n","pool layer1", time2/1000, "and of total time is",time2/totalTime*100);
  printf("%s %lf %s %lf \n","conv_layer2", time3/1000, "and of total time is",time3/totalTime*100);
  printf("%s %lf %s %lf \n","relu layer2", time4/1000, "and of total time is",time4/totalTime*100);
  printf("%s %lf %s %lf \n","pool layer2", time5/1000, "and of total time is",time5/totalTime*100);
  printf("%s %lf %s %lf \n","conv_layer3", time6/1000, "and of total time is",time6/totalTime*100);
  printf("%s %lf %s %lf \n","relu layer3", time7/1000, "and of total time is",time7/totalTime*100);
  printf("%s %lf %s %lf \n","pool layer3", time8/1000, "and of total time is",time8/totalTime*100);
  printf("%s %lf %s %lf \n","fc layer", time9/1000, "and of total time is",time9/totalTime*100);
  printf("%s %lf %s %lf \n","softmax layer", time10/1000, "and of total time is",time10/totalTime*100);

  double convTime = time0 + time3 + time6;
  double reluTime = time1 + time4 + time7;
  double poolTime = time2 + time5 + time8;
  double fc_layer = time9;
  double softmax_layer_t = time10;
  
  printf("%s %lf \n","Time spent in conv_layer is ", convTime/totalTime *100);
  printf("%s %lf \n","Time spent in reluTime is ", reluTime/totalTime*100);
  printf("%s %lf \n","Time spent in poolTime is ", poolTime/totalTime*100);
  printf("%s %lf \n","Time spent in fc_layer is ", fc_layer/totalTime*100);
  printf("%s %lf \n","Time spent in softmax_layer_t is ", softmax_layer_t/totalTime*100);
  
}