From 503785a387de5604ccc102936e8e521c06afb3e5 Mon Sep 17 00:00:00 2001 From: panjiacheng Date: Wed, 17 Jul 2019 15:14:40 -0700 Subject: [PATCH] Prediction: add some comments and fix some minor bugs. --- modules/prediction/common/junction_analyzer.cc | 12 +++++++++++- modules/prediction/container/obstacles/obstacle.cc | 8 ++++++++ .../scripts/records_to_data_for_learning.sh | 1 - 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/prediction/common/junction_analyzer.cc b/modules/prediction/common/junction_analyzer.cc index ffec40182b..a739187608 100644 --- a/modules/prediction/common/junction_analyzer.cc +++ b/modules/prediction/common/junction_analyzer.cc @@ -32,7 +32,9 @@ using apollo::hdmap::LaneInfo; using ConstLaneInfoPtr = std::shared_ptr; std::shared_ptr JunctionAnalyzer::junction_info_ptr_; +// Maps exit lane-id to JunctionExit info. std::unordered_map JunctionAnalyzer::junction_exits_; +// Maps starting lane-id to JunctionFeature info. std::unordered_map JunctionAnalyzer::junction_features_; @@ -55,11 +57,14 @@ void JunctionAnalyzer::Clear() { void JunctionAnalyzer::SetAllJunctionExits() { CHECK_NOTNULL(junction_info_ptr_); + // Go through everything that the junction overlaps with. for (const auto& overlap_id : junction_info_ptr_->junction().overlap_id()) { auto overlap_info_ptr = PredictionMap::OverlapById(overlap_id.id()); if (overlap_info_ptr == nullptr) { continue; } + // Find the lane-segments that are overlapping, yet also extends out of + // the junction area. Those are the junction-exit-lanes. for (const auto& object : overlap_info_ptr->overlap().object()) { if (object.has_lane_overlap_info()) { const std::string& lane_id = object.id().id(); @@ -90,18 +95,22 @@ std::vector JunctionAnalyzer::GetJunctionExits( std::vector junction_exits; std::queue> lane_info_queue; lane_info_queue.emplace(PredictionMap::LaneById(start_lane_id), 0); + std::unordered_set visited_exit_lanes; + // Perform a BFS to find all exit lanes that can be connected through + // this start_lane_id. while (!lane_info_queue.empty()) { ConstLaneInfoPtr curr_lane = lane_info_queue.front().first; int level = lane_info_queue.front().second; lane_info_queue.pop(); const std::string& curr_lane_id = curr_lane->id().id(); - std::unordered_set visited_exit_lanes; + // Stop if this is already an exit lane. if (IsExitLane(curr_lane_id) && visited_exit_lanes.find(curr_lane_id) == visited_exit_lanes.end()) { junction_exits.push_back(junction_exits_[curr_lane_id]); visited_exit_lanes.insert(curr_lane_id); continue; } + // Stop if reached max-search-level. if (level >= max_search_level) { continue; } @@ -122,6 +131,7 @@ const JunctionFeature& JunctionAnalyzer::GetJunctionFeature( JunctionFeature junction_feature; junction_feature.set_junction_id(GetJunctionId()); junction_feature.set_junction_range(ComputeJunctionRange()); + // Find all junction-exit-lanes that are successors of the start_lane_id. std::vector junction_exits = GetJunctionExits(start_lane_id); for (const auto& junction_exit : junction_exits) { diff --git a/modules/prediction/container/obstacles/obstacle.cc b/modules/prediction/container/obstacles/obstacle.cc index 39c98f2f82..6c9eb8de95 100644 --- a/modules/prediction/container/obstacles/obstacle.cc +++ b/modules/prediction/container/obstacles/obstacle.cc @@ -237,16 +237,20 @@ bool Obstacle::IsInJunction(const std::string& junction_id) const { } void Obstacle::BuildJunctionFeature() { + // If obstacle has no history at all, then exit. if (feature_history_.empty()) { AERROR << "Obstacle [" << id_ << "] has no history"; return; } + // If obstacle is not in the given junction, then exit. const std::string& junction_id = JunctionAnalyzer::GetJunctionId(); if (!IsInJunction(junction_id)) { ADEBUG << "Obstacle [" << id_ << "] is not in junction [" << junction_id << "]"; return; } + + // Set the junction features by calling SetJunctionFeatureWithoutEnterLane. Feature* latest_feature_ptr = mutable_latest_feature(); if (feature_history_.size() == 1) { SetJunctionFeatureWithoutEnterLane(latest_feature_ptr); @@ -295,10 +299,14 @@ void Obstacle::SetJunctionFeatureWithEnterLane(const std::string& enter_lane_id, } void Obstacle::SetJunctionFeatureWithoutEnterLane(Feature* const feature_ptr) { + // Sanity checks. if (!feature_ptr->has_lane()) { ADEBUG << "Obstacle [" << id_ << "] has no lane."; return; } + + // Get the possible lanes that the obstalce is on and their neighbor + // lanes and treat them as the starting-lane-segments. std::vector start_lane_ids; if (feature_ptr->lane().current_lane_feature_size() > 0) { for (const auto& lane_feature : diff --git a/modules/tools/prediction/data_pipelines/scripts/records_to_data_for_learning.sh b/modules/tools/prediction/data_pipelines/scripts/records_to_data_for_learning.sh index c233f0b3c1..183dab9527 100644 --- a/modules/tools/prediction/data_pipelines/scripts/records_to_data_for_learning.sh +++ b/modules/tools/prediction/data_pipelines/scripts/records_to_data_for_learning.sh @@ -36,7 +36,6 @@ fi --flagfile=/apollo/modules/prediction/conf/prediction.conf \ --map_dir=/apollo/modules/map/data/${MAP_DIR} \ --prediction_offline_mode=2 \ - --noenable_multi_thread \ --prediction_offline_bags=${SRC_DIR} \ --prediction_data_dir=${TARGET_DIR} \ --noenable_multi_thread -- GitLab