Where can one find an up to date example of how to run a caffe2 model in C++?

The AICamera demo that is mentioned as part of the pytorch->onnx->caffe2 tutorial and caffe2 tutorials collected here are out of date and do not match the current API.

I tried looking at the source, but am still getting an error:

  what():  [enforce fail at operator.h:791] . Unsupported type of tensor: nullptr (uninitialized)Error from operator: 
input: "3" input: "0" output: "10" name: "" type: "Gather" device_option { device_type: 0 device_id: 0 }

Here my attempt to do inference

    caffe2::Predictor* pred = new caffe2::Predictor(init_net, predict_net);

    caffe2::CPUContext cpuc;
    std::vector<float> data(5, 0.);
    caffe2::TensorCPU input({1, 5}, data, &cpuc);

    caffe2::Predictor::TensorList input_vec = {input};
    caffe2::Predictor::TensorList output_vec = {}; 

    (*pred)(input_vec, &output_vec);

with a model

class MLP(nn.Module):
    def __init__(self):
        self.fc = nn.Linear(5, 3)

    def forward(self, x):
        return self.fc(x)

I would also like to know how to do this. I’m experiencing similar problems. Currently available documentations are all out of date and it’s quite frustrating to have to go through a myriad of source files to figure out how things are implemented.

But even before OP’s step, I’m having trouble loading an ONNX model in C++ using caffe2. I tried CAFFE_ENFORCE(ReadProtoFromFile(path, &init_net)); which throws an error…

Any help would be highly appreciated!

1 Like