Skip to content

Commit c6b611c

Browse files
Feature/closed set bag (#20)
* start on closed set bag executable * finish first draft of executable * make unspecified model file fail check * make config output clearer * use cli and fix issues * fix substr bug * use ianvs reader * add missing deps and new utility func * clean up rotation behavior and console logging * add progress bar
1 parent 6160903 commit c6b611c

File tree

7 files changed

+455
-6
lines changed

7 files changed

+455
-6
lines changed

semantic_inference/include/semantic_inference/logging.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,30 @@ class LogEntry {
8686
std::stringstream ss_;
8787
};
8888

89-
struct CoutSink : logging::LogSink {
89+
/**
90+
* @brief Log messages to cout/cerr as appropriate
91+
*/
92+
struct CoutSink : LogSink {
9093
CoutSink(Level level = Level::INFO);
9194
virtual ~CoutSink() = default;
9295

93-
void dispatch(const logging::LogEntry& entry) const override;
96+
void dispatch(const LogEntry& entry) const override;
9497

9598
Level level;
9699
};
97100

101+
/**
102+
* @brief Forward everything to cout without log-levels or optionally prefix
103+
*/
104+
struct SimpleSink : LogSink {
105+
SimpleSink(Level level = Level::INFO, bool with_prefix = false);
106+
virtual ~SimpleSink() = default;
107+
void dispatch(const LogEntry& entry) const override;
108+
109+
const Level level;
110+
const bool with_prefix;
111+
};
112+
98113
void setConfigUtilitiesLogger();
99114

100115
} // namespace logging

semantic_inference/src/logging.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ void CoutSink::dispatch(const logging::LogEntry& entry) const {
117117
}
118118
}
119119

120+
SimpleSink::SimpleSink(Level level, bool with_prefix)
121+
: level(level), with_prefix(with_prefix) {}
122+
123+
void SimpleSink::dispatch(const LogEntry& entry) const {
124+
if (entry.level < level) {
125+
// skip ignored entries
126+
return;
127+
}
128+
129+
std::stringstream ss;
130+
if (with_prefix) {
131+
ss << entry.prefix();
132+
}
133+
134+
ss << entry.message();
135+
std::cout << ss.str() << std::endl;
136+
}
137+
120138
struct SlogLogger : config::internal::Logger {
121139
void logImpl(const config::internal::Severity severity,
122140
const std::string& message) override {

semantic_inference/src/model.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Model::Model(const ModelConfig& config)
212212
engine_ = buildEngineFromOnnx(model, *runtime_);
213213
SLOG(INFO) << "Finished building engine";
214214
} else {
215-
SLOG(INFO) << "Loaded engine file";
215+
SLOG(DEBUG) << "Loaded engine file";
216216
}
217217

218218
if (!engine_) {
@@ -226,19 +226,19 @@ Model::Model(const ModelConfig& config)
226226
throw std::runtime_error("failed to set up trt context");
227227
}
228228

229-
SLOG(INFO) << "Execution context started";
229+
SLOG(DEBUG) << "Execution context started";
230230

231231
if (cudaStreamCreate(&stream_) != cudaSuccess) {
232232
SLOG(ERROR) << "Creating cuda stream failed!";
233233
throw std::runtime_error("failed to set up cuda stream");
234234
} else {
235-
SLOG(INFO) << "CUDA stream started";
235+
SLOG(DEBUG) << "CUDA stream started";
236236
}
237237

238238
initialized_ = true;
239239

240240
info_ = ModelInfo(*engine_);
241-
SLOG(INFO) << info_;
241+
SLOG(DEBUG) << info_;
242242
if (!info_) {
243243
SLOG(ERROR) << "Invalid engine for segmentation!";
244244
throw std::runtime_error("invalid model");

semantic_inference/src/model_config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void declare_config(ModelConfig& config) {
7272
field(config.color, "color");
7373
field(config.depth, "depth");
7474
// checks
75+
checkCondition(!config.model_file.empty(), "model_file required");
7576
check<Path::Exists>(config.model_path(), "model_file");
7677
checkIsOneOf(config.log_severity,
7778
{"INTERNAL_ERROR", "ERROR", "WARNING", "INFO", "VERBOSE"},

semantic_inference_ros/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ endif()
1111

1212
find_package(ament_cmake REQUIRED)
1313
find_package(ament_cmake_python REQUIRED)
14+
find_package(ament_index_cpp REQUIRED)
15+
find_package(CLI11 REQUIRED)
1416
find_package(cv_bridge REQUIRED)
1517
find_package(ianvs REQUIRED)
1618
find_package(image_geometry REQUIRED)
1719
find_package(message_filters REQUIRED)
1820
find_package(rclcpp REQUIRED)
1921
find_package(rclcpp_components REQUIRED)
22+
find_package(rosbag2_transport REQUIRED)
2023
find_package(semantic_inference REQUIRED)
2124
find_package(tf2_eigen REQUIRED)
2225
find_package(tf2_ros REQUIRED)
@@ -68,6 +71,12 @@ rclcpp_components_register_node(
6871
${PROJECT_NAME} PLUGIN semantic_inference::RGBDSegmentationNode EXECUTABLE rgbd_closed_set_node
6972
)
7073

74+
add_executable(closed_set_rosbag_writer app/closed_set_rosbag_writer.cpp)
75+
target_link_libraries(
76+
closed_set_rosbag_writer PUBLIC ${PROJECT_NAME} cv_bridge::cv_bridge ianvs::ianvs_rosbag
77+
rosbag2_transport::rosbag2_transport CLI11::CLI11
78+
)
79+
7180
install(
7281
TARGETS ${PROJECT_NAME}
7382
EXPORT ${PROJECT_NAME}-targets
@@ -77,6 +86,7 @@ install(
7786
install(PROGRAMS app/image_embedding_node app/open_set_node app/text_embedding_node
7887
DESTINATION lib/${PROJECT_NAME}
7988
)
89+
install(TARGETS closed_set_rosbag_writer RUNTIME DESTINATION lib/${PROJECT_NAME})
8090
install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION include/${PROJECT_NAME}/)
8191
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
8292
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})

0 commit comments

Comments
 (0)