ncnn:提取所有层特征值

官方代码托管地址:https://github.com/Tencent/ncnn

在Extractor类中添加以下方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int Extractor::extract_all_blobs()
{
    for (int blob_index = 0; blob_index < blob_mats.size(); blob_index++)
    {
      Mat outMat;
      extract(blob_index, outMat);
 
      // write to file
      char path[256];
      char id[8];
 
      strcpy(path, "./ncnn_blobs_data/");
      sprintf(id, "%d", blob_index);
      strcat(path, id);
      strcat(path, ".txt");
 
      FILE *fp = fopen(path, "w+");
      if(!fp)
        fprintf(stderr, "error open file\n");
 
      // header
      fprintf(fp, net->blobs[blob_index].name.c_str());
      fprintf(fp, "\n");
 
      for (int idx = 0; idx < outMat.w * outMat.h * outMat.c; idx++)
        fprintf(fp, "%f\n", outMat[idx]);
      fclose(fp);
    }
 
    return 0;
}

  

posted @   Pepetang  阅读(805)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示