mini-caffe:提取所有层特征值

官方代码托管地址:https://github.com/luoyetx/mini-caffe

在Net类中增加以下方法:

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
32
33
34
35
36
37
const int Net::extract_all_blobs() const {
  for(int blob_idx = 0; blob_idx < blobs_.size(); blob_idx++) {
    shared_ptr<Blob> blob_ptr = blobs_[blob_idx];
    const float *pData = blob_ptr->cpu_data();
 
      // write to file
      char path[256];
      char id[8];
 
      strcpy(path, "./minicaffe_blobs_data/");
      sprintf(id, "%d", blob_idx);
      strcat(path, id);
      strcat(path, ".txt");
 
      FILE *fp = fopen(path, "w+");
      if(!fp)
        fprintf(stderr, "error open file\n");
 
      // header
      //\ value to key
      char blob_name[256];
      for (auto iter : blob_names_index_)
        if (iter.second == blob_idx){
          strcpy(blob_name, iter.first.c_str());
          break;
        }
 
      fprintf(fp, blob_name);
      fprintf(fp, "\n");
 
      for (int w = 0; w < blob_ptr->count(); w++)
        fprintf(fp, "%f\n", pData[w]);
      fclose(fp);
  }
 
  return 0;
}

  

posted @   Pepetang  阅读(333)  评论(0编辑  收藏  举报
编辑推荐:
· 理解Rust引用及其生命周期标识(下)
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
阅读排行:
· 2025成都.NET开发者Connect圆满结束
· 后端思维之高并发处理方案
· 千万级大表的优化技巧
· 在 VS Code 中,一键安装 MCP Server!
· 10年+ .NET Coder 心语 ── 继承的思维:从思维模式到架构设计的深度解析
点击右上角即可分享
微信分享提示