17
#include "caffe2/core/blob.h"
18
#include "caffe2/core/init.h"
19
#include "caffe2/core/tensor.h"
20
#include "caffe2/core/logging.h"
23
using namespace caffe2;
26
int main(int argc, char** argv) {
27
caffe2::GlobalInit(&argc, &argv);
28
caffe2::ShowLogInfoToStderr();
31
"This script corresponds to the Blob part of the Caffe2 C++ "
34
LOG(INFO) << "Let's create a blob myblob.";
38
LOG(INFO) << "Let's set it to int and set the value to 10.";
40
int* myint = myblob.GetMutable<int>();
44
<< "Is the blob type int? "
45
<< myblob.IsType<int>();
48
<< "Is the blob type float? "
49
<< myblob.IsType<float>();
51
const int& myint_const = myblob.Get<int>();
53
<< "The value of the int number stored in the blob is: "
57
<< "Let's try to get a float pointer. This will trigger an exception.";
60
const float& myfloat = myblob.Get<float>();
61
LOG(FATAL) << "This line should never happen.";
62
} catch (std::exception& e) {
64
<< "As expected, we got an exception. Its content says: "
69
"However, we can change the content type (and destroy the old "
70
"content) by calling GetMutable. Let's change it to double.";
72
double* mydouble = myblob.GetMutable<double>();
75
LOG(INFO) << "The new content is: " << myblob.Get<double>();
78
"If we have a pre-created object, we can use Reset() to transfer the "
81
std::string* pvec = new std::string();
84
LOG(INFO) << "Is the blob now of type string? "
85
<< myblob.IsType<std::string>();
87
LOG(INFO) << "This concludes the blob tutorial.";