使用VScode编译和调试Caffe源码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012435142/article/details/83032248

一.caffe源码编译

  1. 下载源码caffe https://github.com/BVLC/caffe
    . 修改Makefile.config
  • 可选修改项
DEBUG := 1
CPU_ONLY := 1
USE_OPENCV := 1
- 必须修改的项
  #找到下面两行
  INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
  LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
  #修改为:
  INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
  LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-
  gnu/hdf5/serial
  1. sudo make all -j8(使用8个线程执行)

  2. sudo make test -j8

  3. sudo make runtest -j8

二.调试运行cpp_classification.cpp

  1. 按照examples/cpp_classification中的readme.md下载网络权重文件等

  2. 测试生成的例子
    可以看到,当执行了make all命令后,caffe文件中多出来一个build文件(实际上是该build是指向build_debug 或者build_release文件夹的链接)。build文件中生成的examples中包含生成的执行文件,如build/examples/cpp_classification中的classification.bin
    我们可以先运行以下这个classification.bin文件,如在terminal中输入

./build/examples/cpp_classification/classification.bin \
  models/bvlc_reference_caffenet/deploy.prototxt \
  models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel \
  data/ilsvrc12/imagenet_mean.binaryproto \
  data/ilsvrc12/synset_words.txt \
  examples/images/cat.jpg
如果上面的例子执行正常,那我们下面来调试该例子。
  1. 使用VSCODE打开caffe文件目录,修改launch.json
    修改下面一行内容,也就是让程序运行时去执行classification.bin
"program": "${workspaceFolder}/build/examples/cpp_classification/${fileBasenameNoExtension}.bin",
"args": ["models/bvlc_reference_caffenet/deploy.prototxt",
"models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel",
         "data/ilsvrc12/imagenet_mean.binaryproto",
         "data/ilsvrc12/synset_words.txt",
         "examples/images/cat.jpg"
        ],
  1. classfication.cpp增加断点,开始调试运行

  2. 如果编辑了classfication.cpp文件,想要重新生成怎么办?

    例如,给例子添加计时函数

double time1 = static_cast<double>( cv::getTickCount());
std::vector<Prediction> predictions = classifier.Classify(img);
double timeuse = (static_cast<double>( cv::getTickCount()) - time1)/cv::getTickFrequency();
std::cout<<"time use:"<<timeuse<<std::endl;

执行sudo make example -j8可以重新编译examples中的*.cpp,并生成*.bin执行文件

猜你喜欢

转载自blog.csdn.net/u012435142/article/details/83032248