caffe 保存blob值到txt,方便查看和pytorch比较
在blob.hpp添加函数:
void save_data_to_txt(const string path_txt, bool b_save_shape = true)
{
std::ofstream fOut(path_txt);
if (!fOut)
{
std::cout << "Open output file faild." << std::endl;
}
if(b_save_shape)
{
for(int i=0;i<shape_.size();i++)
{
fOut << shape_[i];
if(i == shape_.size()-1)
{
fOut<<std::endl;
}else
{fOut<<",";
}
}
}
const float* data_vec = cpu_data<float>();
for (int i = 0; i < count_; ++i) {
fOut << data_vec[i] << std::endl;
}
fOut.close();
}
会在本地生成blob值,如下示例:
1,2,3,9
0.296902
0.219784
0.411638
0.260122
0.381804
0.226767
0.34326
0.431977
0.442307
0.494072
0.328519
0.396156
0.480086
0.379205
0.577999
0.436218
0.503253
0.458271
0.49964
0.202944
0.267732
0.188421
0.293444
好记性不如烂键盘---点滴、积累、进步!