Apollo 10.0
自动驾驶开放平台
evaluator_manager.cc
浏览该文件的文档.
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
18
19#include <algorithm>
20
25
26namespace apollo {
27namespace perception {
28
37using IdObstacleListMap = std::unordered_map<int, std::list<Obstacle*>>;
38
39bool IsTrainable(const Feature& feature) {
40 if (feature.id() == FLAGS_ego_vehicle_id) {
41 return false;
42 }
43 if (feature.priority().priority() == ObstaclePriority::IGNORE ||
44 feature.is_still() || feature.type() != PerceptionObstacle::VEHICLE) {
45 return false;
46 }
47 return true;
48}
49
51 semantic_map_.reset(new SemanticMap());
52 semantic_map_->Init();
53 evaluator_.reset(new SemanticLSTMEvaluator(semantic_map_.get()));
54 AINFO << "Init SemanticMap instance.";
55}
56
57void EvaluatorManager::Run(ObstaclesContainer* obstacles_container) {
58 BuildObstacleIdHistoryMap(obstacles_container);
59 semantic_map_->RunCurrFrame(obstacle_id_history_map_);
60 AINFO << "starting evaluating objects in semantic map";
61 std::vector<Obstacle*> dynamic_env;
62 for (int id : obstacles_container->curr_frame_considered_obstacle_ids()) {
63 Obstacle* obstacle = obstacles_container->GetObstacle(id);
64 if (obstacle == nullptr) {
65 continue;
66 }
67 if (obstacle->IsStill()) {
68 ADEBUG << "Ignore still obstacle [" << id << "] in evaluator_manager";
69 continue;
70 }
71 EvaluateObstacle(obstacle, obstacles_container, dynamic_env);
72 }
73}
74
76 ObstaclesContainer* obstacles_container,
77 std::vector<Obstacle*> dynamic_env) {
78 // Select different evaluators depending on the obstacle's type.
79 switch (obstacle->type()) {
81 evaluator_->Evaluate(obstacle, obstacles_container);
82 break;
83 }
84 default:
85 break;
86 }
87}
88
90 Obstacle* obstacle, ObstaclesContainer* obstacles_container) {
91 std::vector<Obstacle*> dummy_dynamic_env;
92 EvaluateObstacle(obstacle, obstacles_container, dummy_dynamic_env);
93}
94
95void EvaluatorManager::BuildObstacleIdHistoryMap(
96 ObstaclesContainer* obstacles_container) {
97 obstacle_id_history_map_.clear();
98 std::vector<int> obstacle_ids =
99 obstacles_container->curr_frame_movable_obstacle_ids();
100 obstacle_ids.push_back(FLAGS_ego_vehicle_id);
101 for (int id : obstacle_ids) {
102 Obstacle* obstacle = obstacles_container->GetObstacle(id);
103 if (obstacle == nullptr || obstacle->history_size() == 0) {
104 continue;
105 }
106 size_t num_frames =
107 std::min(static_cast<size_t>(10), obstacle->history_size());
108 for (size_t i = 0; i < num_frames; ++i) {
109 const Feature& obstacle_feature = obstacle->feature(i);
110 Feature feature;
111 feature.set_id(obstacle_feature.id());
112 feature.set_timestamp(obstacle_feature.timestamp());
113 feature.mutable_position()->CopyFrom(obstacle_feature.position());
114 feature.set_theta(obstacle_feature.velocity_heading());
115 if (obstacle_feature.id() != FLAGS_ego_vehicle_id) {
116 feature.mutable_polygon_point()->CopyFrom(
117 obstacle_feature.polygon_point());
118 feature.set_length(obstacle_feature.length());
119 feature.set_width(obstacle_feature.width());
120 } else {
121 const auto& vehicle_config =
122 common::VehicleConfigHelper::Instance()->GetConfig();
123 feature.set_length(vehicle_config.vehicle_param().length());
124 feature.set_width(vehicle_config.vehicle_param().width());
125 }
126 obstacle_id_history_map_[id].add_feature()->CopyFrom(feature);
127 }
128 obstacle_id_history_map_[id].set_is_trainable(
129 IsTrainable(obstacle->latest_feature()));
130 }
131}
132
133} // namespace perception
134} // namespace apollo
void Run(ObstaclesContainer *obstacles_container)
Run evaluators
void EvaluateObstacle(Obstacle *obstacle, ObstaclesContainer *obstacles_container, std::vector< Obstacle * > dynamic_env)
Evaluate obstacle
Prediction obstacle.
Definition obstacle.h:52
perception::PerceptionObstacle::Type type() const
Get the type of perception obstacle's type.
Definition obstacle.cc:54
bool IsStill()
Check if the obstacle is still.
Definition obstacle.cc:95
size_t history_size() const
Get the number of historical features.
Definition obstacle.cc:93
const Feature & feature(const size_t i) const
Get the ith feature from latest to earliest.
Definition obstacle.cc:67
const Feature & latest_feature() const
Get the latest feature.
Definition obstacle.cc:78
const std::vector< int > & curr_frame_movable_obstacle_ids()
Get movable obstacle IDs in the current frame
const std::vector< int > & curr_frame_considered_obstacle_ids()
Get non-ignore obstacle IDs in the current frame
Obstacle * GetObstacle(const int id)
Get obstacle pointer
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
bool IsTrainable(const Feature &feature)
std::unordered_map< int, std::list< Obstacle * > > IdObstacleListMap
class register implement
Definition arena_queue.h:37
Obstacles container
Use evaluator manager to manage all evaluators
optional apollo::perception::PerceptionObstacle::Type type
optional ObstaclePriority priority