Apollo 10.0
自动驾驶开放平台
apollo::prediction::JointlyPredictionPlanningEvaluator类 参考

#include <jointly_prediction_planning_evaluator.h>

类 apollo::prediction::JointlyPredictionPlanningEvaluator 继承关系图:
apollo::prediction::JointlyPredictionPlanningEvaluator 的协作图:

Public 成员函数

 JointlyPredictionPlanningEvaluator ()
 Constructor
 
virtual ~JointlyPredictionPlanningEvaluator ()=default
 Destructor
 
void Clear ()
 Clear obstacle feature map
 
bool VectornetProcessObstaclePosition (Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container, torch::Tensor *ptr_target_obs_pos, torch::Tensor *ptr_target_obs_pos_step, torch::Tensor *ptr_vector_mask, torch::Tensor *ptr_all_obstacle_pos, torch::Tensor *ptr_all_obs_p_id, torch::Tensor *ptr_obs_length)
 Process obstacle position to vector
 
bool VectornetProcessMapData (FeatureVector *map_feature, PidVector *map_p_id, const int obs_num, torch::Tensor *ptr_map_data, torch::Tensor *ptr_all_map_p_id, torch::Tensor *ptr_vector_mask)
 Process map data to vector
 
bool Evaluate (Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container) override
 Override Evaluate
 
bool Evaluate (const ADCTrajectoryContainer *adc_trajectory_container, Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container) override
 Override Evaluate
 
bool ExtractObstaclesHistory (Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container, std::vector< std::pair< double, double > > *curr_pos_history, std::vector< std::pair< double, double > > *all_obs_length, std::vector< std::vector< std::pair< double, double > > > *all_obs_pos_history, torch::Tensor *vector_mask)
 Extract all obstacles history
 
bool ExtractADCTrajectory (std::vector< TrajectoryPoint > *trajectory_points, Obstacle *obstacle_ptr, std::vector< std::pair< double, double > > *acd_traj_curr_pos)
 Extract adc trajectory and convert world coord to obstacle coord
 
std::string GetName () override
 Get the name of evaluator.
 
- Public 成员函数 继承自 apollo::prediction::Evaluator
 Evaluator ()=default
 Constructor
 
virtual ~Evaluator ()=default
 Destructor
 
