Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pytorch
GitHub Repository: pytorch/tutorials
Path: blob/main/advanced_source/custom_classes/infer.cpp
1751 views
1
#include <torch/script.h>
2
3
#include <iostream>
4
#include <memory>
5
6
int main(int argc, const char* argv[]) {
7
torch::jit::Module module;
8
try {
9
// Deserialize the ScriptModule from a file using torch::jit::load().
10
module = torch::jit::load("foo.pt");
11
}
12
catch (const c10::Error& e) {
13
std::cerr << "error loading the model\n";
14
return -1;
15
}
16
17
std::vector<c10::IValue> inputs = {"foobarbaz"};
18
auto output = module.forward(inputs).toString();
19
std::cout << output->string() << std::endl;
20
}
21
22