本例子来源于《21天实战Caffe》

代码如下:

#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(, , , );
cout<<"Size : "<< a.shape_string()<<endl; // 续上面代码
float * p = a.mutable_cpu_data();
for(int i = ; i < a.count(); i++)
{
p[i] = i;
}
for(int u = ; u < a.num(); u++)
{
for(int v = ; v < a.channels(); v++)
{
for(int w = ; w < a.height(); w++)
{
for(int x = ; 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 ;
}

本机的caffe目录为/home/jourluohua/src/caffe,因此编译命令为:

g++ -o test blob_demo.cpp -I/home/jourluohua/src/caffe/include/ -D CPU_ONLY -I/home/jourluohua/src/caffe/.build_release/src/ -L/home/jourluohua/src/caffe/build/lib/ -lcaffe

但是却报

/usr/bin/ld: /tmp/cckoNotB.o: undefined reference to symbol '_ZN6google4base21CheckOpMessageBuilder7ForVar2Ev'
//usr/lib/x86_64-linux-gnu/libglog.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

猜想是找不到libglog的问题,但是之前是使用apt安装过的,因此,加入对glog库的链接后正常:

g++ -o test blob_demo.cpp -I/home/jourluohua/src/caffe/include/ -D CPU_ONLY -I/home/jourluohua/src/caffe/.build_release/src/ -L/home/jourluohua/src/caffe/build/lib/ -lcaffe -lglog

之后加入运行库后(和Halide的使用方式一致)

export LD_LIBRARY_PATH=/home/jourluohua/src/caffe/build/lib/:$LD_LIBRARY_PATH

使用./test可得到结果

Caffe Blob测试的更多相关文章

  1. 【caffe Blob】caffe中与Blob相关的代码注释、使用举例

    首先,Blob使用的小例子(通过运行结果即可知道相关功能): #include <vector> #include <caffe/blob.hpp> #include < ...

  2. Caffe 单独测试添加的layer

    转载请注明出处,楼燚(yì)航的blog,http://home.cnblogs.com/louyihang-loves-baiyan/ 一般我们在使用Caffe的时候,可能需要根据自己的任务需求添加 ...

  3. 使用caffe模型测试图片(python接口)

    1.加载相关模块 1.1 加载numpy import numpy as np 1.2 加载caffe 有两种方法. 方法一(静态导入): 找到当前环境使用的python的site-packages目 ...

  4. caffe blob

    Blob,包括输入数据.输出数据.权值等: Blob是Caffe中处理和传递实际数据的数据封装包,并且在CPU与GPU之间具有同步处理能力.从数学意义上说,blob是按C风格连续存储的N维数组. ca ...

  5. Caffe Blob针对图像数据在内存中的组织方式

    Caffe使用Blob结构在CNN网络中存储.传递数据.对于批量2D图像数据,Blob的维度为 图像数量N × 通道数C × 图像高度H × 图像宽度W 显然,在此种场景下,Blob使用4维坐标定位数 ...

  6. caffe blob理解

    blob数据结构是caffe中基本的数据存储单元,它主要存储的数据是网络中的中间数据变量,比如各层的输入和输出:代价函数关于网络各层参数的梯度. blob中除了存储数据外,还有一些标记数据的参数,以下 ...

  7. 深度学习-Caffe编译测试的小总结

    1. 搭建的环境和代码:win7 64bit + vs2013+CUDA7.5 http://blog.csdn.net/thesby/article/details/50880802 2. 编译,制 ...

  8. caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录

    You need to generate caffe.pb.h manually using protoc as follows. # In the directory you installed C ...

  9. 使用caffe自动测试模型top5的结果

    方法很简单,直接在定义网络的prototxt里面最后加一层就可以了. 这一层定义如下 layer { name: "accuracy_5" type: "Accuracy ...

随机推荐

  1. LC 820. Short Encoding of Words

    Given a list of words, we may encode it by writing a reference string S and a list of indexes A. For ...

  2. matlab处理矩阵

    1.提取大矩阵的一列.一行元素:一列元素:  A(:,j)表示提取A矩阵的第j列全部元素一行元素:  A(i,:)表示提取A矩阵的第i行元素,于是我们有,A(i, j)表示提取A矩阵的第i行第j列的元 ...

  3. CollectionUtils

    public class CollectionUtils { /** * 数组是否包含元素 * @param arr * @param str * @return */ public static b ...

  4. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-2.中大型公司里面项目开发流程讲解

    笔记 2.中大型公司里面项目开发流程讲解     简介:讲解一个项目如何从零到上线,经历过怎样的步骤和流程                  1.一个中大型项目的开发流程,从需求调研到项目上线    ...

  5. Scala面向对象01

  6. [转]html里a标签中href调用js的几种方法

    文章转自:https://blog.csdn.net/best_luxi/article/details/45062301 我们常用的在a标签中有点击事件: 1. a href=”javascript ...

  7. MongodDB基本命令

    MongoDB基本命令 成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show co ...

  8. v-for产生的列表,实现active的切换

    v-for生成序列 <ul> <li v-for="(info,index) in list" :key="info.id" @click=& ...

  9. Hyperledger Fabric1.4 网络环境搭建步骤

    1.  外部访问虚拟机: 安装ssh apt-get install openssh-server openssh-client 2.  安装vim sudo apt install vim 3.  ...

  10. Netcat—瑞士军刀

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...