virtual bool Evaluate (Obstacle *obstacle, ObstaclesContainer *obstacles_container, std::vector< Obstacle * > dynamic_env)
 Evaluate an obstacle
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::prediction::Evaluator
std::pair< double, double > WorldCoordToObjCoord (std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
 
std::pair< double, double > WorldCoordToObjCoordNorth (std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
 
double WorldAngleToObjAngle (double input_world_angle, double obj_world_angle)
 
Eigen::MatrixXf VectorToMatrixXf (const std::vector< double > &nums, const int start_index, const int end_index)
 
Eigen::MatrixXf VectorToMatrixXf (const std::vector< double > &nums, const int start_index, const int end_index, const int output_num_row, const int output_num_col)
 
- Protected 属性 继承自 apollo::prediction::Evaluator
ObstacleConf::EvaluatorType evaluator_type_
 

详细描述

在文件 jointly_prediction_planning_evaluator.h34 行定义.

构造及析构函数说明

◆ JointlyPredictionPlanningEvaluator()

apollo::prediction::JointlyPredictionPlanningEvaluator::JointlyPredictionPlanningEvaluator ( )

Constructor

在文件 jointly_prediction_planning_evaluator.cc40 行定义.

41 : device_(torch::kCPU) {
43 LoadModel();
44}
ObstacleConf::EvaluatorType evaluator_type_
Definition evaluator.h:156

◆ ~JointlyPredictionPlanningEvaluator()

virtual apollo::prediction::JointlyPredictionPlanningEvaluator::~JointlyPredictionPlanningEvaluator ( )
virtualdefault

Destructor

成员函数说明

◆ Clear()

void apollo::prediction::JointlyPredictionPlanningEvaluator::Clear ( )

Clear obstacle feature map

在文件 jointly_prediction_planning_evaluator.cc46 行定义.

46{}

◆ Evaluate() [1/2]

bool apollo::prediction::JointlyPredictionPlanningEvaluator::Evaluate ( const ADCTrajectoryContainer adc_trajectory_container,
Obstacle obstacle_ptr,
ObstaclesContainer obstacles_container 
)
overridevirtual

Override Evaluate

参数
ADCtrajectory container
Obstaclepointer
Obstaclescontainer

重载 apollo::prediction::Evaluator .

在文件 jointly_prediction_planning_evaluator.cc167 行定义.

170 {
171 omp_set_num_threads(1);
172
173 obstacle_ptr->SetEvaluatorType(evaluator_type_);
174
175 Clear();
176 CHECK_NOTNULL(obstacle_ptr);
177 int id = obstacle_ptr->id();
178 if (!obstacle_ptr->latest_feature().IsInitialized()) {
179 AERROR << "Obstacle [" << id << "] has no latest feature.";
180 return false;
181 }
182 Feature* latest_feature_ptr = obstacle_ptr->mutable_latest_feature();
183 CHECK_NOTNULL(latest_feature_ptr);
184
185 if (adc_trajectory_container == nullptr) {
186 AERROR << "Null adc trajectory container";
187 return false;
188 }
189
190 int obs_num =
191 obstacles_container->curr_frame_considered_obstacle_ids().size();
192
193 auto start_time_obs = std::chrono::system_clock::now();
194
195 torch::Tensor target_obstacle_pos = torch::zeros({20, 2});
196 torch::Tensor target_obstacle_pos_step = torch::zeros({20, 2});
197 torch::Tensor vector_mask = torch::zeros({450, 50});
198 torch::Tensor all_obstacle_pos = torch::zeros({obs_num, 20, 2});
199 torch::Tensor all_obs_p_id = torch::zeros({obs_num, 2});
200 torch::Tensor obs_length_tmp = torch::zeros({obs_num, 2});
201
202 if (!VectornetProcessObstaclePosition(obstacle_ptr,
203 obstacles_container,
204 &target_obstacle_pos,
205 &target_obstacle_pos_step,
206 &vector_mask,
207 &all_obstacle_pos,
208 &all_obs_p_id,
209 &obs_length_tmp)) {
210 AERROR << "Obstacle [" << id << "] processing obstacle position fails.";
211 return false;
212 }
213
214 auto end_time_obs = std::chrono::system_clock::now();
215 std::chrono::duration<double> diff_obs = end_time_obs - start_time_obs;
216 ADEBUG << "obstacle vectors used time: " << diff_obs.count() * 1000 << " ms.";
217
218
219 // Query the map data vector
220 FeatureVector map_feature;
221 PidVector map_p_id;
222 double pos_x = latest_feature_ptr->position().x();
223 double pos_y = latest_feature_ptr->position().y();
224 common::PointENU center_point;
225 center_point.set_x(pos_x);
226 center_point.set_y(pos_y);
227 double heading = latest_feature_ptr->velocity_heading();
228
229 auto start_time_query = std::chrono::system_clock::now();
230
231 if (!vector_net_.query(center_point, heading, &map_feature, &map_p_id)) {
232 return false;
233 }
234
235 auto end_time_query = std::chrono::system_clock::now();
236 std::chrono::duration<double> diff_query = end_time_query - start_time_query;
237 ADEBUG << "vectors query used time: " << diff_query.count() * 1000 << " ms.";
238
239 // process map data & map p id & v_mask for map polyline
240 int map_polyline_num = map_feature.size();
241 int data_length =
242 ((obs_num + map_polyline_num) < 450) ? (obs_num + map_polyline_num) : 450;
243
244 // Process input tensor
245 auto start_time_data_prep = std::chrono::system_clock::now();
246 int map_polyline_num_valid =
247 ((obs_num + map_polyline_num) < 450) ? map_polyline_num : (450 - obs_num);
248 map_polyline_num_valid =
249 map_polyline_num_valid > 0 ? map_polyline_num_valid : 0;
250 torch::Tensor map_data = torch::zeros({map_polyline_num_valid, 50, 9});
251 torch::Tensor all_map_p_id = torch::zeros({map_polyline_num_valid, 2});
252
253 if (!VectornetProcessMapData(&map_feature,
254 &map_p_id,
255 obs_num,
256 &map_data,
257 &all_map_p_id,
258 &vector_mask)) {
259 AERROR << "Obstacle [" << id << "] processing map data fails.";
260 return false;
261 }
262
263 // process p mask
264 torch::Tensor polyline_mask = torch::zeros({450});
265 if (data_length < 450) {
266 polyline_mask.index_put_(
267 {torch::indexing::Slice(data_length, torch::indexing::None)}, 1);
268 }
269
270 // Extend obs data to specific dimension
271 torch::Tensor obs_pos_data = torch::cat(
272 {all_obstacle_pos.index(
273 {torch::indexing::Slice(),
274 torch::indexing::Slice(torch::indexing::None, -1),
275 torch::indexing::Slice()}),
276 all_obstacle_pos.index({torch::indexing::Slice(),
277 torch::indexing::Slice(1, torch::indexing::None),
278 torch::indexing::Slice()})},
279 2);
280 // Add obs length
281 torch::Tensor obs_length = obs_length_tmp.unsqueeze(1).repeat({1, 19, 1});
282 // Add obs attribute
283 torch::Tensor obs_attr_agent =
284 torch::tensor({11.0, 4.0}).unsqueeze(0).unsqueeze(0).repeat({1, 19, 1});
285 torch::Tensor obs_attr_other =
286 torch::tensor({10.0, 4.0}).unsqueeze(0).unsqueeze(0).repeat(
287 {(obs_num - 1), 19, 1});
288 torch::Tensor obs_attr = torch::cat({obs_attr_agent, obs_attr_other}, 0);
289 // ADD obs id
290 // add 500 to avoid same id as in map_info
291 torch::Tensor obs_id =
292 torch::arange(500, obs_num + 500).unsqueeze(1).repeat(
293 {1, 19}).unsqueeze(2);
294 // Process obs data
295 torch::Tensor obs_data_with_len = torch::cat({obs_pos_data, obs_length}, 2);
296 torch::Tensor obs_data_with_attr =
297 torch::cat({obs_data_with_len, obs_attr}, 2);
298 torch::Tensor obs_data_with_id = torch::cat({obs_data_with_attr, obs_id}, 2);
299 torch::Tensor obs_data_final =
300 torch::cat({torch::zeros({obs_num, (50 - 19), 9}), obs_data_with_id}, 1);
301
302 // Extend data & pid to specific demension
303 torch::Tensor data_tmp = torch::cat({obs_data_final, map_data}, 0);
304 torch::Tensor p_id_tmp = torch::cat({all_obs_p_id, all_map_p_id}, 0);
305 torch::Tensor vector_data;
306 torch::Tensor polyline_id;
307 if (data_length < 450) {
308 torch::Tensor data_zeros = torch::zeros({(450 - data_length), 50, 9});
309 torch::Tensor p_id_zeros = torch::zeros({(450 - data_length), 2});
310 vector_data = torch::cat({data_tmp, data_zeros}, 0);
311 polyline_id = torch::cat({p_id_tmp, p_id_zeros}, 0);
312 } else {
313 vector_data = data_tmp;
314 polyline_id = p_id_tmp;
315 }
316
317 // Empty rand mask as placeholder
318 auto rand_mask = torch::zeros({450}).toType(at::kBool);
319 // Change mask type to bool
320 auto bool_vector_mask = vector_mask.toType(at::kBool);
321 auto bool_polyline_mask = polyline_mask.toType(at::kBool);
322
323 // Process ADC trajectory & Extract features of ADC trajectory
324 std::vector<std::pair<double, double>> adc_traj_curr_pos(30, {0.0, 0.0});
325 torch::Tensor adc_trajectory = torch::zeros({1, 30, 6});
326 const auto& adc_traj = adc_trajectory_container->adc_trajectory();
327 size_t adc_traj_points_num = adc_traj.trajectory_point().size();
328 if (adc_traj_points_num < 1) {
329 AERROR << "adc_traj points num is " << adc_traj_points_num
330 << " adc traj points are not enough";
331 return false;
332 }
333 std::vector<TrajectoryPoint> adc_traj_points;
334 // ADC trajectory info as model input needs to match with
335 // the predicted obstalce's timestamp.
336 double time_interval = obstacle_ptr->latest_feature().timestamp() -
337 adc_traj.header().timestamp_sec();
338 for (size_t i = 0; i < adc_traj_points_num - 1; ++i) {
339 double delta_time = time_interval -
340 adc_traj.trajectory_point(0).relative_time();
341 adc_traj_points.emplace_back(
343 adc_traj.trajectory_point(i),
344 adc_traj.trajectory_point(i + 1), delta_time));
345 }
346 if (!ExtractADCTrajectory(&adc_traj_points,
347 obstacle_ptr, &adc_traj_curr_pos)) {
348 AERROR << "Failed to extract adc trajectory";
349 return false;
350 }
351 size_t traj_points_num = adc_traj_points.size();
352 for (size_t j = 0; j < 30; ++j) {
353 if (j > traj_points_num - 1) {
354 adc_trajectory[0][j][0] =
355 adc_traj_curr_pos[traj_points_num - 1].first;
356 adc_trajectory[0][j][1] =
357 adc_traj_curr_pos[traj_points_num - 1].second;
358 adc_trajectory[0][j][2] =
359 adc_traj_points[traj_points_num - 1].path_point().theta();
360 adc_trajectory[0][j][3] =
361 adc_traj_points[traj_points_num - 1].v();
362 adc_trajectory[0][j][4] =
363 adc_traj_points[traj_points_num - 1].a();
364 adc_trajectory[0][j][5] =
365 adc_traj_points[traj_points_num - 1].path_point().kappa();
366 } else {
367 adc_trajectory[0][j][0] =
368 adc_traj_curr_pos[j].first;
369 adc_trajectory[0][j][1] =
370 adc_traj_curr_pos[j].second;
371 adc_trajectory[0][j][2] =
372 adc_traj_points[j].path_point().theta();
373 adc_trajectory[0][j][3] =
374 adc_traj_points[j].v();
375 adc_trajectory[0][j][4] =
376 adc_traj_points[j].a();
377 adc_trajectory[0][j][5] =
378 adc_traj_points[j].path_point().kappa();
379 }
380 }
381
382 // Build input features for torch
383 std::vector<torch::jit::IValue> torch_inputs;
384 auto X_value = c10::ivalue::Tuple::create(
385 {std::move(target_obstacle_pos.unsqueeze(0).to(device_)),
386 std::move(target_obstacle_pos_step.unsqueeze(0).to(device_)),
387 std::move(vector_data.unsqueeze(0).to(device_)),
388 std::move(bool_vector_mask.unsqueeze(0).to(device_)),
389 std::move(bool_polyline_mask.unsqueeze(0).to(device_)),
390 std::move(rand_mask.unsqueeze(0).to(device_)),
391 std::move(polyline_id.unsqueeze(0).to(device_))});
392 torch_inputs.push_back(c10::ivalue::Tuple::create(
393 {X_value, std::move(adc_trajectory.to(device_))}));
394
395 auto end_time_data_prep = std::chrono::system_clock::now();
396 std::chrono::duration<double> diff_data_prep =
397 end_time_data_prep - start_time_data_prep;
398 ADEBUG << "vectornet input tensor prepration used time: "
399 << diff_data_prep.count() * 1000 << " ms.";
400
401 // Compute pred_traj
402 auto start_time_inference = std::chrono::system_clock::now();
403 at::Tensor torch_output_tensor = torch_default_output_tensor_;
404 torch_output_tensor =
405 torch_vehicle_model_.forward(torch_inputs).toTensor().to(torch::kCPU);
406
407 auto end_time_inference = std::chrono::system_clock::now();
408 std::chrono::duration<double> diff_inference =
409 end_time_inference - start_time_inference;
410 ADEBUG << "vectornet-interaction inference used time: "
411 << diff_inference.count() * 1000
412 << " ms.";
413
414 // Get the trajectory
415 auto torch_output = torch_output_tensor.accessor<float, 3>();
416 Trajectory* trajectory = latest_feature_ptr->add_predicted_trajectory();
417 trajectory->set_probability(1.0);
418
419 for (int i = 0; i < 30; ++i) {
420 double prev_x = pos_x;
421 double prev_y = pos_y;
422 if (i > 0) {
423 const auto& last_point = trajectory->trajectory_point(i - 1).path_point();
424 prev_x = last_point.x();
425 prev_y = last_point.y();
426 }
427 TrajectoryPoint* point = trajectory->add_trajectory_point();
428 double dx = static_cast<double>(torch_output[0][i][0]);
429 double dy = static_cast<double>(torch_output[0][i][1]);
430
431 double heading = latest_feature_ptr->velocity_heading();
432 Vec2d offset(dx, dy);
433 Vec2d rotated_offset = offset.rotate(heading - (M_PI / 2));
434 double point_x = pos_x + rotated_offset.x();
435 double point_y = pos_y + rotated_offset.y();
436 point->mutable_path_point()->set_x(point_x);
437 point->mutable_path_point()->set_y(point_y);
438
439 if (i < 10) { // use origin heading for the first second
440 point->mutable_path_point()->set_theta(
441 latest_feature_ptr->velocity_heading());
442 } else {
443 point->mutable_path_point()->set_theta(
444 std::atan2(trajectory->trajectory_point(i).path_point().y() -
445 trajectory->trajectory_point(i - 1).path_point().y(),
446 trajectory->trajectory_point(i).path_point().x() -
447 trajectory->trajectory_point(i - 1).path_point().x()));
448 }
449 point->set_relative_time(static_cast<double>(i) *
450 FLAGS_prediction_trajectory_time_resolution);
451 if (i == 0) {
452 point->set_v(latest_feature_ptr->speed());
453 } else {
454 double diff_x = point_x - prev_x;
455 double diff_y = point_y - prev_y;
456 point->set_v(std::hypot(diff_x, diff_y) /
457 FLAGS_prediction_trajectory_time_resolution);
458 }
459 }
460
461 return true;
462}
bool VectornetProcessMapData(FeatureVector *map_feature, PidVector *map_p_id, const int obs_num, torch::Tensor *ptr_map_data, torch::Tensor *ptr_all_map_p_id, torch::Tensor *ptr_vector_mask)
Process map data to vector
bool VectornetProcessObstaclePosition(Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container, torch::Tensor *ptr_target_obs_pos, torch::Tensor *ptr_target_obs_pos_step, torch::Tensor *ptr_vector_mask, torch::Tensor *ptr_all_obstacle_pos, torch::Tensor *ptr_all_obs_p_id, torch::Tensor *ptr_obs_length)
Process obstacle position to vector
bool ExtractADCTrajectory(std::vector< TrajectoryPoint > *trajectory_points, Obstacle *obstacle_ptr, std::vector< std::pair< double, double > > *acd_traj_curr_pos)
Extract adc trajectory and convert world coord to obstacle coord
bool query(const common::PointENU &center_point, const double obstacle_phi, FeatureVector *const feature_ptr, PidVector *const p_id_ptr)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
SLPoint InterpolateUsingLinearApproximation(const SLPoint &p0, const SLPoint &p1, const double w)
std::vector< std::vector< double > > PidVector
Definition vector_net.h:34
std::vector< std::vector< std::vector< double > > > FeatureVector
Definition vector_net.h:33

◆ Evaluate() [2/2]

bool apollo::prediction::JointlyPredictionPlanningEvaluator::Evaluate ( Obstacle obstacle_ptr,
ObstaclesContainer obstacles_container 
)
overridevirtual

Override Evaluate

参数
Obstaclepointer
Obstaclescontainer

实现了 apollo::prediction::Evaluator.

在文件 jointly_prediction_planning_evaluator.cc160 行定义.

161 {
162 const ADCTrajectoryContainer* adc_trajectory_container;
163 Evaluate(adc_trajectory_container, obstacle_ptr, obstacles_container);
164 return true;
165}
bool Evaluate(Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container) override
Override Evaluate

◆ ExtractADCTrajectory()

bool apollo::prediction::JointlyPredictionPlanningEvaluator::ExtractADCTrajectory ( std::vector< TrajectoryPoint > *  trajectory_points,
Obstacle obstacle_ptr,
std::vector< std::pair< double, double > > *  acd_traj_curr_pos 
)

Extract adc trajectory and convert world coord to obstacle coord

参数
Obstaclepointer Feature container in a vector for receiving the obstacle history

在文件 jointly_prediction_planning_evaluator.cc531 行定义.

534 {
535 adc_traj_curr_pos->resize(30, {0.0, 0.0});
536 const Feature& obs_curr_feature = obstacle_ptr->latest_feature();
537 double obs_curr_heading = obs_curr_feature.velocity_heading();
538 std::pair<double, double> obs_curr_pos = std::make_pair(
539 obs_curr_feature.position().x(), obs_curr_feature.position().y());
540 size_t adc_traj_points_num = trajectory_points->size();
541 for (size_t i = 0; i < 30; ++i) {
542 if (i > adc_traj_points_num -1) {
543 adc_traj_curr_pos->at(i) =
544 adc_traj_curr_pos->at(adc_traj_points_num - 1);
545 } else {
546 adc_traj_curr_pos->at(i) = WorldCoordToObjCoordNorth(
547 std::make_pair(trajectory_points->at(i).path_point().x(),
548 trajectory_points->at(i).path_point().y()),
549 obs_curr_pos, obs_curr_heading);
550 }
551 }
552 return true;
553}
std::pair< double, double > WorldCoordToObjCoordNorth(std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
Definition evaluator.h:105

◆ ExtractObstaclesHistory()

bool apollo::prediction::JointlyPredictionPlanningEvaluator::ExtractObstaclesHistory ( Obstacle obstacle_ptr,
ObstaclesContainer obstacles_container,
std::vector< std::pair< double, double > > *  curr_pos_history,
std::vector< std::pair< double, double > > *  all_obs_length,
std::vector< std::vector< std::pair< double, double > > > *  all_obs_pos_history,
torch::Tensor *  vector_mask 
)

Extract all obstacles history

参数
Obstaclescontainer Feature container in a vector for receiving the obstacle history

在文件 jointly_prediction_planning_evaluator.cc464 行定义.

469 {
470 const Feature& obs_curr_feature = obstacle_ptr->latest_feature();
471 double obs_curr_heading = obs_curr_feature.velocity_heading();
472 std::pair<double, double> obs_curr_pos = std::make_pair(
473 obs_curr_feature.position().x(), obs_curr_feature.position().y());
474 // Extract target obstacle history
475 for (std::size_t i = 0; i < obstacle_ptr->history_size() && i < 20; ++i) {
476 const Feature& target_feature = obstacle_ptr->feature(i);
477 if (!target_feature.IsInitialized()) {
478 break;
479 }
480 target_pos_history->at(i) =
481 WorldCoordToObjCoordNorth(std::make_pair(target_feature.position().x(),
482 target_feature.position().y()),
483 obs_curr_pos, obs_curr_heading);
484 }
485 all_obs_length->emplace_back(
486 std::make_pair(obs_curr_feature.length(), obs_curr_feature.width()));
487 all_obs_pos_history->emplace_back(*target_pos_history);
488
489 // Extract other obstacles & convert pos to traget obstacle relative coord
490 std::vector<std::pair<double, double>> pos_history(20, {0.0, 0.0});
491 for (int id : obstacles_container->curr_frame_considered_obstacle_ids()) {
492 Obstacle* obstacle = obstacles_container->GetObstacle(id);
493 if (!obstacle) {
494 continue;
495 }
496 int target_id = obstacle_ptr->id();
497 if (id == target_id) {
498 continue;
499 }
500 const Feature& other_obs_curr_feature = obstacle->latest_feature();
501 all_obs_length->emplace_back(std::make_pair(
502 other_obs_curr_feature.length(), other_obs_curr_feature.width()));
503
504 size_t obs_his_size = obstacle->history_size();
505 obs_his_size = obs_his_size <= 20 ? obs_his_size : 20;
506 int cur_idx = all_obs_pos_history->size();
507 if (obs_his_size > 1) {
508 vector_mask->index_put_({cur_idx,
509 torch::indexing::Slice(torch::indexing::None,
510 -(obs_his_size - 1))}, 1);
511 } else {
512 vector_mask->index_put_({cur_idx,
513 torch::indexing::Slice(torch::indexing::None,
514 -1)}, 1);
515 }
516
517 for (size_t i = 0; i < obs_his_size; ++i) {
518 const Feature& feature = obstacle->feature(i);
519 if (!feature.IsInitialized()) {
520 break;
521 }
522 pos_history[i] = WorldCoordToObjCoordNorth(
523 std::make_pair(feature.position().x(), feature.position().y()),
524 obs_curr_pos, obs_curr_heading);
525 }
526 all_obs_pos_history->emplace_back(pos_history);
527 }
528 return true;
529}

◆ GetName()

std::string apollo::prediction::JointlyPredictionPlanningEvaluator::GetName ( )
inlineoverridevirtual

Get the name of evaluator.

实现了 apollo::prediction::Evaluator.

在文件 jointly_prediction_planning_evaluator.h130 行定义.

130 {
131 return "JOINTLY_PREDICTION_PLANNING_EVALUATOR";
132 }

◆ VectornetProcessMapData()

bool apollo::prediction::JointlyPredictionPlanningEvaluator::VectornetProcessMapData ( FeatureVector map_feature,
PidVector map_p_id,
const int  obs_num,
torch::Tensor *  ptr_map_data,
torch::Tensor *  ptr_all_map_p_id,
torch::Tensor *  ptr_vector_mask 
)

Process map data to vector

参数
FeatureVectormap feature vector
intobstacle number
PidVectormap p_id vector
Tensormap data
Tensormap data p_id

在文件 jointly_prediction_planning_evaluator.cc119 行定义.

125 {
126 int map_polyline_num = map_feature->size();
127
128 for (int i = 0; i < map_polyline_num && obs_num + i < 450; ++i) {
129 size_t one_polyline_vector_size = map_feature->at(i).size();
130 if (one_polyline_vector_size < 50) {
131 ptr_vector_mask->index_put_({obs_num + i,
132 torch::indexing::Slice(
133 one_polyline_vector_size,
134 torch::indexing::None)},
135 1);
136 }
137 }
138
139 auto opts = torch::TensorOptions().dtype(torch::kDouble);
140
141 for (int i = 0; i < map_polyline_num && i + obs_num < 450; ++i) {
142 ptr_all_map_p_id->index_put_({i}, torch::from_blob(map_p_id->at(i).data(),
143 {2},
144 opts));
145
146 int one_polyline_vector_size = map_feature->at(i).size();
147 for (int j = 0; j < one_polyline_vector_size && j < 50; ++j) {
148 ptr_map_data->index_put_({i, j},
149 torch::from_blob(map_feature->at(i)[j].data(),
150 {9},
151 opts));
152 }
153 }
154 *ptr_map_data = ptr_map_data->toType(at::kFloat);
155 *ptr_all_map_p_id = ptr_all_map_p_id->toType(at::kFloat);
156
157 return true;
158}

◆ VectornetProcessObstaclePosition()

bool apollo::prediction::JointlyPredictionPlanningEvaluator::VectornetProcessObstaclePosition ( Obstacle obstacle_ptr,
ObstaclesContainer obstacles_container,
torch::Tensor *  ptr_target_obs_pos,
torch::Tensor *  ptr_target_obs_pos_step,
torch::Tensor *  ptr_vector_mask,
torch::Tensor *  ptr_all_obstacle_pos,
torch::Tensor *  ptr_all_obs_p_id,
torch::Tensor *  ptr_obs_length 
)

Process obstacle position to vector

参数
Obstaclespointer
Obstaclescontainer
Tensortarget obstacle position
Tensortarget obstacle position step
Tensorvector mask
Tensorall obstacle position
Tensorall obstacle p_id
Tensorall obstacle length

在文件 jointly_prediction_planning_evaluator.cc48 行定义.

56 {
57 // obs data vector
58 // Extract features of pos_history
59 std::vector<std::pair<double, double>> target_pos_history(20, {0.0, 0.0});
60 std::vector<std::pair<double, double>> all_obs_length;
61 std::vector<std::vector<std::pair<double, double>>> all_obs_pos_history;
62
63 if (!ExtractObstaclesHistory(obstacle_ptr, obstacles_container,
64 &target_pos_history, &all_obs_length,
65 &all_obs_pos_history, ptr_vector_mask)) {
66 AERROR << "Obstacle [" << obstacle_ptr->id()
67 << "] failed to extract obstacle history";
68 return false;
69 }
70
71 for (int j = 0; j < 20; ++j) {
72 ptr_target_obs_pos->index_put_({19 - j, 0}, target_pos_history[j].first);
73 ptr_target_obs_pos->index_put_({19 - j, 1}, target_pos_history[j].second);
74 if (j == 19 || (j > 0 && target_pos_history[j + 1].first == 0.0)) {
75 break;
76 }
77 ptr_target_obs_pos_step->index_put_(
78 {19 - j, 0},
79 target_pos_history[j].first - target_pos_history[j + 1].first);
80 ptr_target_obs_pos_step->index_put_(
81 {19 - j, 1},
82 target_pos_history[j].second - target_pos_history[j + 1].second);
83 }
84
85 int obs_num =
86 obstacles_container->curr_frame_considered_obstacle_ids().size();
87 for (int i = 0; i < obs_num; ++i) {
88 std::vector<double> obs_p_id{std::numeric_limits<float>::max(),
89 std::numeric_limits<float>::max()};
90 for (int j = 0; j < 20; ++j) {
91 // Process obs pid
92 if (obs_p_id[0] > all_obs_pos_history[i][j].first) {
93 obs_p_id[0] = all_obs_pos_history[i][j].first;
94 }
95 if (obs_p_id[1] > all_obs_pos_history[i][j].second) {
96 obs_p_id[1] = all_obs_pos_history[i][j].second;
97 }
98 // Process obs pos history
99 ptr_all_obstacle_pos->index_put_(
100 {i, 19 - j, 0},
101 all_obs_pos_history[i][j].first);
102 ptr_all_obstacle_pos->index_put_(
103 {i, 19 - j, 1},
104 all_obs_pos_history[i][j].second);
105 }
106
107 ptr_all_obs_p_id->index_put_({i, 0}, obs_p_id[0]);
108 ptr_all_obs_p_id->index_put_({i, 1}, obs_p_id[1]);
109 }
110
111 for (int i = 0; i < obs_num; ++i) {
112 ptr_obs_length->index_put_({i, 0}, all_obs_length[i].first);
113 ptr_obs_length->index_put_({i, 1}, all_obs_length[i].second);
114 }
115
116 return true;
117}
bool ExtractObstaclesHistory(Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container, std::vector< std::pair< double, double > > *curr_pos_history, std::vector< std::pair< double, double > > *all_obs_length, std::vector< std::vector< std::pair< double, double > > > *all_obs_pos_history, torch::Tensor *vector_mask)
Extract all obstacles history

该类的文档由以下文件生成: