官方代码托管地址: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;
}