Apollo  6.0
Open source self driving car software
lane_scanning_evaluator.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 <string>
20 #include <vector>
21 
22 #include "torch/script.h"
23 #include "torch/torch.h"
24 
27 
28 namespace apollo {
29 namespace prediction {
30 
32  public:
37 
41  virtual ~LaneScanningEvaluator() = default;
42 
48  bool Evaluate(Obstacle* obstacle_ptr,
49  ObstaclesContainer* obstacles_container) override;
50 
57  bool Evaluate(Obstacle* obstacle_ptr, ObstaclesContainer* obstacles_container,
58  std::vector<Obstacle*> dynamic_env) override;
59 
66  bool ExtractFeatures(const Obstacle* obstacle_ptr,
67  const LaneGraph* lane_graph_ptr,
68  std::vector<double>* feature_values);
69 
71  const LaneGraph& lane_graph,
72  std::vector<std::string>* const string_feature_values);
73 
77  std::string GetName() override { return "LANE_SCANNING_EVALUATOR"; }
78 
79  private:
83  void LoadModel();
84 
90  bool ExtractObstacleFeatures(const Obstacle* obstacle_ptr,
91  std::vector<double>* feature_values);
92 
98  bool ExtractStaticEnvFeatures(const Obstacle* obstacle_ptr,
99  const LaneGraph* lane_graph_ptr,
100  std::vector<double>* feature_values,
101  std::vector<int>* lane_sequence_idx_to_remove);
102 
103  void ModelInference(const std::vector<torch::jit::IValue>& torch_inputs,
104  torch::jit::script::Module torch_model,
105  Feature* feature_ptr);
106 
107  private:
108  static const size_t OBSTACLE_FEATURE_SIZE = 20 * (9 + 40);
109  static const size_t INTERACTION_FEATURE_SIZE = 8;
110  static const size_t SINGLE_LANE_FEATURE_SIZE = 4;
111  static const size_t LANE_POINTS_SIZE = 100; // 50m
112  static const size_t BACKWARD_LANE_POINTS_SIZE = 50; // 25m
113  static const size_t MAX_NUM_LANE = 10;
114  static const size_t SHORT_TERM_TRAJECTORY_SIZE = 10;
115 
116  torch::jit::script::Module torch_lane_scanning_model_;
117  torch::Device device_;
118 };
119 
120 } // namespace prediction
121 } // namespace apollo
Prediction obstacle.
Definition: obstacle.h:52
Definition: obstacles_container.h:39
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::string GetName() override
Get the name of evaluator.
Definition: lane_scanning_evaluator.h:77
Definition: lane_scanning_evaluator.h:31
bool ExtractStringFeatures(const LaneGraph &lane_graph, std::vector< std::string > *const string_feature_values)
virtual ~LaneScanningEvaluator()=default
Destructor.
Obstacles container.
bool Evaluate(Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container) override
Override Evaluate.
Definition: evaluator.h:39
Define the data container base class.
bool ExtractFeatures(const Obstacle *obstacle_ptr, const LaneGraph *lane_graph_ptr, std::vector< double > *feature_values)
Extract features for learning model&#39;s input.