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

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

在Net类中增加以下方法:

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;
}

  

转载于:https://www.cnblogs.com/pepetang/p/11347532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值