提交 d538c42d 编写于 作者: L Liangliang Zhang 提交者: Jiaming Tao

Perception: used proto for traffic light recognizer. Added test for proto loading.

上级 f5680df8
......@@ -182,3 +182,7 @@ DEFINE_string(traffic_light_multi_camera_projection_config,
"modules/perception/model/traffic_light/"
"multi_camera_projection_config.pb.txt",
"traffic light multi camera projection config filename.");
DEFINE_string(traffic_light_recognizer_config,
"modules/perception/model/traffic_light/"
"recognizer_config.pb.txt",
"traffic light recognizer config filename.");
......@@ -125,5 +125,6 @@ DECLARE_string(cnn_segmentation_config);
DECLARE_string(hdmap_roi_filter_config);
DECLARE_string(low_object_filter_config);
DECLARE_string(traffic_light_multi_camera_projection_config);
DECLARE_string(traffic_light_recognizer_config);
#endif // MODULES_PERCEPTION_COMMON_PERCEPTION_GFLAGS_H_
model_config_path: "model/traffic_light/recognizer.config"
model_config_path: "model/traffic_light/rectifier.config"
model_config_path: "model/traffic_light/reviser.config"
model_config_path: "model/traffic_light/preprocessor.config"
......
model_configs {
name: "UnityRecognize"
version: "1.0.0"
string_params {
name: "classify_model"
value: "model/traffic_light/rcg_all/2017-11-17/vertical/baidu_iter_250000.caffemodel"
}
string_params {
name: "classify_net"
value: "model/traffic_light/rcg_all/2017-11-17/vertical/deploy.prototxt"
}
float_params{
name: "classify_threshold"
value: 0.5
}
integer_params{
name: "classify_resize_width"
value: 32
}
integer_params{
name: "classify_resize_height"
value: 96
}
}
model_configs {
name: "UnityRecognizeNight"
version: "1.0.0"
string_params {
name: "classify_model"
value: "model/traffic_light/rcg_all/2017-09-15/quadrate/baidu_iter_200000.caffemodel"
}
string_params {
name: "classify_net"
value: "model/traffic_light/rcg_all/2017-09-15/quadrate/deploy.prototxt"
}
float_params{
name: "classify_threshold"
value: 0.5
}
integer_params{
name: "classify_resize_width"
value: 64
}
integer_params{
name: "classify_resize_height"
value: 64
}
}
recognizer_config {
name: "UnityRecognize"
version: "1.0.0"
classify_model: "modules/perception/model/traffic_light/rcg_all/2017-11-17/vertical/baidu_iter_250000.caffemodel"
classify_net: "modules/perception/model/traffic_light/rcg_all/2017-11-17/vertical/deploy.prototxt"
classify_threshold: 0.5
classify_resize_width: 32
classify_resize_height: 96
}
recognizer_config {
name: "UnityRecognizeNight"
version: "1.0.0"
classify_model: "modules/perception/model/traffic_light/rcg_all/2017-09-15/quadrate/baidu_iter_200000.caffemodel"
classify_net: "modules/perception/model/traffic_light/rcg_all/2017-09-15/quadrate/deploy.prototxt"
classify_threshold: 0.5
classify_resize_width: 64
classify_resize_height: 64
}
......@@ -13,3 +13,17 @@ proto_library(
"multi_camera_projection_config.proto",
],
)
cc_proto_library(
name = "recognizer_config_lib_proto",
deps = [
":recognizer_config_lib",
],
)
proto_library(
name = "recognizer_config_lib",
srcs = [
"recognizer_config.proto",
],
)
syntax = "proto2";
package apollo.perception.traffic_light.recognizer_config;
message RecognizerConfig {
optional string name = 1;
optional string version = 2;
optional string classify_model = 3;
optional string classify_net = 4;
optional float classify_threshold = 5;
optional int32 classify_resize_width = 6;
optional int32 classify_resize_height = 7;
}
message ModelConfigs {
repeated RecognizerConfig recognizer_config = 1;
}
......@@ -17,11 +17,29 @@ cc_library(
"//modules/common/proto:error_code_proto",
"//modules/common/proto:header_proto",
"//modules/map/proto:map_proto",
"//modules/perception/lib/config_manager",
"//modules/perception/proto:perception_proto",
"//modules/perception/proto/traffic_light:recognizer_config_lib_proto",
"//modules/perception/traffic_light/base",
"//modules/perception/traffic_light/interface",
],
)
cc_test(
name = "unity_recognize_test",
size = "small",
srcs = [
"unity_recognize_test.cc",
],
data = [
"//modules/perception:perception_data",
"//modules/perception:perception_model",
"//modules/perception/conf:perception_config",
],
deps = [
"perception_traffic_light_recognizer",
"//modules/perception/lib/base",
"@gtest//:main",
],
)
cpplint()
......@@ -17,90 +17,44 @@
#include "modules/perception/traffic_light/recognizer/unity_recognize.h"
#include "modules/common/util/file.h"
#include "modules/perception/common/perception_gflags.h"
#include "modules/perception/traffic_light/recognizer/classify.h"
namespace apollo {
namespace perception {
namespace traffic_light {
using apollo::common::util::GetAbsolutePath;
using apollo::common::util::GetProtoFromFile;
bool UnityRecognize::Init() {
ConfigManager *config_manager = ConfigManager::instance();
if (config_manager == nullptr) {
AERROR << "failed to get ConfigManager instance.";
if (!GetProtoFromFile(FLAGS_traffic_light_recognizer_config, &config_)) {
AERROR << "Cannot get config proto from file: "
<< FLAGS_traffic_light_recognizer_config;
return false;
}
const ModelConfig *model_config_night =
config_manager->GetModelConfig(name() + "Night");
if (model_config_night == nullptr) {
AERROR << "not found model config: " << name() + "Night";
if (config_.recognizer_config_size() != 2) {
AERROR << "RecognizeConfig size should be 2.";
return false;
}
if (!InitModel(config_manager, model_config_night, &classify_night_)) {
AERROR << "init night model failed";
return false;
}
const ModelConfig *model_config_day = config_manager->GetModelConfig(name());
if (model_config_day == nullptr) {
AERROR << "not found model config: " << name();
return false;
}
if (!InitModel(config_manager, model_config_day, &classify_day_)) {
AERROR << "init day model failed";
return false;
}
return true;
}
bool UnityRecognize::InitModel(const ConfigManager *config_manager,
const ModelConfig *model_config,
std::shared_ptr<IRefine> *classify) {
std::string classify_model;
std::string classify_net;
if (!model_config->GetValue("classify_model", &classify_model)) {
AERROR << "classify_model not found." << name();
return false;
}
classify_model = GetAbsolutePath(config_manager->WorkRoot(), classify_model);
if (!model_config->GetValue("classify_net", &classify_net)) {
AERROR << "classify_net not found." << name();
return false;
}
classify_net = GetAbsolutePath(config_manager->WorkRoot(), classify_net);
float classify_threshold = 0.0;
int classify_resize_width = 0;
int classify_resize_height = 0;
if (!model_config->GetValue("classify_threshold", &classify_threshold)) {
AERROR << "classify_threshold not found." << name();
return false;
}
if (!model_config->GetValue("classify_resize_width",
&classify_resize_width)) {
AERROR << "classify_resize_width not found." << name();
return false;
}
if (!model_config->GetValue("classify_resize_height",
&classify_resize_height)) {
AERROR << "classify_resize_height not found." << name();
return false;
}
if (!model_config->GetValue("classify_threshold", &classify_threshold)) {
AERROR << "classify_threshold not found." << name();
return false;
for (const auto &recognizer_config : config_.recognizer_config()) {
if (recognizer_config.name() == "UnityRecognizeNight") {
classify_night_ = std::make_shared<ClassifyBySimple>(
recognizer_config.classify_net(), recognizer_config.classify_model(),
recognizer_config.classify_threshold(),
static_cast<unsigned int>(recognizer_config.classify_resize_width()),
static_cast<unsigned int>(
recognizer_config.classify_resize_height()));
}
if (recognizer_config.name() == "UnityRecognize") {
classify_day_ = std::make_shared<ClassifyBySimple>(
recognizer_config.classify_net(), recognizer_config.classify_model(),
recognizer_config.classify_threshold(),
static_cast<unsigned int>(recognizer_config.classify_resize_width()),
static_cast<unsigned int>(
recognizer_config.classify_resize_height()));
}
}
classify->reset(new ClassifyBySimple(classify_net, classify_model,
classify_threshold,
(unsigned int)classify_resize_width,
(unsigned int)classify_resize_height));
return true;
}
......
......@@ -20,7 +20,8 @@
#include <string>
#include <vector>
#include "modules/perception/lib/config_manager/config_manager.h"
#include "modules/perception/proto/traffic_light/recognizer_config.pb.h"
#include "modules/perception/traffic_light/interface/base_recognizer.h"
#include "modules/perception/traffic_light/interface/green_interface.h"
......@@ -54,9 +55,7 @@ class UnityRecognize : public BaseRecognizer {
std::shared_ptr<IRefine> classify_day_;
std::shared_ptr<IRefine> classify_night_;
bool InitModel(const ConfigManager *config_manager,
const ModelConfig *model_config,
std::shared_ptr<IRefine> *classify);
traffic_light::recognizer_config::ModelConfigs config_;
};
REGISTER_RECOGNIZER(UnityRecognize);
......
/******************************************************************************
* Copyright 2018 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/perception/traffic_light/recognizer/unity_recognize.h"
#include "gtest/gtest.h"
namespace apollo {
namespace perception {
namespace traffic_light {
TEST(UnityRecognizeTest, load_proto) {
UnityRecognize ur;
EXPECT_TRUE(ur.Init());
}
} // namespace traffic_light
} // namespace perception
} // namespace apollo
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册