44 omp_set_num_threads(1);
49 CHECK_NOTNULL(obstacle_ptr);
50 int id = obstacle_ptr->
id();
52 AERROR <<
"Obstacle [" <<
id <<
"] has no latest feature.";
56 CHECK_NOTNULL(latest_feature_ptr);
59 if (!latest_feature_ptr->has_junction_feature() ||
61 ADEBUG <<
"Obstacle [" <<
id <<
"] has less than two junction_exits.";
65 std::vector<double> feature_values;
67 ADEBUG <<
"Obstacle [" <<
id <<
"] failed to extract junction exit mask";
71 if (!FLAGS_enable_semantic_map) {
72 ADEBUG <<
"Not enable semantic map, exit junction_map_evaluator.";
76 if (!semantic_map_->
GetMapById(
id, &feature_map)) {
81 std::vector<torch::jit::IValue> torch_inputs;
83 cv::cvtColor(feature_map, feature_map, cv::COLOR_BGR2RGB);
85 feature_map.convertTo(img_float, CV_32F, 1.0 / 255);
86 torch::Tensor img_tensor = torch::from_blob(img_float.data, {1, 224, 224, 3});
87 img_tensor = img_tensor.permute({0, 3, 1, 2});
88 img_tensor[0][0] = img_tensor[0][0].sub(0.485).div(0.229);
89 img_tensor[0][1] = img_tensor[0][1].sub(0.456).div(0.224);
90 img_tensor[0][2] = img_tensor[0][2].sub(0.406).div(0.225);
92 torch::Tensor junction_exit_mask =
93 torch::zeros({1,
static_cast<int>(feature_values.size())});
94 for (
size_t i = 0; i < feature_values.size(); ++i) {
95 junction_exit_mask[0][i] =
static_cast<float>(feature_values[i]);
98 torch_inputs.push_back(
99 c10::ivalue::Tuple::create({std::move(img_tensor.to(device_)),
100 std::move(junction_exit_mask.to(device_))}));
103 std::vector<double> probability;
104 at::Tensor torch_output_tensor =
105 torch_model_.forward(torch_inputs).toTensor().to(torch::kCPU);
106 auto torch_output = torch_output_tensor.accessor<float, 2>();
107 for (
int i = 0; i < torch_output.size(1); ++i) {
108 probability.push_back(
static_cast<double>(torch_output[0][i]));
111 std::unordered_map<std::string, double> junction_exit_prob;
115 junction_exit.exit_position().x() - latest_feature_ptr->
position().
x();
117 junction_exit.exit_position().y() - latest_feature_ptr->
position().
y();
119 std::atan2(y, x) - std::atan2(latest_feature_ptr->
raw_velocity().
y(),
121 double d_idx = (angle / (2.0 * M_PI) + 1.0 / 24.0) * 12.0;
122 int idx =
static_cast<int>(floor(d_idx >= 0 ? d_idx : d_idx + 12));
123 junction_exit_prob[junction_exit.exit_lane_id()] = probability[idx];
128 latest_feature_ptr->mutable_lane()->mutable_lane_graph();
129 CHECK_NOTNULL(lane_graph_ptr);
131 AERROR <<
"Obstacle [" <<
id <<
"] has no lane sequences.";
134 for (
int i = 0; i < lane_graph_ptr->lane_sequence_size(); ++i) {
135 LaneSequence* lane_sequence_ptr = lane_graph_ptr->mutable_lane_sequence(i);
136 CHECK_NOTNULL(lane_sequence_ptr);
138 if (junction_exit_prob.find(lane_segment.lane_id()) !=
139 junction_exit_prob.end()) {
140 lane_sequence_ptr->set_probability(
141 junction_exit_prob[lane_segment.lane_id()]);
149 Obstacle* obstacle_ptr, std::vector<double>* feature_values) {
150 feature_values->clear();
151 feature_values->resize(JUNCTION_FEATURE_SIZE, 0.0);
153 if (!feature_ptr->has_position()) {
154 ADEBUG <<
"Obstacle [" << obstacle_ptr->
id() <<
"] has no position.";
159 if (!feature_ptr->has_junction_feature()) {
160 AERROR <<
"Obstacle [" << obstacle_ptr->
id()
161 <<
"] has no junction_feature.";
165 int num_junction_exit = feature_ptr->
junction_feature().junction_exit_size();
166 for (
int i = 0; i < num_junction_exit; ++i) {
171 double diff_x = std::cos(-heading) * x - std::sin(-heading) * y;
172 double diff_y = std::sin(-heading) * x + std::cos(-heading) * y;
173 double angle = std::atan2(diff_y, diff_x);
174 double d_idx = (angle / (2.0 * M_PI) + 1.0 / 24.0) * 12.0;
175 int idx =
static_cast<int>(floor(d_idx >= 0 ? d_idx : d_idx + 12));
176 feature_values->at(idx) = 1.0;