Skip to content

Instantly share code, notes, and snippets.

@nihui
Created January 27, 2022 07:08
Show Gist options
  • Save nihui/2292e695bb24e0b2dbb08240e9ace347 to your computer and use it in GitHub Desktop.
Save nihui/2292e695bb24e0b2dbb08240e9ace347 to your computer and use it in GitHub Desktop.
libtorch inference test
#include <torch/script.h>
int main()
{
c10::InferenceMode guard(true);
torch::NoGradGuard no_grad;
torch::jit::Module mod2 = torch::jit::load("stylegan.pt");
mod2.eval();
at::Tensor t = torch::ones({1, 18, 512}, torch::kFloat32);
std::vector<torch::jit::IValue> inputs;
inputs.push_back(t);
auto outputs = mod2.forward(inputs).toTensor();
const int ndim = (int)outputs.dim();
fprintf(stderr, "ndim = %d\n", ndim);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment