Is there a way to read .pt files in C++?

Is there a way to read .pt files in C++ without a python wrapper?

Yes there is

int main(int argc, const char* argv[])
    if(argc != 2) {
        std::cerr << "path to the model not mentioned!!";
        return -1;

    std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(argv[1]);

    std::vector<torch::jit::IValue> inputs;

    for (int i=0; i<COUNT; ++i) {
        auto output = at::argmax(module->forward(inputs).toTensor());
    return 0;
1 Like

Thanks for your helpful answer.

  1. Could you share a link to the C++ torch::jit documentation? I can’t find it on the pytorch website.
  2. is this supported for pytorch 1.0 as well?
  3. what would you have to import?

@0xFFFFFFFF It is supported for PyTorch 1.0, and this tutorial best explains how to load a PyTorch model in C++.

1 Like