Apollo 11.0
自动驾驶开放平台
torch_net.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23#include <torch/script.h>
24#include <torch/torch.h>
25
27
28namespace apollo {
29namespace perception {
30namespace inference {
31
32
33class TorchNet : public Inference {
34 public:
35 TorchNet(const std::string &model_file,
36 const std::vector<std::string> &outputs,
37 const std::vector<std::string> &inputs);
38
39 virtual ~TorchNet() {}
40
41 bool Init(const std::map<std::string, std::vector<int>> &shapes) override;
42
43 void Infer() override;
44 base::BlobPtr<float> get_blob(const std::string &name) override;
45
46 protected:
47 bool reshape();
48 bool shape(const std::string &name, std::vector<int> *res);
49 torch::jit::script::Module net_;
50
51 private:
52 std::string model_file_;
53 std::vector<std::string> output_names_;
54 std::vector<std::string> input_names_;
55 BlobMap blobs_;
56
57 torch::DeviceType device_type_;
58 int device_id_ = 0;
59};
60
61} // namespace inference
62} // namespace perception
63} // namespace apollo
base::BlobPtr< float > get_blob(const std::string &name) override
Definition torch_net.cc:65
bool shape(const std::string &name, std::vector< int > *res)
Definition torch_net.cc:75
bool Init(const std::map< std::string, std::vector< int > > &shapes) override
Definition torch_net.cc:33
torch::jit::script::Module net_
Definition torch_net.h:49
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition blob.h:313
std::map< std::string, base::BlobPtr< float > > BlobMap
Definition inference.h:39
class register implement
Definition arena_queue.h:37