Apollo 11.0
自动驾驶开放平台
libtorch_obstacle_detector.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 <utility>
23#include <vector>
24#include <torch/script.h>
25#include <torch/torch.h>
26
28
29namespace apollo {
30namespace perception {
31namespace inference {
32
33
35 public:
36 ObstacleDetector(const std::string &net_file, const std::string &model_file,
37 const std::vector<std::string> &outputs);
38
39 ObstacleDetector(const std::string &net_file, const std::string &model_file,
40 const std::vector<std::string> &outputs,
41 const std::vector<std::string> &inputs);
42
43 virtual ~ObstacleDetector() {}
44
45 bool Init(const std::map<std::string, std::vector<int>> &shapes) override;
46
47 void Infer() override;
48 base::BlobPtr<float> get_blob(const std::string &name) override;
49
50 protected:
51 bool shape(const std::string &name, std::vector<int> *res);
52 torch::jit::script::Module net_;
53
54 private:
55 std::string net_file_;
56 std::string model_file_;
57 std::vector<std::string> output_names_;
58 std::vector<std::string> input_names_;
59 BlobMap blobs_;
60
61 torch::DeviceType device_type_;
62 int device_id_ = 0;
63};
64
65} // namespace inference
66} // namespace perception
67} // namespace apollo
base::BlobPtr< float > get_blob(const std::string &name) override
bool shape(const std::string &name, std::vector< int > *res)
bool Init(const std::map< std::string, std::vector< int > > &shapes) override
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