Caffe data Structure blob detailed explanation __caffe notes

Source: Internet
Author: User
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<< "[" &LT;&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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.