diff --git a/modules/prediction/evaluator/evaluator.h b/modules/prediction/evaluator/evaluator.h index 1a5cfd8f46dfc6b984f72ee748debbc91a68ab33..e55551d171e2e6edb80d99102035972dbdc89d9f 100644 --- a/modules/prediction/evaluator/evaluator.h +++ b/modules/prediction/evaluator/evaluator.h @@ -48,7 +48,7 @@ class Evaluator { virtual void Evaluate(Obstacle* obstacle) = 0; protected: - std::vector feature_values; + std::vector feature_values_; }; } // namespace prediction diff --git a/modules/prediction/evaluator/vehicle/BUILD b/modules/prediction/evaluator/vehicle/BUILD index 7acc6dde37fdc746c50283c7d78492228102d6af..dda432bb3455cb08054104de61256a4ae8a1a87c 100644 --- a/modules/prediction/evaluator/vehicle/BUILD +++ b/modules/prediction/evaluator/vehicle/BUILD @@ -3,16 +3,17 @@ load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( - name = "vehicle_evaluator", + name = "mlp_evaluator", hdrs = [ - "vehicle_evaluator.h", + "mlp_evaluator.h", ], srcs = [ - "vehicle_evaluator.cc", + "mlp_evaluator.cc", ], deps = [ "//modules/prediction/evaluator:evaluator", "//modules/prediction/container/obstacles:obstacle", + "//modules/prediction/proto:lane_graph_proto", ], ) diff --git a/modules/prediction/evaluator/vehicle/mlp_evaluator.cc b/modules/prediction/evaluator/vehicle/mlp_evaluator.cc new file mode 100644 index 0000000000000000000000000000000000000000..584331c0550bc191c7791cfacb94fc5327d22edb --- /dev/null +++ b/modules/prediction/evaluator/vehicle/mlp_evaluator.cc @@ -0,0 +1,74 @@ +/****************************************************************************** + * Copyright 2017 The Apollo Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#include "modules/prediction/evaluator/vehicle/mlp_evaluator.h" + +namespace apollo { +namespace prediction { + +MLPEvaluator::MLPEvaluator() { +} + +MLPEvaluator::~MLPEvaluator() { +} + +void MLPEvaluator::Evaluate(Obstacle* obstacle_ptr) { + Clear(); + if (obstacle_ptr == nullptr) { + AERROR << "Invalid obstacle."; + return; + } + + int id = obstacle_ptr->id(); + Feature latest_feature = obstacle_ptr->latest_feature(); + if (!latest_feature.IsInitialized()) { + ADEBUG << "Obstacle [" << id << "] has no latest feature."; + return; + } + + Lane* lane_ptr = latest_feature.mutable_lane(); + if (!latest_feature.has_lane() || lane_ptr == nullptr) { + ADEBUG << "Obstacle [" << id << "] has no lane feature."; + return; + } + + LaneGraph* lane_graph_ptr = lane_ptr->mutable_lane_graph(); + if (!latest_feature.lane().has_lane_graph() || lane_graph_ptr == nullptr) { + ADEBUG << "Obstacle [" << id << "] has no lane graph."; + return; + } + + if (latest_feature.lane().lane_graph().lane_sequence_size() == 0) { + ADEBUG << "Obstacle [" << id << "] has no lane sequences."; + return; + } + + for (int i = 0; + i < latest_feature.lane().lane_graph().lane_sequence_size(); ++i) { + LaneSequence* lane_sequence_ptr = lane_graph_ptr->mutable_lane_sequence(i); + CHECK(lane_sequence_ptr != nullptr); + ExtractFeatureValues(obstacle_ptr, lane_sequence_ptr); + } +} + +void MLPEvaluator::ExtractFeatureValues(Obstacle* obstacle_ptr, + LaneSequence* lane_sequence_ptr) { + feature_values_.clear(); + // TODO(kechxu) implement insert feture values into feature_values_ +} + +} // namespace prediction +} // namespace apollo diff --git a/modules/prediction/evaluator/vehicle/vehicle_evaluator.h b/modules/prediction/evaluator/vehicle/mlp_evaluator.h similarity index 60% rename from modules/prediction/evaluator/vehicle/vehicle_evaluator.h rename to modules/prediction/evaluator/vehicle/mlp_evaluator.h index df1295d02263e5ae144dff10e1ccfad1a0f3064b..008837deb796c7eddad9739f76a03c499263afbd 100644 --- a/modules/prediction/evaluator/vehicle/vehicle_evaluator.h +++ b/modules/prediction/evaluator/vehicle/mlp_evaluator.h @@ -14,45 +14,33 @@ * limitations under the License. *****************************************************************************/ -/** - * @file - * @brief Define the vehicle evaluator. - */ +#ifndef MODULES_PREDICTION_EVALUATOR_VEHICLE_MLP_EVALUATOR_H_ +#define MODULES_PREDICTION_EVALUATOR_VEHICLE_MLP_EVALUATOR_H_ -#ifndef MODULES_PREDICTION_EVALUATOR_VEHICLE_VEHICLE_EVALUATOR_H_ -#define MODULES_PREDICTION_EVALUATOR_VEHICLE_VEHICLE_EVALUATOR_H_ - -#include -#include -#include +#include #include "modules/prediction/evaluator/evaluator.h" #include "modules/prediction/container/obstacles/obstacle.h" +#include "modules/prediction/proto/lane_graph.pb.h" namespace apollo { namespace prediction { -class VehicleEvaluator : public Evaluator { +class MLPEvaluator : public Evaluator { public: - VehicleEvaluator(); - - virtual ~VehicleEvaluator(); + MLPEvaluator(); - void Evaluate(Obstacle* obstacle); + virtual ~MLPEvaluator(); - void Clear(); + void Evaluate(Obstacle* obstacle_ptr); - private: - void RegisterClass(const std::string& name, std::unique_ptr ptr); + void ExtractFeatureValues(Obstacle* obstacle_ptr, + LaneSequence* lane_sequence_ptr); - void Init(); - - private: - Evaluator* evaluator_; - std::unordered_map> map_evaluators_; + void Clear(); }; } // namespace prediction } // namespace apollo -#endif // MODULES_PREDICTION_EVALUATOR_VEHICLE_VEHICLE_EVALUATOR_H_ +#endif // MODULES_PREDICTION_EVALUATOR_VEHICLE_MLP_EVALUATOR_H_ diff --git a/modules/prediction/evaluator/vehicle/vehicle_evaluator.cc b/modules/prediction/evaluator/vehicle/vehicle_evaluator.cc deleted file mode 100644 index ce6b272b9ae64cf74d938a52acf30d3b4449db5b..0000000000000000000000000000000000000000 --- a/modules/prediction/evaluator/vehicle/vehicle_evaluator.cc +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * Copyright 2017 The Apollo Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -#include - -#include "modules/prediction/evaluator/vehicle/vehicle_evaluator.h" - -namespace apollo { -namespace prediction { - -VehicleEvaluator::VehicleEvaluator() : evaluator_(nullptr) { - Init(); -} - -void VehicleEvaluator::Init() { - CHECK(map_evaluators_.find("DefaultVehicleEvaluator") != - map_evaluators_.end()); - evaluator_ = map_evaluators_["DefaultVehicleEvaluator"].get(); - - // TODO(kechxu) load user defined model taking over the default one - - CHECK(evaluator_ != nullptr); -} - -void VehicleEvaluator::Evaluate(Obstacle* obstacle) { - evaluator_->Evaluate(obstacle); -} - -void VehicleEvaluator::RegisterClass(const std::string& name, - std::unique_ptr ptr) { - map_evaluators_[name] = std::move(ptr); -} - -} // namespace prediction -} // namespace apollo