43 {
45 device_type_ = torch::kCUDA;
47 } else {
48 device_type_ = torch::kCPU;
49 }
50
51 for (const auto &name : output_names_) {
52 auto iter = shapes.find(name);
53 if (iter != shapes.end()) {
54 auto blob = std::make_shared<Blob<float>>(iter->second);
55 blobs_.emplace(name, blob);
56 }
57 }
58
59 for (const auto &name : input_names_) {
60 auto iter = shapes.find(name);
61 if (iter != shapes.end()) {
62 auto blob = std::make_shared<Blob<float>>(iter->second);
63 blobs_.emplace(name, blob);
64 }
65 }
66
67
68
69
70 torch::Device
device(device_type_, device_id_);
73
74
75 int height_ = blobs_[input_names_[0]]->shape(1);
76 int width_ = blobs_[input_names_[0]]->shape(2);
77 torch::Tensor input_feature_tensor = torch::zeros({1, 3, height_, width_});
78 std::array<float, 2> down_ratio{8.0f, 8.0f};
79 torch::Tensor tensor_downratio = torch::from_blob(down_ratio.data(), {1, 2});
80 std::array<float, 9> K{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
81 torch::Tensor tensor_K = torch::from_blob(K.data(), {1, 3, 3});
82
83 std::vector<torch::jit::IValue> torch_inputs;
84 torch_inputs.push_back(input_feature_tensor.to(
device));
85 torch_inputs.push_back(
86 std::make_tuple(tensor_K.to(
device), tensor_downratio.to(
device)));
87 auto torch_output_tensor =
net_.forward(torch_inputs).toTuple()->elements();
88 if (torch_output_tensor[0].toTensor().requires_grad()) {
89 AWARN <<
"Require grad";
90 }
91
92 emptyCache();
93 return true;
94}