main.cpp 584 Bytes
Newer Older
1
#include <iostream>
2
3
#include <torch/torch.h>
#include <torchvision/vision.h>
4
5
6
7
8
9
10
11
12
13
14
#include <torchvision/models/resnet.h>

int main()
{
  auto model = vision::models::ResNet18();
  model->eval();

  // Create a random input tensor and run it through the model.
  auto in = torch::rand({1, 3, 10, 10});
  auto out = model->forward(in);

15
16
17
18
19
20
21
22
23
24
  std::cout << out.sizes();

  if (torch::cuda::is_available()) {
    // Move model and inputs to GPU
    model->to(torch::kCUDA);
    auto gpu_in = in.to(torch::kCUDA);
    auto gpu_out = model->forward(gpu_in);

    std::cout << gpu_out.sizes();
  }
25
}