blob of 1001 Caffe data Structure
This article records the Caffe data structure of BLOB learning, Welcome to the exchange:
Caffe data Structure BLOB code block run step output result
code block
#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;
Continue the above code 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 (), + + +) {cout<< "a[" <<u<< "[" <&L
t;v<< "[" <<w<< "] [" <<x<< "] =" << a.data_at (U, V, W, x) <<endl; The above code cout<< "asum =" <<a.asum_data () <<endl; Print L1 norm cout<< "sumsq =" <<a.sumsq_data () <<endl;
Print L2 norm return 0; }
Run Steps
Copy the Blob_demo.cpp to the/home/hdu/caffe/include:
Compile file:
g++-O blob_demo blob_demo.cpp-i. /include/-D cpu_only-i. /.build_release/src/-L. /build/lib/-lcaffe-lglog-lboost_system
Import path:
Export Ld_library_path=. /build/lib/: $LD _library_path
To run the program:
./blob_demo Output Results
size:1 2 3 4 (in) a[0][0][0][0] = 0 A[0][0][0][1] = 1 A[0][0][0][2] = 2 a[0][0][0][3] = 3 a[0][
0][1][0] = 4 A[0][0][1][1] = 5 A[0][0][1][2] = 6 a[0][0][1][3] = 7 A[0][0][2][0] = 8 a[0][0][2][1] = 9 a[0][0][2][2] = 10 A[0][0][2][3] = one a[0][1][0][0] = a[0][1][0][1] = a[0][1][0][2] = a[0][1][0][3] = a[0][1][1][0] = a[0][1][ 1][1] = a[0][1][1][2] = a[0][1][1][3] = a[0][1][2][0] = a[0][1][2][1] = a[0][1][2][2] = a[0][1][2][3] = Asum = 276//output L1 norm SUMSQ = 4324//output L2 norm