测试caffe安装成功_用VSCODE调试Caffe程序

d77e9b926014c9ea581423ce339b8f74.png
  1. 电脑配置
    1. 1. ubuntu 16.04 LTS+Caffe 1.0.0+Vscond 1.43.2
    2. 2 anaconda 3
    3. 3 caffe 安装目录为 ~/.conda/envs/caffe/caffe
  2. 在cd ~/.conda/envs/caffe
  3. mkdir cfproj
  4. 打开vscode, 选择打开刚刚创建好的cfproj文件夹
  5. 编写一个简单的测试程序,保存为blob_demo.cpp
  6. #include <vector>
    #include <iostream>
    #include <caffe/blob.hpp>
    using namespace caffe;
    using namespace std;
    int main(void)
    {
    Blob<float> a;
    cout<<"Size : "<< a.shape_string()<<endl;
    a.Reshape(1, 2, 3, 4);
    cout<<"Size : "<< a.shape_string()<<endl;
    float *p = a.mutable_cpu_data();
    for(int i = 0; i < a.count(); i++)
    {
    p[i] = i;
    }
    for(int u = 0; u < a.num(); u++)
    {
    for(int v = 0; v < a.channels(); v++)
    {
    for(int w = 0; w < a.height(); w++)
    {
    for(int x = 0; x < a.width(); x++)
    {
    cout<< "a[" << u << " " << v << " " << w << " " << x << "]=" << a.data_at(u,v,w,x) << endl;
    }
    }
    }
    }
    cout << "ASUM=" << a.asum_data() << endl;
    cout << "SUMSQ = "<<a.sumsq_data() << endl;
    return 0;
    }
  7. 如下图所示

058c98fb3e261f4ec29a3e2d54258a26.png

8. 选择Terminal/Configure Tasks 设置编译参数,选择g++ build active file.

6fd12ab2eba7fceb2c908f00e7d0491a.png

自动创建了task.json文件,内容修改如下

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"${file}",
"-I/home/robin/.conda/envs/caffe/caffe/include/",
"-D",
"CPU_ONLY",
"-I/home/robin/.conda/envs/caffe/caffe/.build_release/src/",
"-L/home/robin/.conda/envs/caffe/caffe/build/lib/",
"-lcaffe",
"-lglog",
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}

9. 设置运行/调试参数,选择Run/Add configurations... , 在下拉菜单选择c/c++ GDB launch.

修改红色部分内容如下

40b2b849742fa0a89601894672791f99.png

10. 设置编译器包含路径

在vscode界面同时按住shift+ctrl+p 出现选择界面,请选择C/C++:Edit configurations(UI)

c2acc97a068bf8bcde55a3aaa2206f52.png

11. 执行build and run在还需要在vscode terminal执行如下命令

export LD_LIBRARY_PATH=../caffe/build/lib/:$LD_LIBRARY_PATH

否则将出现如下错误

error while loading shared libraries: libcaffe.so.1.0.0

8ae5a97293bcd38f0cf5f6e8ac3bee91.png


13. 按快捷键F5, 开始进入调试,设置你在哪里停住的断点,如果出现如下界面,说明调试成功了,恭喜!

cd1652f37ed8d6fbaf1d4e985475481d.png
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值