Caffe2: Is there an equivalent in cpp to workspace.FeedBlob() which is implemented in python?

Hello,

I wanted to fill an issue on github but I found this link so I am asking my question here. As the caffe2 library now leaves in the pytorch directory on github I thought that you could have answers for me even if it is a pytorch forum.

I am currently working with caffe2 in c++ and I get an error when loading different pre-trained models: Blob data not in the workspace. I searched on internet and found a fix. It consists in creating a blob called “data” and initializing it with random numbers before running the models. However, I don’t find the way to do it in c++. Indeed, there is a function in python called “FeedBlob” in the “class” workspace that does not exist in c++ (I think). I looked into the caffe 2 files (workspace.h, blob.h…) but I did not find anything to modify a blob in a workspace (I can create one, delete one but not modifying it).

Should I post this on github as it seems to be only a pytorch forum? Does someone know how to fix the original error in c++? Is there a way to modify this blob in c++ that I did not find?

you need to use GetBlob, then copy data to it or share point to other buffer.

    // load network
    CAFFE_ENFORCE(workSpace.RunNetOnce(initNet));
    CAFFE_ENFORCE(workSpace.CreateNet(predictNet));

    // load image from file, then convert it to float array.
    float imgArray[3 * 32 * 32];
    loadImage(FLAGS_file, imgArray);

    // define a Tensor which is used to stone input data
    TensorCPU input;
    input.Resize(std::vector<TIndex>({1, 3, 32, 32}));
    input.ShareExternalPointer(imgArray);

    // get "data" blob
#ifdef USE_GPU
    auto data = workSpace.GetBlob("data")->GetMutable<TensorCUDA>();
#else
    auto data = workSpace.GetBlob("data")->GetMutable<TensorCPU>();
#endif

    // copy from input data
    data->CopyFrom(input);

see 03_cpp_forward/main.cpp and Caffe2_Demo for details.