Skip to content

Commit 7dd097d

Browse files
YoheiMishinamitsudome-rharihitodeyukkysaitonnmm
authoredDec 6, 2021
feat: add lidar apollo instance segmentation package (autowarefoundation#115)
* release v0.4.0 * check if gdown command exists (autowarefoundation#707) * Fix/cublas dependency (autowarefoundation#849) * fix cublas depencency * fix cublas depencency * remove ROS1 packages temporarily Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * Revert "remove ROS1 packages temporarily" This reverts commit b641153235b8c3ec5b5c5a052179c53434e66d7c. Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * add COLCON_IGNORE to ros1 packages Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * Rename launch files to launch.xml (autowarefoundation#28) * Port lidar apollo instance segmentation (autowarefoundation#98) * port lidar_apollo_instance_segmentation Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * move shared_from_this out of constructor Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * fix launch file Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * fix warnings Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * change rclcpp::Node::SharedPtr to raw pointer Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * uncomment publish of debug topic Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * Rename h files to hpp (autowarefoundation#142) * Change includes * Rename files * Adjustments to make things compile * Other packages * Adjust copyright notice on 532 out of 699 source files (autowarefoundation#143) * Use quotes for includes where appropriate (autowarefoundation#144) * Use quotes for includes where appropriate * Fix lint tests * Make tests pass hopefully * Run uncrustify on the entire Pilot.Auto codebase (autowarefoundation#151) * Run uncrustify on the entire Pilot.Auto codebase * Exclude open PRs * [tensorrt_yolo3][lidar_apollo_instance_segmentation] fix objection recognition headers (autowarefoundation#197) Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * adding linters to lidar_apollo_instance_segmentation (autowarefoundation#173) * Ros2 v0.8.0 lidar apollo instance segmentation (autowarefoundation#256) * restore file name for v0.8.0 update Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * fix typos in perception (autowarefoundation#862) * Revert "restore file name for v0.8.0 update" This reverts commit f8e44568acf0613a0385c9323f2d25bcf45025d2. Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * add use_sim-time option (autowarefoundation#454) * Format launch files (autowarefoundation#1219) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix reliability (autowarefoundation#1222) * fix reliability * use sensor data qos * Unify Apache-2.0 license name (autowarefoundation#1242) * Remove use_sim_time for set_parameter (autowarefoundation#1260) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Perception components (autowarefoundation#1368) * [bev_optical_flow]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [object_merger]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [object_range_splitter]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [shape_estimation]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [map_based_prediction]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [naive_path_prediction]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [roi_image_saver]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [lidar_apollo_instance_segmentation]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [object_flow_fusion]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [traffic_light_map_based_detector]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [dynamic_object_visualization]: component node Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix typo Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * [lidar_apollo_instance_segmentation]: Change subscriber queue size(5 to 1) (autowarefoundation#1570) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Add pre-commit (autowarefoundation#1560) * add pre-commit * add pre-commit-config * add additional settings for private repository * use default pre-commit-config * update pre-commit setting * Ignore whitespace for line breaks in markdown * Update .github/workflows/pre-commit.yml Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * exclude svg * remove pretty-format-json * add double-quote-string-fixer * consider COLCON_IGNORE file when seaching modified package * format file * pre-commit fixes * Update pre-commit.yml * Update .pre-commit-config.yaml Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: pre-commit <pre-commit@example.com> Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> * Fix build error with TensorRT v8 (autowarefoundation#1612) * Fix build error with TensorRT v8 Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix typo Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Add markdownlint and prettier (autowarefoundation#1661) * Add markdownlint and prettier Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Ignore .param.yaml Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix MD029 (autowarefoundation#1813) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix -Wunused-parameter (autowarefoundation#1836) * Fix -Wunused-parameter Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix mistake Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix spell * Fix lint issues Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Ignore flake8 warnings Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Co-authored-by: Hiroki OTA <hiroki.ota@tier4.jp> * suppress warnings in perception directory (autowarefoundation#1866) * add maybe unused * add Werror * Ignore -Wdeprecated-declarations in lidar_apollo_instance_segmentation (autowarefoundation#1875) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Refactor shape estimation for detection by tracking (autowarefoundation#1861) * refactor * modification due to refactoring * cosmetic change and add virtual * change to lib * fix typo * bug fix * cosmetic change * bug fix * add constexpr * cosmetic change * cosmetic change * cosmetic change * cosmetic change * add sort-package-xml hook in pre-commit (autowarefoundation#1881) * add sort xml hook in pre-commit * change retval to exit_status * rename * add prettier plugin-xml * use early return * add license note * add tier4 license * restore prettier * change license order * move local hooks to public repo * move prettier-xml to pre-commit-hooks-ros * update version for bug-fix * apply pre-commit * Detection by tracker (autowarefoundation#1910) * initial commit * backup * apply format * cosmetic change * implement divided under segmenterd clusters * cosmetic change * bug fix * bug fix * bug fix * modify launch * add debug and bug fix * bug fix * bug fix * add no found tracked object * modify parameters and cmake * bug fix * remove debug info * add readme * modify clustering launch * run pre-commit * cosmetic change * cosmetic change * cosmetic change * apply markdownlint * modify launch * modify for cpplint * modify qos * change int to size_T * bug fix * change perception qos * Update perception/object_recognition/detection/detection_by_tracker/package.xml Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * cosmetic change * cosmetic change * fix launch * Update perception/object_recognition/detection/detection_by_tracker/src/utils.cpp Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * modify header include order * change include order * Update perception/object_recognition/detection/detection_by_tracker/src/detection_by_tracker_core.cpp Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * change to std::optional * cosmetic change * Update perception/object_recognition/detection/detection_by_tracker/src/detection_by_tracker_core.cpp Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * Update perception/object_recognition/detection/detection_by_tracker/src/detection_by_tracker_core.cpp Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * bug fix * modify readme Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> * Change formatter to clang-format and black (autowarefoundation#2332) * Revert "Temporarily comment out pre-commit hooks" This reverts commit 748e9cdb145ce12f8b520bcbd97f5ff899fc28a3. * Replace ament_lint_common with autoware_lint_common Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Remove ament_cmake_uncrustify and ament_clang_format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply Black Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix for cpplint * Fix include double quotes to angle brackets Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Add COLCON_IGNORE (autowarefoundation#500) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Port lidar apollo instance segmentation to .auto (autowarefoundation#548) * Port lidar apollo instance segmentation to .auto Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Run pre-commit Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Update document for lidar apollo instance segmentation (autowarefoundation#597) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Sync .auto branch with the latest branch in internal repository (autowarefoundation#691) * add trajectory point offset in rviz plugin (autowarefoundation#2270) * sync rc rc/v0.23.0 (autowarefoundation#2258) * fix interpolation for insert point (autowarefoundation#2228) * fix interpolation for insert point * to prev interpolation pkg * Revert "to prev interpolation pkg" This reverts commit 9eb145b5d36e297186015fb17c267ccd5b3c21ef. Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> Co-authored-by: taikitanaka <ttatcoder@outlook.jp> * fix topic name (autowarefoundation#2266) Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Add namespace to diag for dual_return_filter (autowarefoundation#2269) * Add a function to make 'geometry_msgs::msg::TransformStamped' (autowarefoundation#2250) * Add a function to make 'geometry_msgs::msg::TransformStamped' * Add 'child_frame_id' as an argument of 'pose2transform' * Simplify marker scale initialization (autowarefoundation#2286) * Fix/crosswalk polygon (autowarefoundation#2279) * extend crosswalk polygon * improve readability * fix polygon shape * Add warning when decel distance calculation fails (autowarefoundation#2289) Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * [motion_velocity_smoother] ignore debug print (autowarefoundation#2292) * cosmetic change Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * cahnge severity from WARN to DEBUG for debug info Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * use util for stop_watch Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix map based prediction (autowarefoundation#2200) * fix map based prediction * fix format * change map based prediction * fix spells * fix spells in comments * fix for cpplint * fix some problems * fix format and code for clang-tidy * fix space for cpplint * Update Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md * fix vector access method * fix readme format * add parameter * Update perception/object_recognition/prediction/map_based_prediction/Readme.md Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Update perception/object_recognition/prediction/map_based_prediction/Readme.md Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Update perception/object_recognition/prediction/map_based_prediction/Readme.md Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Update Readme.md * Update perception/object_recognition/prediction/map_based_prediction/Readme.md Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * remove failure condition for 0 velocity trajectory (autowarefoundation#2295) Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * [mpc_follower] remove stop distance condition from stopState decision (autowarefoundation#1916) * [mpc_follower] remove stop distance condition from stopState decision Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add invalid index handling Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Move the debug marker initialization part to another file (autowarefoundation#2288) * Move the debug marker initialization part to 'debug.cpp' * Make 'isLocalOptimalSolutionOscillation' independent from 'NDTScanMatcher' (autowarefoundation#2300) * Remove an unused function 'getTransform' (autowarefoundation#2301) * Simplify iteration of initial poses (autowarefoundation#2310) * Make a transform object const (autowarefoundation#2311) * Represent poses in 'std::vector' instead of 'geometry_msgs::msg::PoseArray' (autowarefoundation#2312) * Feature/no stopping area (autowarefoundation#2163) * add no stopping area module to behavior velocity planner * apply utils * add polygon interpolation module order stopline around area is considered * devide jpass udge with stop line polygon * update docs * rename file name * update to latest * minor change for marker * update license Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> * update license Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> * update license Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> * update license Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> * minor fix * add parameter tuning at experiment * update readme * format doc * apply comments * add exception gurd * cosmetic change * fix ament * fix typo and remove for statement * & to " " * better ns * return pass judge param * add missing stoppable condition * add clear pass judge and stoppable flag * add comment * precommit fix * cpplint Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> * sync rc rc/v0.23.0 (autowarefoundation#2281) * Fix side shift planner (autowarefoundation#2171) (autowarefoundation#2172) * add print debug Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * remove forward shift points when adding new point Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * remove debug print Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * format Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * Fix remove threshold Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Fix/pull out and pull over (autowarefoundation#2175) * delete unnecessary check * fix condition of starting pull out * Add emergency status API (autowarefoundation#2174) (autowarefoundation#2182) * Fix/mpc reset prev result (autowarefoundation#2185) (autowarefoundation#2195) * reset prev result * clean code * reset only raw_steer_cmd * Update control/mpc_follower/src/mpc_follower_core.cpp Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * [hotfix] 1 path point exception after resampling (autowarefoundation#2204) * fix 1 path point exception after resampling Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> * [hotfix] Fix lane ids (autowarefoundation#2211) * Fix lane ids * Prevent acceleration on avoidance (autowarefoundation#2214) * prevent acceleration on avoidance Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * fix param name Signed-off-by: TakaHoribe <horibe.takamasa@gmail.com> * parametrize avoidance acc Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * change param name Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix typo Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Fix qos in roi cluster fusion (autowarefoundation#2218) * fix confidence (autowarefoundation#2220) * too high confidence (autowarefoundation#2229) * Fix/obstacle stop 0.23.0 (autowarefoundation#2232) * fix unexpected slow down in sharp curves (autowarefoundation#2181) * Fix/insert implementation (autowarefoundation#2186) Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> * [hotfix] Remove exception in avoidance module (autowarefoundation#2233) * Remove exception * Fix clock * Remove blank line * Update traffic light state if ref stop point is ahead of previous one (autowarefoundation#2197) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * fix interpolation for insert point (autowarefoundation#2228) * fix interpolation for insert point * to prev interpolation pkg * fix index (autowarefoundation#2265) * turn signal calculation (#2280) * add turn signal funtion in path shifter * add ros parameters Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Takagi, Isamu <43976882+isamu-takagi@users.noreply.github.com> Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> Co-authored-by: Sugatyon <32741405+Sugatyon@users.noreply.github.com> * [behavior_path_planner] fix sudden path change around ego (autowarefoundation#2305) (autowarefoundation#2318) * fix return-from-ego shift point generation logic Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * change param for trimSimilarGradShiftPoint Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add comment for issue Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * update comment Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * replace code with function (logic has not changed) Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * move func to cpp Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add comment for issue Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix typo Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Update planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Update planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Add functions to make stamped scalar messages (autowarefoundation#2317) * Fix/object yaw in intersection module (autowarefoundation#2294) * fix object orientation * fix function name * add guard (autowarefoundation#2321) * reduce cost (double to float) (autowarefoundation#2298) * Add detail collision check (autowarefoundation#2274) * Add detail collision check Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Remove unused function Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix arc length Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Seperate time margin Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix parameter name Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Update Readme Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Address review: Add comment for TimeDistanceArray Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Run pre-commit Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix cpplint Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Add return for empty polygon Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * update CenterPoint (autowarefoundation#2222) * update to model trained by mmdet3d * add vizualizer (debug) * for multi-frame inputs * chagne config * use autoware_utils::pi * project specific model and param * rename vfe -> encoder * rename general to common * update download link * update * fix * rename model_name * change training toolbox link * chage lint package * fix test error * commit suggestion * Feature/lane change detection (autowarefoundation#2331) * add old information deleter * fix access bug * change to deque * update obstacle buffer * fix some bugs * add lane change detector * make a update lanelet function * fix code style * parameterize essential values * Update perception/object_recognition/prediction/map_based_prediction/src/map_based_prediction_ros.cpp Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * fix slash position * remove unnecessary lines * fix format * fix format * change to new enum * fix format * fix typo and add guard * change funciton name * add lane change description Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> * Add Planning Evaluator (autowarefoundation#2293) * Add prototype planning evaluator Produced data for dist between points, curvature, and relative angle * Cleanup the code to make adding metrics easier * Add remaining basic metrics (length, duration, vel, accel, jerk) * Add motion_evaluator to evaluate the actual ego motion + code cleanup * Add deviation metrics * Add naive stability metric * Handle invalid stat (TODO: fix the output file formatting) * Add parameter file and cleanup * Add basic obstacle metric (TTC not yet implemented) and fix output file format * Add basic time to collision * Add lateral-distance based stability metric * Add check (at init time) that metrics' maps are complete * Publish metrics as ParamaterDeclaration msg (for openscenario) * Use lookahead and start from ego_pose when calculating stability metrics * Code cleanup * Fix lint * Add tests * Fix bug with Frechet dist and the last traj point * Finish implementing tests * Fix lint * Code cleanup * Update README.md * Remove unused metric * Change msg type of published metrics to DiagnosticArray * fix format to fix pre-commit check Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix yaml format to fix pre-commit check Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix yaml format Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * apply clang-format Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * apply clang-format Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Update planning/planning_diagnostics/planning_evaluator/include/planning_evaluator/planning_evaluator_node.hpp * Update planning/planning_diagnostics/planning_evaluator/test/test_planning_evaluator_node.cpp * Update planning/planning_diagnostics/planning_evaluator/test/test_planning_evaluator_node.cpp * change lint format to autoware_lint_common Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Add keep braking function at driving state (autowarefoundation#2346) * Add keep braking function at driving state Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Remove debug messages Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Fix format Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Change diag_updater's pediod from default to 0.1sec (autowarefoundation#2348) * add cross judgement and common signal function (autowarefoundation#2319) * merge branch turn_signal_common * add turn signal function in signal decider * add cross judge in path_utilities and delete from turn_signal_decider * remove original signal calculation in lane change * omit substitution * replace turn signal decider in pull over function * modify cross judge logic * replace turn signal decider in avoidance * add readme of turn signal * update * delete print debug * update * delete lane change decider in path shifter * delete blank line * fix indent * fix typo * fix typo * decrease nest * run pre commit * Add 0 limit at forward jerk velocity filter (autowarefoundation#2340) Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * add time offset param to point cloud concatenation (autowarefoundation#2303) * add offset param * clang-format Co-authored-by: Akihito OHSATO <aohsato@gmail.com> * Feature/add doc for keep braking function at driving state (autowarefoundation#2366) * Add the description of brake keeping Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Add the english document Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Improve description Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Add english description Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * Fix include files (autowarefoundation#2339) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix behavior intersection module * fix behavior no stopping area module * fix planning_evaluator * fix motion_velocity_smoother * rename variable * Revert "[mpc_follower] remove stop distance condition from stopState decision (autowarefoundation#1916)" This reverts commit ff4f0b5a844d1f835f1b93bd3b36a76747b0cd02. * Revert "Add keep braking function at driving state (autowarefoundation#2346)" This reverts commit f0478187db4c28bf6092c198723dcc5ec11a9c70. * Revert "Feature/add doc for keep braking function at driving state (autowarefoundation#2366)" This reverts commit 66de2f3924a479049fce2d5c5c6b579cacbd3e49. * Fix orientation availability in centerpoint Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * fix test_trajectory.cpp * add target link libraries * Use .auto msg in test code for planniing evaluator Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * fix include Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> Co-authored-by: Takayuki Murooka <takayuki5168@gmail.com> Co-authored-by: autoware-iv-sync-ci[bot] <87871706+autoware-iv-sync-ci[bot]@users.noreply.github.com> Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> Co-authored-by: taikitanaka <ttatcoder@outlook.jp> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takeshi Miura <57553950+1222-takeshi@users.noreply.github.com> Co-authored-by: Takeshi Ishita <ishitah.takeshi@gmail.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> Co-authored-by: Makoto Kurihara <mkuri8m@gmail.com> Co-authored-by: purewater0901 <43805014+purewater0901@users.noreply.github.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Takagi, Isamu <43976882+isamu-takagi@users.noreply.github.com> Co-authored-by: Sugatyon <32741405+Sugatyon@users.noreply.github.com> Co-authored-by: s-murakami-esol <81723883+s-murakami-esol@users.noreply.github.com> Co-authored-by: Yusuke Muramatsu <yukke42@users.noreply.github.com> Co-authored-by: Maxime CLEMENT <78338830+maxime-clem@users.noreply.github.com> Co-authored-by: Shunsuke Miura <37187849+miursh@users.noreply.github.com> Co-authored-by: Shinnosuke Hirakawa <8327162+0x126@users.noreply.github.com> Co-authored-by: Akihito OHSATO <aohsato@gmail.com> Co-authored-by: Kenji Miyake <kenji.miyake@tier4.jp> Co-authored-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> Co-authored-by: Daichi Murakami <harihitode@gmail.com> Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com> Co-authored-by: Nikolai Morin <nnmmgit@gmail.com> Co-authored-by: Ryohsuke Mitsudome <43976834+mitsudome-r@users.noreply.github.com> Co-authored-by: nik-tier4 <71747268+nik-tier4@users.noreply.github.com> Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Co-authored-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Co-authored-by: pre-commit <pre-commit@example.com> Co-authored-by: Hiroki OTA <hiroki.ota@tier4.jp> Co-authored-by: Takayuki Murooka <takayuki5168@gmail.com> Co-authored-by: autoware-iv-sync-ci[bot] <87871706+autoware-iv-sync-ci[bot]@users.noreply.github.com> Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> Co-authored-by: taikitanaka <ttatcoder@outlook.jp> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takeshi Miura <57553950+1222-takeshi@users.noreply.github.com> Co-authored-by: Takeshi Ishita <ishitah.takeshi@gmail.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> Co-authored-by: Makoto Kurihara <mkuri8m@gmail.com> Co-authored-by: purewater0901 <43805014+purewater0901@users.noreply.github.com> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Takagi, Isamu <43976882+isamu-takagi@users.noreply.github.com> Co-authored-by: Sugatyon <32741405+Sugatyon@users.noreply.github.com> Co-authored-by: s-murakami-esol <81723883+s-murakami-esol@users.noreply.github.com> Co-authored-by: Yusuke Muramatsu <yukke42@users.noreply.github.com> Co-authored-by: Maxime CLEMENT <78338830+maxime-clem@users.noreply.github.com> Co-authored-by: Shunsuke Miura <37187849+miursh@users.noreply.github.com> Co-authored-by: Shinnosuke Hirakawa <8327162+0x126@users.noreply.github.com> Co-authored-by: Akihito OHSATO <aohsato@gmail.com> Co-authored-by: Kenji Miyake <kenji.miyake@tier4.jp>
1 parent dfe48bd commit 7dd097d

32 files changed

+4446
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data/*.caffemodel
2+
data/*.engine
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(lidar_apollo_instance_segmentation)
3+
4+
option(CUDA_VERBOSE "Verbose output of CUDA modules" OFF)
5+
6+
# set flags for CUDA availability
7+
option(CUDA_AVAIL "CUDA available" OFF)
8+
find_package(CUDA)
9+
if (CUDA_FOUND)
10+
find_library(CUBLAS_LIBRARIES cublas HINTS
11+
${CUDA_TOOLKIT_ROOT_DIR}/lib64
12+
${CUDA_TOOLKIT_ROOT_DIR}/lib
13+
)
14+
if (CUDA_VERBOSE)
15+
message("CUDA is available!")
16+
message("CUDA Libs: ${CUDA_LIBRARIES}")
17+
message("CUDA Headers: ${CUDA_INCLUDE_DIRS}")
18+
endif ()
19+
set(CUDA_AVAIL ON)
20+
else()
21+
message("CUDA NOT FOUND")
22+
set(CUDA_AVAIL OFF)
23+
endif (CUDA_FOUND)
24+
25+
# set flags for TensorRT availability
26+
option(TRT_AVAIL "TensorRT available" OFF)
27+
# try to find the tensorRT modules
28+
find_library(NVINFER NAMES nvinfer)
29+
find_library(NVPARSERS NAMES nvparsers)
30+
find_library(NVCAFFE_PARSER NAMES nvcaffe_parser)
31+
find_library(NVINFER_PLUGIN NAMES nvinfer_plugin)
32+
if(NVINFER AND NVPARSERS AND NVCAFFE_PARSER AND NVINFER_PLUGIN)
33+
if (CUDA_VERBOSE)
34+
message("TensorRT is available!")
35+
message("NVINFER: ${NVINFER}")
36+
message("NVPARSERS: ${NVPARSERS}")
37+
message("NVCAFFE_PARSER: ${NVCAFFE_PARSER}")
38+
endif ()
39+
set(TRT_AVAIL ON)
40+
else()
41+
message("TensorRT is NOT Available")
42+
set(TRT_AVAIL OFF)
43+
endif()
44+
45+
# set flags for CUDNN availability
46+
option(CUDNN_AVAIL "CUDNN available" OFF)
47+
# try to find the CUDNN module
48+
find_library(CUDNN_LIBRARY
49+
NAMES libcudnn.so${__cudnn_ver_suffix} libcudnn${__cudnn_ver_suffix}.dylib ${__cudnn_lib_win_name}
50+
PATHS $ENV{LD_LIBRARY_PATH} ${__libpath_cudart} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}
51+
PATH_SUFFIXES lib lib64 bin
52+
DOC "CUDNN library." )
53+
if(CUDNN_LIBRARY)
54+
if (CUDA_VERBOSE)
55+
message("CUDNN is available!")
56+
message("CUDNN_LIBRARY: ${CUDNN_LIBRARY}")
57+
endif ()
58+
set(CUDNN_AVAIL ON)
59+
else()
60+
message("CUDNN is NOT Available")
61+
set(CUDNN_AVAIL OFF)
62+
endif()
63+
64+
find_program(GDOWN_AVAIL "gdown")
65+
if (NOT GDOWN_AVAIL)
66+
message("gdown: command not found. External files could not be downloaded.")
67+
endif()
68+
if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
69+
# download weight files
70+
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/data")
71+
if (NOT EXISTS "${PATH}")
72+
execute_process(COMMAND mkdir -p ${PATH})
73+
endif()
74+
set(FILE "${PATH}/vlp-16.caffemodel")
75+
message(STATUS "Checking and downloading vlp-16.caffemodel")
76+
if (NOT EXISTS "${FILE}")
77+
message(STATUS "... file does not exist. Downloading now ...")
78+
execute_process(COMMAND gdown "https://drive.google.com/uc?id=1bbO_eeGG5HUqyUiAYjOd6hUn-Zma0mMJ" -O ${PATH}/vlp-16.caffemodel)
79+
endif()
80+
set(FILE "${PATH}/hdl-64.caffemodel")
81+
message(STATUS "Checking and downloading hdl-64.caffemodel")
82+
if (NOT EXISTS "${FILE}")
83+
message(STATUS "... file does not exist. Downloading now ...")
84+
execute_process(COMMAND gdown "https://drive.google.com/uc?id=1ZdB6V3jua3GmtYuY9NR1nc9QZe_ChjkP" -O ${PATH}/hdl-64.caffemodel)
85+
endif()
86+
set(FILE "${PATH}/vls-128.caffemodel")
87+
message(STATUS "Checking and downloading vls-128.caffemodel")
88+
if (NOT EXISTS "${FILE}")
89+
message(STATUS "... file does not exist. Downloading now ...")
90+
execute_process(COMMAND gdown "https://drive.google.com/uc?id=1izpNotNxS6mrYIzJwHQ_EyX_IPDU-MBr" -O ${PATH}/vls-128.caffemodel)
91+
endif()
92+
93+
find_package(ament_cmake_auto REQUIRED)
94+
ament_auto_find_build_dependencies()
95+
find_package(PCL REQUIRED)
96+
97+
if(NOT CMAKE_CXX_STANDARD)
98+
set(CMAKE_CXX_STANDARD 14)
99+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
100+
set(CMAKE_CXX_EXTENSIONS OFF)
101+
endif()
102+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
103+
add_compile_options(-Wall -Wextra -Wpedantic -Wno-deprecated-declarations -Werror)
104+
endif()
105+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3")
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_MWAITXINTRIN_H_INCLUDED")
107+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")
108+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STRICT_ANSI__")
109+
110+
include_directories(
111+
lib/include
112+
${CUDA_INCLUDE_DIRS}
113+
${PCL_INCLUDE_DIRS}
114+
)
115+
116+
ament_auto_add_library(tensorrt_apollo_cnn_lib SHARED
117+
lib/src/TrtNet.cpp
118+
)
119+
120+
target_link_libraries(tensorrt_apollo_cnn_lib
121+
${NVINFER}
122+
${NVCAFFE_PARSER}
123+
${NVINFER_PLUGIN}
124+
${CUDA_LIBRARIES}
125+
${CUBLAS_LIBRARIES}
126+
${CUDA_curand_LIBRARY}
127+
${CUDNN_LIBRARY}
128+
${PCL_LIBRARIES}
129+
)
130+
131+
ament_auto_add_library(lidar_apollo_instance_segmentation SHARED
132+
src/node.cpp
133+
src/detector.cpp
134+
src/log_table.cpp
135+
src/feature_generator.cpp
136+
src/feature_map.cpp
137+
src/cluster2d.cpp
138+
src/debugger.cpp
139+
)
140+
141+
target_link_libraries(lidar_apollo_instance_segmentation
142+
tensorrt_apollo_cnn_lib
143+
)
144+
145+
rclcpp_components_register_node(lidar_apollo_instance_segmentation
146+
PLUGIN "LidarInstanceSegmentationNode"
147+
EXECUTABLE lidar_apollo_instance_segmentation_node
148+
)
149+
150+
if(BUILD_TESTING)
151+
find_package(ament_lint_auto REQUIRED)
152+
ament_lint_auto_find_test_dependencies()
153+
endif()
154+
155+
ament_auto_package(INSTALL_TO_SHARE
156+
launch
157+
config
158+
data
159+
)
160+
161+
else()
162+
find_package(ament_cmake_auto REQUIRED)
163+
ament_auto_find_build_dependencies()
164+
165+
if(BUILD_TESTING)
166+
find_package(ament_lint_auto REQUIRED)
167+
ament_lint_auto_find_test_dependencies()
168+
endif()
169+
170+
# to avoid launch file missing without a gpu
171+
ament_auto_package(INSTALL_TO_SHARE
172+
launch
173+
)
174+
175+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# lidar_apollo_instance_segmentation
2+
3+
![Peek 2020-04-07 00-17](https://user-images.githubusercontent.com/8327598/78574862-92507d80-7865-11ea-9a2d-56d3453bdb7a.gif)
4+
5+
## Purpose
6+
7+
This node segments 3D pointcloud data from lidar sensors into obstacles, e.g., cars, trucks, bicycles, and pedestrians
8+
based on CNN based model and obstacle clustering method.
9+
10+
## Inner-workings / Algorithms
11+
12+
See the [original design](https://github.com/ApolloAuto/apollo/blob/master/docs/specs/3d_obstacle_perception.md) by Apollo.
13+
14+
## Inputs / Outputs
15+
16+
### Input
17+
18+
| Name | Type | Description |
19+
| ------------------ | ------------------------- | ---------------------------------- |
20+
| `input/pointcloud` | `sensor_msgs/PointCloud2` | Pointcloud data from lidar sensors |
21+
22+
### Output
23+
24+
| Name | Type | Description |
25+
| --------------------------- | ----------------------------------------------------- | ------------------------------------------------- |
26+
| `output/labeled_clusters` | `autoware_perception_msgs/DetectedObjectsWithFeature` | Detected objects with labeled pointcloud cluster. |
27+
| `debug/instance_pointcloud` | `sensor_msgs/PointCloud2` | Segmented pointcloud for visualization. |
28+
29+
## Parameters
30+
31+
### Node Parameters
32+
33+
None
34+
35+
### Core Parameters
36+
37+
| Name | Type | Default Value | Description |
38+
| ----------------------- | ------ | -------------------- | ---------------------------------------------------------------------------------- |
39+
| `score_threshold` | double | 0.8 | If the score of a detected object is lower than this value, the object is ignored. |
40+
| `range` | int | 60 | Half of the length of feature map sides. [m] |
41+
| `width` | int | 640 | The grid width of feature map. |
42+
| `height` | int | 640 | The grid height of feature map. |
43+
| `engine_file` | string | "vls-128.engine" | The name of TensorRT engine file for CNN model. |
44+
| `prototxt_file` | string | "vls-128.prototxt" | The name of prototxt file for CNN model. |
45+
| `caffemodel_file` | string | "vls-128.caffemodel" | The name of caffemodel file for CNN model. |
46+
| `use_intensity_feature` | bool | true | The flag to use intensity feature of pointcloud. |
47+
| `use_constant_feature` | bool | false | The flag to use direction and distance feature of pointcloud. |
48+
| `target_frame` | string | "base_link" | Pointcloud data is transformed into this frame. |
49+
| `z_offset` | int | 2 | z offset from target frame. [m] |
50+
51+
## Assumptions / Known limits
52+
53+
There is no training code for CNN model.
54+
55+
### Note
56+
57+
This package makes use of three external codes.
58+
The trained files are provided by apollo. The trained files are automatically downloaded when you build.
59+
60+
Original URL
61+
62+
- VLP-16 :
63+
<https://github.com/ApolloAuto/apollo/raw/88bfa5a1acbd20092963d6057f3a922f3939a183/modules/perception/production/data/perception/lidar/models/cnnseg/velodyne16/deploy.caffemodel>
64+
- HDL-64 :
65+
<https://github.com/ApolloAuto/apollo/raw/88bfa5a1acbd20092963d6057f3a922f3939a183/modules/perception/production/data/perception/lidar/models/cnnseg/velodyne64/deploy.caffemodel>
66+
- VLS-128 :
67+
<https://github.com/ApolloAuto/apollo/raw/91844c80ee4bd0cc838b4de4c625852363c258b5/modules/perception/production/data/perception/lidar/models/cnnseg/velodyne128/deploy.caffemodel>
68+
69+
Supported lidars are velodyne 16, 64 and 128, but you can also use velodyne 32 and other lidars with good accuracy.
70+
71+
1. [apollo 3D Obstacle Perception description](https://github.com/ApolloAuto/apollo/blob/master/docs/specs/3d_obstacle_perception.md)
72+
73+
```txt
74+
/******************************************************************************
75+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
76+
*
77+
* Licensed under the Apache License, Version 2.0 (the "License");
78+
* you may not use this file except in compliance with the License.
79+
* You may obtain a copy of the License at
80+
*
81+
* http://www.apache.org/licenses/LICENSE-2.0
82+
*
83+
* Unless required by applicable law or agreed to in writing, software
84+
* distributed under the License is distributed on an "AS IS" BASIS,
85+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86+
* See the License for the specific language governing permissions and
87+
* limitations under the License.
88+
*****************************************************************************/
89+
```
90+
91+
2. [tensorRTWrapper](https://github.com/lewes6369/tensorRTWrapper) :
92+
It is used under the lib directory.
93+
94+
```txt
95+
MIT License
96+
97+
Copyright (c) 2018 lewes6369
98+
99+
Permission is hereby granted, free of charge, to any person obtaining a copy
100+
of this software and associated documentation files (the "Software"), to deal
101+
in the Software without restriction, including without limitation the rights
102+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
103+
copies of the Software, and to permit persons to whom the Software is
104+
furnished to do so, subject to the following conditions:
105+
106+
The above copyright notice and this permission notice shall be included in all
107+
copies or substantial portions of the Software.
108+
109+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
115+
SOFTWARE.
116+
```
117+
118+
3. [autoware_perception description](https://github.com/k0suke-murakami/autoware_perception/tree/feature/integration_baidu_seg/lidar_apollo_cnn_seg_detect)
119+
120+
```txt
121+
/*
122+
* Copyright 2018-2019 Autoware Foundation. All rights reserved.
123+
*
124+
* Licensed under the Apache License, Version 2.0 (the "License");
125+
* you may not use this file except in compliance with the License.
126+
* You may obtain a copy of the License at
127+
*
128+
* http://www.apache.org/licenses/LICENSE-2.0
129+
*
130+
* Unless required by applicable law or agreed to in writing, software
131+
* distributed under the License is distributed on an "AS IS" BASIS,
132+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133+
* See the License for the specific language governing permissions and
134+
* limitations under the License.
135+
*/
136+
```
137+
138+
### Special thanks
139+
140+
- [Apollo Project](https://github.com/ApolloAuto/apollo)
141+
- [lewes6369](https://github.com/lewes6369)
142+
- [Autoware Foundation](https://github.com/autowarefoundation/autoware)
143+
- [Kosuke Takeuchi](https://github.com/kosuke55) (TierIV Part timer)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**:
2+
ros__parameters:
3+
score_threshold: 0.1
4+
range: 70
5+
width: 672
6+
height: 672
7+
use_intensity_feature: true
8+
use_constant_feature: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**:
2+
ros__parameters:
3+
score_threshold: 0.1
4+
range: 70
5+
width: 672
6+
height: 672
7+
use_intensity_feature: true
8+
use_constant_feature: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**:
2+
ros__parameters:
3+
score_threshold: 0.1
4+
range: 90
5+
width: 864
6+
height: 864
7+
use_intensity_feature: false
8+
use_constant_feature: false

‎perception/lidar_apollo_instance_segmentation/data/hdl-64.prototxt

+685
Large diffs are not rendered by default.

‎perception/lidar_apollo_instance_segmentation/data/vlp-16.prototxt

+685
Large diffs are not rendered by default.

‎perception/lidar_apollo_instance_segmentation/data/vls-128.prototxt

+686
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
/*
15+
* Copyright 2018-2019 Autoware Foundation. All rights reserved.
16+
*
17+
* Licensed under the Apache License, Version 2.0 (the "License");
18+
* you may not use this file except in compliance with the License.
19+
* You may obtain a copy of the License at
20+
*
21+
* http://www.apache.org/licenses/LICENSE-2.0
22+
*
23+
* Unless required by applicable law or agreed to in writing, software
24+
* distributed under the License is distributed on an "AS IS" BASIS,
25+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
* See the License for the specific language governing permissions and
27+
* limitations under the License.
28+
*/
29+
30+
/******************************************************************************
31+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
32+
*
33+
* Licensed under the Apache License, Version 2.0 (the "License");
34+
* you may not use this file except in compliance with the License.
35+
* You may obtain a copy of the License at
36+
*
37+
* http://www.apache.org/licenses/LICENSE-2.0
38+
*
39+
* Unless required by applicable law or agreed to in writing, software
40+
* distributed under the License is distributed on an "AS IS" BASIS,
41+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42+
* See the License for the specific language governing permissions and
43+
* limitations under the License.
44+
*****************************************************************************/
45+
46+
#ifndef LIDAR_APOLLO_INSTANCE_SEGMENTATION__CLUSTER2D_HPP_
47+
#define LIDAR_APOLLO_INSTANCE_SEGMENTATION__CLUSTER2D_HPP_
48+
49+
#include "disjoint_set.hpp"
50+
#include "util.hpp"
51+
52+
#include <autoware_perception_msgs/msg/detected_object_with_feature.hpp>
53+
#include <autoware_perception_msgs/msg/detected_objects_with_feature.hpp>
54+
#include <std_msgs/msg/header.hpp>
55+
56+
#include <pcl/PointIndices.h>
57+
#include <pcl/point_cloud.h>
58+
#include <pcl/point_types.h>
59+
60+
#include <memory>
61+
#include <vector>
62+
63+
enum MetaType {
64+
META_UNKNOWN,
65+
META_SMALLMOT,
66+
META_BIGMOT,
67+
META_NONMOT,
68+
META_PEDESTRIAN,
69+
MAX_META_TYPE
70+
};
71+
72+
struct Obstacle
73+
{
74+
std::vector<int> grids;
75+
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_ptr;
76+
float score;
77+
float height;
78+
float heading;
79+
MetaType meta_type;
80+
std::vector<float> meta_type_probs;
81+
82+
Obstacle() : score(0.0), height(-5.0), heading(0.0), meta_type(META_UNKNOWN)
83+
{
84+
cloud_ptr.reset(new pcl::PointCloud<pcl::PointXYZI>);
85+
meta_type_probs.assign(MAX_META_TYPE, 0.0);
86+
}
87+
};
88+
89+
class Cluster2D
90+
{
91+
public:
92+
Cluster2D(const int rows, const int cols, const float range);
93+
94+
~Cluster2D() {}
95+
96+
void cluster(
97+
const std::shared_ptr<float> & inferred_data,
98+
const pcl::PointCloud<pcl::PointXYZI>::Ptr & pc_ptr, const pcl::PointIndices & valid_indices,
99+
float objectness_thresh, bool use_all_grids_for_clustering);
100+
101+
void filter(const std::shared_ptr<float> & inferred_data);
102+
void classify(const std::shared_ptr<float> & inferred_data);
103+
104+
void getObjects(
105+
const float confidence_thresh, const float height_thresh, const int min_pts_num,
106+
autoware_perception_msgs::msg::DetectedObjectsWithFeature & objects,
107+
const std_msgs::msg::Header & in_header);
108+
109+
autoware_perception_msgs::msg::DetectedObjectWithFeature obstacleToObject(
110+
const Obstacle & in_obstacle, const std_msgs::msg::Header & in_header);
111+
112+
private:
113+
int rows_;
114+
int cols_;
115+
int siz_;
116+
float range_;
117+
float scale_;
118+
float inv_res_x_;
119+
float inv_res_y_;
120+
std::vector<int> point2grid_;
121+
std::vector<Obstacle> obstacles_;
122+
std::vector<int> id_img_;
123+
124+
pcl::PointCloud<pcl::PointXYZI>::Ptr pc_ptr_;
125+
const std::vector<int> * valid_indices_in_pc_ = nullptr;
126+
127+
struct Node
128+
{
129+
Node * center_node;
130+
Node * parent;
131+
char node_rank;
132+
char traversed;
133+
bool is_center;
134+
bool is_object;
135+
int point_num;
136+
int obstacle_id;
137+
138+
Node()
139+
{
140+
center_node = nullptr;
141+
parent = nullptr;
142+
node_rank = 0;
143+
traversed = 0;
144+
is_center = false;
145+
is_object = false;
146+
point_num = 0;
147+
obstacle_id = -1;
148+
}
149+
};
150+
151+
inline bool IsValidRowCol(int row, int col) const { return IsValidRow(row) && IsValidCol(col); }
152+
153+
inline bool IsValidRow(int row) const { return row >= 0 && row < rows_; }
154+
155+
inline bool IsValidCol(int col) const { return col >= 0 && col < cols_; }
156+
157+
inline int RowCol2Grid(int row, int col) const { return row * cols_ + col; }
158+
159+
void traverse(Node * x);
160+
};
161+
162+
#endif // LIDAR_APOLLO_INSTANCE_SEGMENTATION__CLUSTER2D_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <rclcpp/rclcpp.hpp>
18+
19+
#include <autoware_perception_msgs/msg/detected_objects_with_feature.hpp>
20+
21+
class Debugger
22+
{
23+
public:
24+
explicit Debugger(rclcpp::Node * node);
25+
~Debugger() {}
26+
void publishColoredPointCloud(
27+
const autoware_perception_msgs::msg::DetectedObjectsWithFeature & input);
28+
29+
private:
30+
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr instance_pointcloud_pub_;
31+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "cluster2d.hpp"
18+
#include "feature_generator.hpp"
19+
#include "lidar_apollo_instance_segmentation/node.hpp"
20+
21+
#include <TrtNet.hpp>
22+
23+
#include <pcl/common/transforms.h>
24+
#include <tf2_eigen/tf2_eigen.h>
25+
#include <tf2_ros/buffer_interface.h>
26+
#include <tf2_ros/transform_listener.h>
27+
28+
#include <memory>
29+
#include <string>
30+
31+
class LidarApolloInstanceSegmentation : public LidarInstanceSegmentationInterface
32+
{
33+
public:
34+
explicit LidarApolloInstanceSegmentation(rclcpp::Node * node);
35+
~LidarApolloInstanceSegmentation() {}
36+
bool detectDynamicObjects(
37+
const sensor_msgs::msg::PointCloud2 & input,
38+
autoware_perception_msgs::msg::DetectedObjectsWithFeature & output) override;
39+
40+
private:
41+
bool transformCloud(
42+
const sensor_msgs::msg::PointCloud2 & input, sensor_msgs::msg::PointCloud2 & transformed_cloud,
43+
float z_offset);
44+
45+
rclcpp::Node * node_;
46+
std::unique_ptr<Tn::trtNet> net_ptr_;
47+
std::shared_ptr<Cluster2D> cluster2d_;
48+
std::shared_ptr<FeatureGenerator> feature_generator_;
49+
float score_threshold_;
50+
51+
tf2_ros::Buffer tf_buffer_;
52+
tf2_ros::TransformListener tf_listener_;
53+
std::string target_frame_;
54+
float z_offset_;
55+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/******************************************************************************
2+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*****************************************************************************/
16+
17+
#ifndef MODULES_PERCEPTION_OBSTACLE_COMMON_DISJOINT_SET_H_
18+
#define MODULES_PERCEPTION_OBSTACLE_COMMON_DISJOINT_SET_H_
19+
20+
template <class T>
21+
void DisjointSetMakeSet(T * x)
22+
{
23+
x->parent = x;
24+
x->node_rank = 0;
25+
}
26+
27+
template <class T>
28+
T * DisjointSetFindRecursive(T * x)
29+
{
30+
if (x->parent != x) {
31+
x->parent = DisjointSetFindRecursive(x->parent);
32+
}
33+
return x->parent;
34+
}
35+
36+
template <class T>
37+
T * DisjointSetFind(T * x)
38+
{
39+
T * y = x->parent;
40+
if (y == x || y->parent == y) {
41+
return y;
42+
}
43+
T * root = DisjointSetFindRecursive(y->parent);
44+
x->parent = root;
45+
y->parent = root;
46+
return root;
47+
}
48+
49+
template <class T>
50+
void DisjointSetMerge([[maybe_unused]] T * x, [[maybe_unused]] const T * y)
51+
{
52+
}
53+
54+
template <class T>
55+
void DisjointSetUnion(T * x, T * y)
56+
{
57+
x = DisjointSetFind(x);
58+
y = DisjointSetFind(y);
59+
if (x == y) {
60+
return;
61+
}
62+
if (x->node_rank < y->node_rank) {
63+
x->parent = y;
64+
DisjointSetMerge(y, x);
65+
} else if (y->node_rank < x->node_rank) {
66+
y->parent = x;
67+
DisjointSetMerge(x, y);
68+
} else {
69+
y->parent = x;
70+
x->node_rank++;
71+
DisjointSetMerge(x, y);
72+
}
73+
}
74+
75+
#endif // MODULES_PERCEPTION_OBSTACLE_COMMON_DISJOINT_SET_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "lidar_apollo_instance_segmentation/feature_map.hpp"
18+
#include "util.hpp"
19+
20+
#include <pcl/point_cloud.h>
21+
#include <pcl/point_types.h>
22+
23+
#include <memory>
24+
25+
class FeatureGenerator
26+
{
27+
private:
28+
float min_height_;
29+
float max_height_;
30+
bool use_intensity_feature_;
31+
bool use_constant_feature_;
32+
std::shared_ptr<FeatureMapInterface> map_ptr_;
33+
34+
public:
35+
FeatureGenerator(
36+
const int width, const int height, const int range, const bool use_intensity_feature,
37+
const bool use_constant_feature);
38+
~FeatureGenerator() {}
39+
40+
std::shared_ptr<FeatureMapInterface> generate(
41+
const pcl::PointCloud<pcl::PointXYZI>::Ptr & pc_ptr);
42+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#pragma once
15+
#include <memory>
16+
#include <vector>
17+
18+
struct FeatureMapInterface
19+
{
20+
public:
21+
int channels;
22+
int width;
23+
int height;
24+
int range;
25+
float * max_height_data; // channel 0
26+
float * mean_height_data; // channel 1
27+
float * count_data; // channel 2
28+
float * direction_data; // channel 3
29+
float * top_intensity_data; // channel 4
30+
float * mean_intensity_data; // channel 5
31+
float * distance_data; // channel 6
32+
float * nonempty_data; // channel 7
33+
std::vector<float> map_data;
34+
virtual void initializeMap(std::vector<float> & map) = 0;
35+
virtual void resetMap(std::vector<float> & map) = 0;
36+
FeatureMapInterface(const int _channels, const int _width, const int _height, const int _range);
37+
};
38+
39+
struct FeatureMap : public FeatureMapInterface
40+
{
41+
FeatureMap(const int width, const int height, const int range);
42+
void initializeMap(std::vector<float> & map) override;
43+
void resetMap(std::vector<float> & map) override;
44+
};
45+
46+
struct FeatureMapWithIntensity : public FeatureMapInterface
47+
{
48+
FeatureMapWithIntensity(const int width, const int height, const int range);
49+
void initializeMap(std::vector<float> & map) override;
50+
void resetMap(std::vector<float> & map) override;
51+
};
52+
53+
struct FeatureMapWithConstant : public FeatureMapInterface
54+
{
55+
FeatureMapWithConstant(const int width, const int height, const int range);
56+
void initializeMap(std::vector<float> & map) override;
57+
void resetMap(std::vector<float> & map) override;
58+
};
59+
60+
struct FeatureMapWithConstantAndIntensity : public FeatureMapInterface
61+
{
62+
FeatureMapWithConstantAndIntensity(const int width, const int height, const int range);
63+
void initializeMap(std::vector<float> & map) override;
64+
void resetMap(std::vector<float> & map) override;
65+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#pragma once
15+
16+
float calcApproximateLog(float num);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#pragma once
15+
#include "lidar_apollo_instance_segmentation/debugger.hpp"
16+
17+
#include <rclcpp/rclcpp.hpp>
18+
19+
#include <autoware_perception_msgs/msg/dynamic_object_with_feature_array.hpp>
20+
#include <sensor_msgs/msg/point_cloud2.hpp>
21+
22+
#include <memory>
23+
24+
class LidarInstanceSegmentationInterface
25+
{
26+
public:
27+
LidarInstanceSegmentationInterface() {}
28+
virtual ~LidarInstanceSegmentationInterface() {}
29+
virtual bool detectDynamicObjects(
30+
const sensor_msgs::msg::PointCloud2 & input,
31+
autoware_perception_msgs::msg::DetectedObjectsWithFeature & output) = 0;
32+
};
33+
34+
class LidarInstanceSegmentationNode : public rclcpp::Node
35+
{
36+
private:
37+
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloud_sub_;
38+
rclcpp::Publisher<autoware_perception_msgs::msg::DetectedObjectsWithFeature>::SharedPtr
39+
dynamic_objects_pub_;
40+
std::shared_ptr<LidarInstanceSegmentationInterface> detector_ptr_;
41+
std::shared_ptr<Debugger> debugger_ptr_;
42+
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
43+
44+
public:
45+
explicit LidarInstanceSegmentationNode(const rclcpp::NodeOptions & node_options);
46+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2018-2019 Autoware Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/******************************************************************************
16+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
17+
*
18+
* Licensed under the Apache License, Version 2.0 (the "License");
19+
* you may not use this file except in compliance with the License.
20+
* You may obtain a copy of the License at
21+
*
22+
* http://www.apache.org/licenses/LICENSE-2.0
23+
*
24+
* Unless required by applicable law or agreed to in writing, software
25+
* distributed under the License is distributed on an "AS IS" BASIS,
26+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27+
* See the License for the specific language governing permissions and
28+
* limitations under the License.
29+
*****************************************************************************/
30+
31+
#ifndef MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_
32+
#define MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_
33+
34+
#include <cmath>
35+
#include <string>
36+
37+
// project point cloud to 2d map. calc in which grid point is.
38+
// pointcloud to pixel
39+
inline int F2I(float val, float ori, float scale)
40+
{
41+
return static_cast<int>(std::floor((ori - val) * scale));
42+
}
43+
44+
inline int Pc2Pixel(float in_pc, float in_range, float out_size)
45+
{
46+
float inv_res = 0.5 * out_size / in_range;
47+
return static_cast<int>(std::floor((in_range - in_pc) * inv_res));
48+
}
49+
50+
// return the distance from my car to center of the grid.
51+
// Pc means point cloud = real world scale. so transform pixel scale to real
52+
// world scale
53+
inline float Pixel2Pc(int in_pixel, float in_size, float out_range)
54+
{
55+
float res = 2.0 * out_range / in_size;
56+
return out_range - (static_cast<float>(in_pixel) + 0.5f) * res;
57+
}
58+
59+
#endif // MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<launch>
2+
<arg name="model" default="model_128" />
3+
<arg name="output/objects" default="labeled_clusters" />
4+
5+
<arg if="$(eval &quot;'$(var model)'=='model_16'&quot;)" name="base_name" default="vlp-16" />
6+
<arg if="$(eval &quot;'$(var model)'=='model_64'&quot;)" name="base_name" default="hdl-64" />
7+
<arg if="$(eval &quot;'$(var model)'=='model_128'&quot;)" name="base_name" default="vls-128" />
8+
9+
<arg name="trained_engine_file" default="$(find-pkg-share lidar_apollo_instance_segmentation)/data/$(var base_name).engine" />
10+
<arg name="trained_prototxt_file" default="$(find-pkg-share lidar_apollo_instance_segmentation)/data/$(var base_name).prototxt" />
11+
<arg name="trained_caffemodel_file" default="$(find-pkg-share lidar_apollo_instance_segmentation)/data/$(var base_name).caffemodel" />
12+
<arg name="param_file" default="$(find-pkg-share lidar_apollo_instance_segmentation)/config/$(var base_name).param.yaml"/>
13+
14+
<arg name="target_frame" default="base_link" />
15+
<arg name="z_offset" default="-2" />
16+
17+
<node pkg="lidar_apollo_instance_segmentation" exec="lidar_apollo_instance_segmentation_node" name="lidar_apollo_instance_segmentation" output="screen">
18+
<remap from="input/pointcloud" to="/sensing/lidar/top/rectified/pointcloud"/>
19+
<remap from="output/labeled_clusters" to="$(var output/objects)"/>
20+
<param name="engine_file" value="$(var trained_engine_file)"/>
21+
<param name="prototxt_file" value="$(var trained_prototxt_file)"/>
22+
<param name="caffemodel_file" value="$(var trained_caffemodel_file)"/>
23+
<param name="z_offset" value="$(var z_offset)"/>
24+
<param name="target_frame" value="$(var target_frame)"/>
25+
<param from="$(var param_file)"/>
26+
</node>
27+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 lewes6369
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Note
2+
3+
This library is customized.
4+
Original repository : <https://github.com/lewes6369/tensorRTWrapper>
5+
6+
```txt
7+
MIT License
8+
9+
Copyright (c) 2018 lewes6369
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
28+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 lewes6369
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
#ifndef __TRT_NET_H_
25+
#define __TRT_NET_H_
26+
27+
#include "Utils.hpp"
28+
29+
#include <NvCaffeParser.h>
30+
#include <NvInferPlugin.h>
31+
32+
#include <algorithm>
33+
#include <fstream>
34+
#include <memory>
35+
#include <numeric>
36+
#include <string>
37+
#include <vector>
38+
39+
namespace Tn
40+
{
41+
enum class RUN_MODE { FLOAT32 = 0, FLOAT16 = 1, INT8 = 2 };
42+
43+
class trtNet
44+
{
45+
public:
46+
// Load from engine file
47+
explicit trtNet(const std::string & engineFile);
48+
49+
~trtNet()
50+
{
51+
// Release the stream and the buffers
52+
cudaStreamSynchronize(mTrtCudaStream);
53+
cudaStreamDestroy(mTrtCudaStream);
54+
for (auto & item : mTrtCudaBuffer) {
55+
cudaFree(item);
56+
}
57+
58+
if (!mTrtRunTime) {
59+
mTrtRunTime->destroy();
60+
}
61+
if (!mTrtContext) {
62+
mTrtContext->destroy();
63+
}
64+
if (!mTrtEngine) {
65+
mTrtEngine->destroy();
66+
}
67+
}
68+
69+
void saveEngine(std::string fileName)
70+
{
71+
if (mTrtEngine) {
72+
nvinfer1::IHostMemory * data = mTrtEngine->serialize();
73+
std::ofstream file;
74+
file.open(fileName, std::ios::binary | std::ios::out);
75+
if (!file.is_open()) {
76+
std::cout << "read create engine file" << fileName << " failed" << std::endl;
77+
return;
78+
}
79+
80+
file.write((const char *)data->data(), data->size());
81+
file.close();
82+
}
83+
}
84+
85+
void doInference(const void * inputData, void * outputData);
86+
87+
inline size_t getInputSize()
88+
{
89+
return std::accumulate(
90+
mTrtBindBufferSize.begin(), mTrtBindBufferSize.begin() + mTrtInputCount, 0);
91+
}
92+
93+
inline size_t getOutputSize()
94+
{
95+
return std::accumulate(
96+
mTrtBindBufferSize.begin() + mTrtInputCount, mTrtBindBufferSize.end(), 0);
97+
}
98+
99+
private:
100+
void InitEngine();
101+
102+
nvinfer1::IExecutionContext * mTrtContext;
103+
nvinfer1::ICudaEngine * mTrtEngine;
104+
nvinfer1::IRuntime * mTrtRunTime;
105+
cudaStream_t mTrtCudaStream;
106+
Profiler mTrtProfiler;
107+
RUN_MODE mTrtRunMode;
108+
109+
std::vector<void *> mTrtCudaBuffer;
110+
std::vector<int64_t> mTrtBindBufferSize;
111+
int mTrtInputCount;
112+
};
113+
} // namespace Tn
114+
115+
#endif // __TRT_NET_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 lewes6369
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#ifndef __TRT_UTILS_H_
26+
#define __TRT_UTILS_H_
27+
28+
#include <NvInferPlugin.h>
29+
#include <cudnn.h>
30+
31+
#include <algorithm>
32+
#include <iostream>
33+
#include <string>
34+
#include <utility>
35+
#include <vector>
36+
37+
#ifndef CUDA_CHECK
38+
39+
#define CUDA_CHECK(callstr) \
40+
{ \
41+
cudaError_t error_code = callstr; \
42+
if (error_code != cudaSuccess) { \
43+
std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__; \
44+
assert(0); \
45+
} \
46+
}
47+
48+
#endif
49+
50+
namespace Tn
51+
{
52+
class Profiler : public nvinfer1::IProfiler
53+
{
54+
public:
55+
void printLayerTimes(int iterationsTimes)
56+
{
57+
float totalTime = 0;
58+
for (size_t i = 0; i < mProfile.size(); i++) {
59+
printf("%-40.40s %4.3fms\n", mProfile[i].first.c_str(), mProfile[i].second / iterationsTimes);
60+
totalTime += mProfile[i].second;
61+
}
62+
printf("Time over all layers: %4.3f\n", totalTime / iterationsTimes);
63+
}
64+
65+
private:
66+
typedef std::pair<std::string, float> Record;
67+
std::vector<Record> mProfile;
68+
69+
void reportLayerTime(const char * layerName, float ms) noexcept override
70+
{
71+
auto record = std::find_if(
72+
mProfile.begin(), mProfile.end(), [&](const Record & r) { return r.first == layerName; });
73+
if (record == mProfile.end()) {
74+
mProfile.push_back(std::make_pair(layerName, ms));
75+
} else {
76+
record->second += ms;
77+
}
78+
}
79+
};
80+
81+
// Logger for TensorRT info/warning/errors
82+
class Logger : public nvinfer1::ILogger
83+
{
84+
public:
85+
Logger() : Logger(Severity::kWARNING) {}
86+
87+
explicit Logger(Severity severity) : reportableSeverity(severity) {}
88+
89+
void log(Severity severity, const char * msg) noexcept override
90+
{
91+
// suppress messages with severity enum value greater than the reportable
92+
if (severity > reportableSeverity) {
93+
return;
94+
}
95+
96+
switch (severity) {
97+
case Severity::kINTERNAL_ERROR:
98+
std::cerr << "INTERNAL_ERROR: ";
99+
break;
100+
case Severity::kERROR:
101+
std::cerr << "ERROR: ";
102+
break;
103+
case Severity::kWARNING:
104+
std::cerr << "WARNING: ";
105+
break;
106+
case Severity::kINFO:
107+
std::cerr << "INFO: ";
108+
break;
109+
default:
110+
std::cerr << "UNKNOWN: ";
111+
break;
112+
}
113+
std::cerr << msg << std::endl;
114+
}
115+
116+
Severity reportableSeverity{Severity::kWARNING};
117+
};
118+
119+
template <typename T>
120+
void write(char *& buffer, const T & val)
121+
{
122+
*reinterpret_cast<T *>(buffer) = val;
123+
buffer += sizeof(T);
124+
}
125+
126+
template <typename T>
127+
void read(const char *& buffer, T & val)
128+
{
129+
val = *reinterpret_cast<const T *>(buffer);
130+
buffer += sizeof(T);
131+
}
132+
} // namespace Tn
133+
134+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 lewes6369
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include <TrtNet.hpp>
26+
27+
#include <cublas_v2.h>
28+
#include <cudnn.h>
29+
#include <string.h>
30+
#include <time.h>
31+
32+
#include <cassert>
33+
#include <chrono>
34+
#include <iostream>
35+
#include <sstream>
36+
#include <unordered_map>
37+
38+
using namespace nvinfer1; // NOLINT
39+
using namespace nvcaffeparser1; // NOLINT
40+
using namespace plugin; // NOLINT
41+
42+
static Tn::Logger gLogger;
43+
44+
inline void * safeCudaMalloc(size_t memSize)
45+
{
46+
void * deviceMem;
47+
CUDA_CHECK(cudaMalloc(&deviceMem, memSize));
48+
if (deviceMem == nullptr) {
49+
std::cerr << "Out of memory" << std::endl;
50+
exit(1);
51+
}
52+
return deviceMem;
53+
}
54+
55+
inline int64_t volume(const nvinfer1::Dims & d)
56+
{
57+
return std::accumulate(d.d, d.d + d.nbDims, 1, std::multiplies<int64_t>());
58+
}
59+
60+
inline unsigned int getElementSize(nvinfer1::DataType t)
61+
{
62+
switch (t) {
63+
case nvinfer1::DataType::kINT32:
64+
return 4;
65+
case nvinfer1::DataType::kFLOAT:
66+
return 4;
67+
case nvinfer1::DataType::kHALF:
68+
return 2;
69+
case nvinfer1::DataType::kINT8:
70+
return 1;
71+
default:
72+
throw std::runtime_error("Invalid DataType.");
73+
return 0;
74+
}
75+
}
76+
77+
namespace Tn
78+
{
79+
trtNet::trtNet(const std::string & engineFile)
80+
: mTrtContext(nullptr),
81+
mTrtEngine(nullptr),
82+
mTrtRunTime(nullptr),
83+
mTrtRunMode(RUN_MODE::FLOAT32),
84+
mTrtInputCount(0)
85+
{
86+
using namespace std; // NOLINT
87+
fstream file;
88+
89+
file.open(engineFile, ios::binary | ios::in);
90+
if (!file.is_open()) {
91+
cout << "read engine file" << engineFile << " failed" << endl;
92+
return;
93+
}
94+
file.seekg(0, ios::end);
95+
int length = file.tellg();
96+
file.seekg(0, ios::beg);
97+
std::unique_ptr<char[]> data(new char[length]);
98+
file.read(data.get(), length);
99+
file.close();
100+
101+
mTrtRunTime = createInferRuntime(gLogger);
102+
assert(mTrtRunTime != nullptr);
103+
mTrtEngine = mTrtRunTime->deserializeCudaEngine(data.get(), length, nullptr);
104+
assert(mTrtEngine != nullptr);
105+
106+
InitEngine();
107+
}
108+
109+
void trtNet::InitEngine()
110+
{
111+
const int maxBatchSize = 1;
112+
mTrtContext = mTrtEngine->createExecutionContext();
113+
assert(mTrtContext != nullptr);
114+
mTrtContext->setProfiler(&mTrtProfiler);
115+
116+
int nbBindings = mTrtEngine->getNbBindings();
117+
118+
mTrtCudaBuffer.resize(nbBindings);
119+
mTrtBindBufferSize.resize(nbBindings);
120+
for (int i = 0; i < nbBindings; ++i) {
121+
Dims dims = mTrtEngine->getBindingDimensions(i);
122+
DataType dtype = mTrtEngine->getBindingDataType(i);
123+
int64_t totalSize = volume(dims) * maxBatchSize * getElementSize(dtype);
124+
mTrtBindBufferSize[i] = totalSize;
125+
mTrtCudaBuffer[i] = safeCudaMalloc(totalSize);
126+
if (mTrtEngine->bindingIsInput(i)) {
127+
mTrtInputCount++;
128+
}
129+
}
130+
131+
CUDA_CHECK(cudaStreamCreate(&mTrtCudaStream));
132+
}
133+
134+
void trtNet::doInference(const void * inputData, void * outputData)
135+
{
136+
static const int batchSize = 1;
137+
assert(mTrtInputCount == 1);
138+
139+
int inputIndex = 0;
140+
CUDA_CHECK(cudaMemcpyAsync(
141+
mTrtCudaBuffer[inputIndex], inputData, mTrtBindBufferSize[inputIndex], cudaMemcpyHostToDevice,
142+
mTrtCudaStream));
143+
144+
mTrtContext->execute(batchSize, &mTrtCudaBuffer[inputIndex]);
145+
146+
for (size_t bindingIdx = mTrtInputCount; bindingIdx < mTrtBindBufferSize.size(); ++bindingIdx) {
147+
auto size = mTrtBindBufferSize[bindingIdx];
148+
CUDA_CHECK(cudaMemcpyAsync(
149+
outputData, mTrtCudaBuffer[bindingIdx], size, cudaMemcpyDeviceToHost, mTrtCudaStream));
150+
}
151+
}
152+
} // namespace Tn
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<package format="3">
3+
<name>lidar_apollo_instance_segmentation</name>
4+
<version>0.1.0</version>
5+
<description>lidar_apollo_instance_segmentation</description>
6+
7+
<maintainer email="yukky.saito@gmail.com">Yukihiro Saito</maintainer>
8+
<author email="kosuke.tnp@gmail.com">Kosuke Takeuchi</author>
9+
<author email="yukky.saito@gmail.com">Yukihiro Saito</author>
10+
11+
<license>Apache License 2.0</license>
12+
13+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
14+
15+
<depend>autoware_auto_perception_msgs</depend>
16+
<depend>autoware_perception_msgs</depend>
17+
<depend>libpcl-all-dev</depend>
18+
<depend>pcl_conversions</depend>
19+
<depend>rclcpp</depend>
20+
<depend>tf2</depend>
21+
<depend>tf2_eigen</depend>
22+
<depend>tf2_geometry_msgs</depend>
23+
<depend>tf2_ros</depend>
24+
25+
<test_depend>ament_cmake_cppcheck</test_depend>
26+
<test_depend>ament_lint_auto</test_depend>
27+
28+
<export>
29+
<build_type>ament_cmake</build_type>
30+
</export>
31+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,372 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*
16+
* Copyright 2018-2019 Autoware Foundation. All rights reserved.
17+
*
18+
* Licensed under the Apache License, Version 2.0 (the "License");
19+
* you may not use this file except in compliance with the License.
20+
* You may obtain a copy of the License at
21+
*
22+
* http://www.apache.org/licenses/LICENSE-2.0
23+
*
24+
* Unless required by applicable law or agreed to in writing, software
25+
* distributed under the License is distributed on an "AS IS" BASIS,
26+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27+
* See the License for the specific language governing permissions and
28+
* limitations under the License.
29+
*/
30+
31+
/******************************************************************************
32+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
33+
*
34+
* Licensed under the Apache License, Version 2.0 (the "License");
35+
* you may not use this file except in compliance with the License.
36+
* You may obtain a copy of the License at
37+
*
38+
* http://www.apache.org/licenses/LICENSE-2.0
39+
*
40+
* Unless required by applicable law or agreed to in writing, software
41+
* distributed under the License is distributed on an "AS IS" BASIS,
42+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43+
* See the License for the specific language governing permissions and
44+
* limitations under the License.
45+
*****************************************************************************/
46+
47+
#include "lidar_apollo_instance_segmentation/cluster2d.hpp"
48+
49+
#include <autoware_auto_perception_msgs/msg/detected_object_kinematics.hpp>
50+
#include <autoware_auto_perception_msgs/msg/object_classification.hpp>
51+
52+
#include <pcl_conversions/pcl_conversions.h>
53+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
54+
55+
geometry_msgs::msg::Quaternion getQuaternionFromRPY(const double r, const double p, const double y)
56+
{
57+
tf2::Quaternion q;
58+
q.setRPY(r, p, y);
59+
return tf2::toMsg(q);
60+
}
61+
62+
Cluster2D::Cluster2D(const int rows, const int cols, const float range)
63+
{
64+
rows_ = rows;
65+
cols_ = cols;
66+
siz_ = rows * cols;
67+
range_ = range;
68+
scale_ = 0.5 * static_cast<float>(rows_) / range_;
69+
inv_res_x_ = 0.5 * static_cast<float>(cols_) / range_;
70+
inv_res_y_ = 0.5 * static_cast<float>(rows_) / range_;
71+
point2grid_.clear();
72+
id_img_.assign(siz_, -1);
73+
pc_ptr_.reset();
74+
valid_indices_in_pc_ = nullptr;
75+
}
76+
77+
void Cluster2D::traverse(Node * x)
78+
{
79+
std::vector<Node *> p;
80+
p.clear();
81+
82+
while (x->traversed == 0) {
83+
p.push_back(x);
84+
x->traversed = 2;
85+
x = x->center_node;
86+
}
87+
if (x->traversed == 2) {
88+
for (int i = static_cast<int>(p.size()) - 1; i >= 0 && p[i] != x; i--) {
89+
p[i]->is_center = true;
90+
}
91+
x->is_center = true;
92+
}
93+
for (size_t i = 0; i < p.size(); i++) {
94+
Node * y = p[i];
95+
y->traversed = 1;
96+
y->parent = x->parent;
97+
}
98+
}
99+
100+
void Cluster2D::cluster(
101+
const std::shared_ptr<float> & inferred_data, const pcl::PointCloud<pcl::PointXYZI>::Ptr & pc_ptr,
102+
const pcl::PointIndices & valid_indices, float objectness_thresh,
103+
bool use_all_grids_for_clustering)
104+
{
105+
const float * category_pt_data = inferred_data.get();
106+
const float * instance_pt_x_data = inferred_data.get() + siz_;
107+
const float * instance_pt_y_data = inferred_data.get() + siz_ * 2;
108+
109+
pc_ptr_ = pc_ptr;
110+
111+
std::vector<std::vector<Node>> nodes(rows_, std::vector<Node>(cols_, Node()));
112+
113+
valid_indices_in_pc_ = &(valid_indices.indices);
114+
point2grid_.assign(valid_indices_in_pc_->size(), -1);
115+
116+
for (size_t i = 0; i < valid_indices_in_pc_->size(); ++i) {
117+
int point_id = valid_indices_in_pc_->at(i);
118+
const auto & point = pc_ptr_->points[point_id];
119+
// * the coordinates of x and y have been exchanged in feature generation
120+
// step,
121+
// so we swap them back here.
122+
int pos_x = F2I(point.y, range_, inv_res_x_); // col
123+
int pos_y = F2I(point.x, range_, inv_res_y_); // row
124+
if (IsValidRowCol(pos_y, pos_x)) {
125+
point2grid_[i] = RowCol2Grid(pos_y, pos_x);
126+
nodes[pos_y][pos_x].point_num++;
127+
}
128+
}
129+
130+
for (int row = 0; row < rows_; ++row) {
131+
for (int col = 0; col < cols_; ++col) {
132+
int grid = RowCol2Grid(row, col);
133+
Node * node = &nodes[row][col];
134+
DisjointSetMakeSet(node);
135+
node->is_object = (use_all_grids_for_clustering || nodes[row][col].point_num > 0) &&
136+
(*(category_pt_data + grid) >= objectness_thresh);
137+
int center_row = std::round(row + instance_pt_x_data[grid] * scale_);
138+
int center_col = std::round(col + instance_pt_y_data[grid] * scale_);
139+
center_row = std::min(std::max(center_row, 0), rows_ - 1);
140+
center_col = std::min(std::max(center_col, 0), cols_ - 1);
141+
node->center_node = &nodes[center_row][center_col];
142+
}
143+
}
144+
145+
for (int row = 0; row < rows_; ++row) {
146+
for (int col = 0; col < cols_; ++col) {
147+
Node * node = &nodes[row][col];
148+
if (node->is_object && node->traversed == 0) {
149+
traverse(node);
150+
}
151+
}
152+
}
153+
154+
for (int row = 0; row < rows_; ++row) {
155+
for (int col = 0; col < cols_; ++col) {
156+
Node * node = &nodes[row][col];
157+
if (!node->is_center) {
158+
continue;
159+
}
160+
for (int row2 = row - 1; row2 <= row + 1; ++row2) {
161+
for (int col2 = col - 1; col2 <= col + 1; ++col2) {
162+
if ((row2 == row || col2 == col) && IsValidRowCol(row2, col2)) {
163+
Node * node2 = &nodes[row2][col2];
164+
if (node2->is_center) {
165+
DisjointSetUnion(node, node2);
166+
}
167+
}
168+
}
169+
}
170+
}
171+
}
172+
173+
int count_obstacles = 0;
174+
obstacles_.clear();
175+
id_img_.assign(siz_, -1);
176+
for (int row = 0; row < rows_; ++row) {
177+
for (int col = 0; col < cols_; ++col) {
178+
Node * node = &nodes[row][col];
179+
if (!node->is_object) {
180+
continue;
181+
}
182+
Node * root = DisjointSetFind(node);
183+
if (root->obstacle_id < 0) {
184+
root->obstacle_id = count_obstacles++;
185+
obstacles_.push_back(Obstacle());
186+
}
187+
int grid = RowCol2Grid(row, col);
188+
id_img_[grid] = root->obstacle_id;
189+
obstacles_[root->obstacle_id].grids.push_back(grid);
190+
}
191+
}
192+
filter(inferred_data);
193+
classify(inferred_data);
194+
}
195+
196+
void Cluster2D::filter(const std::shared_ptr<float> & inferred_data)
197+
{
198+
const float * confidence_pt_data = inferred_data.get() + siz_ * 3;
199+
const float * heading_pt_x_data = inferred_data.get() + siz_ * 9;
200+
const float * heading_pt_y_data = inferred_data.get() + siz_ * 10;
201+
const float * height_pt_data = inferred_data.get() + siz_ * 11;
202+
203+
for (size_t obstacle_id = 0; obstacle_id < obstacles_.size(); obstacle_id++) {
204+
Obstacle * obs = &obstacles_[obstacle_id];
205+
double score = 0.0;
206+
double height = 0.0;
207+
double vec_x = 0.0;
208+
double vec_y = 0.0;
209+
for (int grid : obs->grids) {
210+
score += static_cast<double>(confidence_pt_data[grid]);
211+
height += static_cast<double>(height_pt_data[grid]);
212+
vec_x += heading_pt_x_data[grid];
213+
vec_y += heading_pt_y_data[grid];
214+
}
215+
obs->score = score / static_cast<double>(obs->grids.size());
216+
obs->height = height / static_cast<double>(obs->grids.size());
217+
obs->heading = std::atan2(vec_y, vec_x) * 0.5;
218+
obs->cloud_ptr.reset(new pcl::PointCloud<pcl::PointXYZI>);
219+
}
220+
}
221+
222+
void Cluster2D::classify(const std::shared_ptr<float> & inferred_data)
223+
{
224+
const float * classify_pt_data = inferred_data.get() + siz_ * 4;
225+
int num_classes = 5;
226+
for (size_t obs_id = 0; obs_id < obstacles_.size(); obs_id++) {
227+
Obstacle * obs = &obstacles_[obs_id];
228+
229+
for (size_t grid_id = 0; grid_id < obs->grids.size(); grid_id++) {
230+
int grid = obs->grids[grid_id];
231+
for (int k = 0; k < num_classes; k++) {
232+
obs->meta_type_probs[k] += classify_pt_data[k * siz_ + grid];
233+
}
234+
}
235+
int meta_type_id = 0;
236+
for (int k = 0; k < num_classes; k++) {
237+
obs->meta_type_probs[k] /= obs->grids.size();
238+
if (obs->meta_type_probs[k] > obs->meta_type_probs[meta_type_id]) {
239+
meta_type_id = k;
240+
}
241+
}
242+
obs->meta_type = static_cast<MetaType>(meta_type_id);
243+
}
244+
}
245+
246+
autoware_perception_msgs::msg::DetectedObjectWithFeature Cluster2D::obstacleToObject(
247+
const Obstacle & in_obstacle, const std_msgs::msg::Header & in_header)
248+
{
249+
using autoware_auto_perception_msgs::msg::DetectedObjectKinematics;
250+
using autoware_auto_perception_msgs::msg::ObjectClassification;
251+
252+
autoware_perception_msgs::msg::DetectedObjectWithFeature resulting_object;
253+
// pcl::PointCloud<pcl::PointXYZI> in_cluster = *(in_obstacle.cloud_ptr);
254+
255+
resulting_object.object.classification.emplace_back(
256+
autoware_auto_perception_msgs::build<ObjectClassification>()
257+
.label(ObjectClassification::UNKNOWN)
258+
.probability(in_obstacle.score));
259+
if (in_obstacle.meta_type == MetaType::META_PEDESTRIAN) {
260+
resulting_object.object.classification.front().label = ObjectClassification::PEDESTRIAN;
261+
} else if (in_obstacle.meta_type == MetaType::META_NONMOT) {
262+
resulting_object.object.classification.front().label = ObjectClassification::MOTORCYCLE;
263+
} else if (in_obstacle.meta_type == MetaType::META_SMALLMOT) {
264+
resulting_object.object.classification.front().label = ObjectClassification::CAR;
265+
} else if (in_obstacle.meta_type == MetaType::META_BIGMOT) {
266+
resulting_object.object.classification.front().label = ObjectClassification::BUS;
267+
} else {
268+
// resulting_object.object.classification.front().label = ObjectClassification::PEDESTRIAN;
269+
resulting_object.object.classification.front().label = ObjectClassification::UNKNOWN;
270+
}
271+
272+
pcl::PointXYZ min_point;
273+
pcl::PointXYZ max_point;
274+
for (auto pit = in_obstacle.cloud_ptr->points.begin(); pit != in_obstacle.cloud_ptr->points.end();
275+
++pit) {
276+
if (pit->x < min_point.x) {
277+
min_point.x = pit->x;
278+
}
279+
if (pit->y < min_point.y) {
280+
min_point.y = pit->y;
281+
}
282+
if (pit->z < min_point.z) {
283+
min_point.z = pit->z;
284+
}
285+
if (pit->x > max_point.x) {
286+
max_point.x = pit->x;
287+
}
288+
if (pit->y > max_point.y) {
289+
max_point.y = pit->y;
290+
}
291+
if (pit->z > max_point.z) {
292+
max_point.z = pit->z;
293+
}
294+
}
295+
296+
// cluster and ground filtering
297+
pcl::PointCloud<pcl::PointXYZI> cluster;
298+
const float min_height = min_point.z + ((max_point.z - min_point.z) * 0.1f);
299+
for (auto pit = in_obstacle.cloud_ptr->points.begin(); pit != in_obstacle.cloud_ptr->points.end();
300+
++pit) {
301+
if (min_height < pit->z) {
302+
cluster.points.push_back(*pit);
303+
}
304+
}
305+
min_point.z = 0.0;
306+
max_point.z = 0.0;
307+
for (auto pit = cluster.points.begin(); pit != cluster.points.end(); ++pit) {
308+
if (pit->z < min_point.z) {
309+
min_point.z = pit->z;
310+
}
311+
if (pit->z > max_point.z) {
312+
max_point.z = pit->z;
313+
}
314+
}
315+
sensor_msgs::msg::PointCloud2 ros_pc;
316+
pcl::toROSMsg(cluster, ros_pc);
317+
resulting_object.feature.cluster = ros_pc;
318+
resulting_object.feature.cluster.header = in_header;
319+
320+
// position
321+
const float height = max_point.z - min_point.z;
322+
const float length = max_point.x - min_point.x;
323+
const float width = max_point.y - min_point.y;
324+
resulting_object.object.kinematics.pose_with_covariance.pose.position.x =
325+
min_point.x + length / 2;
326+
resulting_object.object.kinematics.pose_with_covariance.pose.position.y = min_point.y + width / 2;
327+
resulting_object.object.kinematics.pose_with_covariance.pose.position.z =
328+
min_point.z + height / 2;
329+
330+
resulting_object.object.kinematics.pose_with_covariance.pose.orientation =
331+
getQuaternionFromRPY(0.0, 0.0, in_obstacle.heading);
332+
resulting_object.object.kinematics.orientation_availability =
333+
DetectedObjectKinematics::SIGN_UNKNOWN;
334+
335+
return resulting_object;
336+
}
337+
338+
void Cluster2D::getObjects(
339+
const float confidence_thresh, const float height_thresh, const int min_pts_num,
340+
autoware_perception_msgs::msg::DetectedObjectsWithFeature & objects,
341+
const std_msgs::msg::Header & in_header)
342+
{
343+
for (size_t i = 0; i < point2grid_.size(); ++i) {
344+
int grid = point2grid_[i];
345+
if (grid < 0) {
346+
continue;
347+
}
348+
349+
int obstacle_id = id_img_[grid];
350+
351+
int point_id = valid_indices_in_pc_->at(i);
352+
353+
if (obstacle_id >= 0 && obstacles_[obstacle_id].score >= confidence_thresh) {
354+
if (
355+
height_thresh < 0 ||
356+
pc_ptr_->points[point_id].z <= obstacles_[obstacle_id].height + height_thresh) {
357+
obstacles_[obstacle_id].cloud_ptr->push_back(pc_ptr_->points[point_id]);
358+
}
359+
}
360+
}
361+
362+
for (size_t obstacle_id = 0; obstacle_id < obstacles_.size(); obstacle_id++) {
363+
Obstacle * obs = &obstacles_[obstacle_id];
364+
if (static_cast<int>(obs->cloud_ptr->size()) < min_pts_num) {
365+
continue;
366+
}
367+
autoware_perception_msgs::msg::DetectedObjectWithFeature out_obj =
368+
obstacleToObject(*obs, in_header);
369+
objects.feature_objects.push_back(out_obj);
370+
}
371+
objects.header = in_header;
372+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/debugger.hpp"
16+
17+
#include <autoware_auto_perception_msgs/msg/object_classification.hpp>
18+
#include <sensor_msgs/msg/point_cloud2.hpp>
19+
20+
#include <pcl/point_cloud.h>
21+
#include <pcl/point_types.h>
22+
#include <pcl_conversions/pcl_conversions.h>
23+
24+
Debugger::Debugger(rclcpp::Node * node)
25+
{
26+
instance_pointcloud_pub_ =
27+
node->create_publisher<sensor_msgs::msg::PointCloud2>("debug/instance_pointcloud", 1);
28+
}
29+
30+
void Debugger::publishColoredPointCloud(
31+
const autoware_perception_msgs::msg::DetectedObjectsWithFeature & input)
32+
{
33+
using autoware_auto_perception_msgs::msg::ObjectClassification;
34+
pcl::PointCloud<pcl::PointXYZRGB> colored_pointcloud;
35+
for (size_t i = 0; i < input.feature_objects.size(); i++) {
36+
pcl::PointCloud<pcl::PointXYZI> object_pointcloud;
37+
pcl::fromROSMsg(input.feature_objects.at(i).feature.cluster, object_pointcloud);
38+
39+
int red = 0, green = 0, blue = 0;
40+
switch (input.feature_objects.at(i).object.classification.front().label) {
41+
case ObjectClassification::CAR: {
42+
red = 255;
43+
green = 0;
44+
blue = 0;
45+
break;
46+
}
47+
case ObjectClassification::TRUCK: {
48+
red = 255;
49+
green = 127;
50+
blue = 0;
51+
break;
52+
}
53+
case ObjectClassification::BUS: {
54+
red = 255;
55+
green = 0;
56+
blue = 127;
57+
break;
58+
}
59+
case ObjectClassification::PEDESTRIAN: {
60+
red = 0;
61+
green = 255;
62+
blue = 0;
63+
break;
64+
}
65+
case ObjectClassification::BICYCLE: {
66+
red = 0;
67+
green = 0;
68+
blue = 255;
69+
break;
70+
}
71+
case ObjectClassification::MOTORCYCLE: {
72+
red = 0;
73+
green = 127;
74+
blue = 255;
75+
break;
76+
}
77+
case ObjectClassification::UNKNOWN: {
78+
red = 255;
79+
green = 255;
80+
blue = 255;
81+
break;
82+
}
83+
}
84+
85+
for (size_t i = 0; i < object_pointcloud.size(); i++) {
86+
pcl::PointXYZRGB colored_point;
87+
colored_point.x = object_pointcloud[i].x;
88+
colored_point.y = object_pointcloud[i].y;
89+
colored_point.z = object_pointcloud[i].z;
90+
colored_point.r = red;
91+
colored_point.g = green;
92+
colored_point.b = blue;
93+
colored_pointcloud.push_back(colored_point);
94+
}
95+
}
96+
sensor_msgs::msg::PointCloud2 output_msg;
97+
pcl::toROSMsg(colored_pointcloud, output_msg);
98+
output_msg.header = input.header;
99+
instance_pointcloud_pub_->publish(output_msg);
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/detector.hpp"
16+
17+
#include "lidar_apollo_instance_segmentation/feature_map.hpp"
18+
19+
#include <NvCaffeParser.h>
20+
#include <NvInfer.h>
21+
#include <pcl_conversions/pcl_conversions.h>
22+
23+
LidarApolloInstanceSegmentation::LidarApolloInstanceSegmentation(rclcpp::Node * node)
24+
: node_(node), tf_buffer_(node_->get_clock()), tf_listener_(tf_buffer_)
25+
{
26+
int range, width, height;
27+
bool use_intensity_feature, use_constant_feature;
28+
std::string engine_file;
29+
std::string prototxt_file;
30+
std::string caffemodel_file;
31+
score_threshold_ = node_->declare_parameter("score_threshold", 0.8);
32+
range = node_->declare_parameter("range", 60);
33+
width = node_->declare_parameter("width", 640);
34+
height = node_->declare_parameter("height", 640);
35+
engine_file = node_->declare_parameter("engine_file", "vls-128.engine");
36+
prototxt_file = node_->declare_parameter("prototxt_file", "vls-128.prototxt");
37+
caffemodel_file = node_->declare_parameter("caffemodel_file", "vls-128.caffemodel");
38+
use_intensity_feature = node_->declare_parameter("use_intensity_feature", true);
39+
use_constant_feature = node_->declare_parameter("use_constant_feature", true);
40+
target_frame_ = node_->declare_parameter("target_frame", "base_link");
41+
z_offset_ = node_->declare_parameter("z_offset", 2);
42+
43+
// load weight file
44+
std::ifstream fs(engine_file);
45+
if (!fs.is_open()) {
46+
RCLCPP_INFO(
47+
node_->get_logger(),
48+
"Could not find %s. try making TensorRT engine from caffemodel and prototxt",
49+
engine_file.c_str());
50+
Tn::Logger logger;
51+
nvinfer1::IBuilder * builder = nvinfer1::createInferBuilder(logger);
52+
nvinfer1::INetworkDefinition * network = builder->createNetworkV2(0U);
53+
nvcaffeparser1::ICaffeParser * parser = nvcaffeparser1::createCaffeParser();
54+
nvinfer1::IBuilderConfig * config = builder->createBuilderConfig();
55+
const nvcaffeparser1::IBlobNameToTensor * blob_name2tensor = parser->parse(
56+
prototxt_file.c_str(), caffemodel_file.c_str(), *network, nvinfer1::DataType::kFLOAT);
57+
std::string output_node = "deconv0";
58+
auto output = blob_name2tensor->find(output_node.c_str());
59+
if (output == nullptr) {
60+
RCLCPP_ERROR(node_->get_logger(), "can not find output named %s", output_node.c_str());
61+
}
62+
network->markOutput(*output);
63+
const int batch_size = 1;
64+
builder->setMaxBatchSize(batch_size);
65+
config->setMaxWorkspaceSize(1 << 30);
66+
nvinfer1::ICudaEngine * engine = builder->buildEngineWithConfig(*network, *config);
67+
nvinfer1::IHostMemory * trt_model_stream = engine->serialize();
68+
assert(trt_model_stream != nullptr);
69+
std::ofstream outfile(engine_file, std::ofstream::binary);
70+
assert(!outfile.fail());
71+
outfile.write(reinterpret_cast<char *>(trt_model_stream->data()), trt_model_stream->size());
72+
outfile.close();
73+
network->destroy();
74+
parser->destroy();
75+
builder->destroy();
76+
config->destroy();
77+
}
78+
net_ptr_.reset(new Tn::trtNet(engine_file));
79+
80+
// feature map generator: pre process
81+
feature_generator_ = std::make_shared<FeatureGenerator>(
82+
width, height, range, use_intensity_feature, use_constant_feature);
83+
84+
// cluster: post process
85+
cluster2d_ = std::make_shared<Cluster2D>(width, height, range);
86+
}
87+
88+
bool LidarApolloInstanceSegmentation::transformCloud(
89+
const sensor_msgs::msg::PointCloud2 & input, sensor_msgs::msg::PointCloud2 & transformed_cloud,
90+
float z_offset)
91+
{
92+
// TODO(mitsudome-r): remove conversion once pcl_ros transform are available.
93+
pcl::PointCloud<pcl::PointXYZI> pcl_input, pcl_transformed_cloud;
94+
pcl::fromROSMsg(input, pcl_input);
95+
96+
// transform pointcloud to target_frame
97+
if (target_frame_ != input.header.frame_id) {
98+
try {
99+
geometry_msgs::msg::TransformStamped transform_stamped;
100+
transform_stamped = tf_buffer_.lookupTransform(
101+
target_frame_, input.header.frame_id, input.header.stamp, std::chrono::milliseconds(500));
102+
Eigen::Matrix4f affine_matrix =
103+
tf2::transformToEigen(transform_stamped.transform).matrix().cast<float>();
104+
pcl::transformPointCloud(pcl_input, pcl_transformed_cloud, affine_matrix);
105+
transformed_cloud.header.frame_id = target_frame_;
106+
} catch (tf2::TransformException & ex) {
107+
RCLCPP_WARN(node_->get_logger(), "%s", ex.what());
108+
return false;
109+
}
110+
} else {
111+
pcl_transformed_cloud = pcl_input;
112+
}
113+
114+
// move pointcloud z_offset in z axis
115+
pcl::PointCloud<pcl::PointXYZI> pointcloud_with_z_offset;
116+
Eigen::Affine3f z_up_translation(Eigen::Translation3f(0, 0, z_offset));
117+
Eigen::Matrix4f z_up_transform = z_up_translation.matrix();
118+
pcl::transformPointCloud(pcl_transformed_cloud, pcl_transformed_cloud, z_up_transform);
119+
120+
pcl::toROSMsg(pcl_transformed_cloud, transformed_cloud);
121+
122+
return true;
123+
}
124+
125+
bool LidarApolloInstanceSegmentation::detectDynamicObjects(
126+
const sensor_msgs::msg::PointCloud2 & input,
127+
autoware_perception_msgs::msg::DetectedObjectsWithFeature & output)
128+
{
129+
// move up pointcloud z_offset in z axis
130+
sensor_msgs::msg::PointCloud2 transformed_cloud;
131+
transformCloud(input, transformed_cloud, z_offset_);
132+
133+
// convert from ros to pcl
134+
pcl::PointCloud<pcl::PointXYZI>::Ptr pcl_pointcloud_raw_ptr(new pcl::PointCloud<pcl::PointXYZI>);
135+
pcl::fromROSMsg(transformed_cloud, *pcl_pointcloud_raw_ptr);
136+
137+
// generate feature map
138+
std::shared_ptr<FeatureMapInterface> feature_map_ptr =
139+
feature_generator_->generate(pcl_pointcloud_raw_ptr);
140+
141+
// inference
142+
std::shared_ptr<float> inferred_data(new float[net_ptr_->getOutputSize() / sizeof(float)]);
143+
net_ptr_->doInference(feature_map_ptr->map_data.data(), inferred_data.get());
144+
145+
// post process
146+
const float objectness_thresh = 0.5;
147+
pcl::PointIndices valid_idx;
148+
valid_idx.indices.resize(pcl_pointcloud_raw_ptr->size());
149+
std::iota(valid_idx.indices.begin(), valid_idx.indices.end(), 0);
150+
cluster2d_->cluster(
151+
inferred_data, pcl_pointcloud_raw_ptr, valid_idx, objectness_thresh,
152+
true /*use all grids for clustering*/);
153+
const float height_thresh = 0.5;
154+
const int min_pts_num = 3;
155+
cluster2d_->getObjects(
156+
score_threshold_, height_thresh, min_pts_num, output, transformed_cloud.header);
157+
158+
// move down pointcloud z_offset in z axis
159+
for (std::size_t i = 0; i < output.feature_objects.size(); i++) {
160+
sensor_msgs::msg::PointCloud2 transformed_cloud;
161+
transformCloud(output.feature_objects.at(i).feature.cluster, transformed_cloud, -z_offset_);
162+
output.feature_objects.at(i).feature.cluster = transformed_cloud;
163+
}
164+
165+
output.header = transformed_cloud.header;
166+
return true;
167+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/feature_generator.hpp"
16+
17+
#include "lidar_apollo_instance_segmentation/log_table.hpp"
18+
19+
namespace
20+
{
21+
inline float normalizeIntensity(float intensity) { return intensity / 255.0f; }
22+
} // namespace
23+
24+
FeatureGenerator::FeatureGenerator(
25+
const int width, const int height, const int range, const bool use_intensity_feature,
26+
const bool use_constant_feature)
27+
: min_height_(-5.0),
28+
max_height_(5.0),
29+
use_intensity_feature_(use_intensity_feature),
30+
use_constant_feature_(use_constant_feature)
31+
{
32+
// select feature map type
33+
if (use_constant_feature && use_intensity_feature) {
34+
map_ptr_ = std::make_shared<FeatureMapWithConstantAndIntensity>(width, height, range);
35+
} else if (use_constant_feature) {
36+
map_ptr_ = std::make_shared<FeatureMapWithConstant>(width, height, range);
37+
} else if (use_intensity_feature) {
38+
map_ptr_ = std::make_shared<FeatureMapWithIntensity>(width, height, range);
39+
} else {
40+
map_ptr_ = std::make_shared<FeatureMap>(width, height, range);
41+
}
42+
map_ptr_->initializeMap(map_ptr_->map_data);
43+
}
44+
45+
std::shared_ptr<FeatureMapInterface> FeatureGenerator::generate(
46+
const pcl::PointCloud<pcl::PointXYZI>::Ptr & pc_ptr)
47+
{
48+
const double epsilon = 1e-6;
49+
map_ptr_->resetMap(map_ptr_->map_data);
50+
51+
int size = map_ptr_->height * map_ptr_->width;
52+
53+
const float inv_res_x = 0.5 * map_ptr_->width / map_ptr_->range;
54+
const float inv_res_y = 0.5 * map_ptr_->height / map_ptr_->range;
55+
56+
for (size_t i = 0; i < pc_ptr->points.size(); ++i) {
57+
if (pc_ptr->points[i].z <= min_height_ || max_height_ <= pc_ptr->points[i].z) {
58+
continue;
59+
}
60+
61+
const int pos_x = std::floor((map_ptr_->range - pc_ptr->points[i].y) * inv_res_x); // x on grid
62+
const int pos_y = std::floor((map_ptr_->range - pc_ptr->points[i].x) * inv_res_y); // y on grid
63+
if (pos_x < 0 || map_ptr_->width <= pos_x || pos_y < 0 || map_ptr_->height <= pos_y) {
64+
continue;
65+
}
66+
67+
const int idx = pos_y * map_ptr_->width + pos_x;
68+
69+
if (map_ptr_->max_height_data[idx] < pc_ptr->points[i].z) {
70+
map_ptr_->max_height_data[idx] = pc_ptr->points[i].z;
71+
if (map_ptr_->top_intensity_data != nullptr) {
72+
map_ptr_->top_intensity_data[idx] = normalizeIntensity(pc_ptr->points[i].intensity);
73+
}
74+
}
75+
map_ptr_->mean_height_data[idx] += static_cast<float>(pc_ptr->points[i].z);
76+
if (map_ptr_->mean_intensity_data != nullptr) {
77+
map_ptr_->mean_intensity_data[idx] += normalizeIntensity(pc_ptr->points[i].intensity);
78+
}
79+
map_ptr_->count_data[idx] += 1.0f;
80+
}
81+
82+
for (int i = 0; i < size; ++i) {
83+
if (map_ptr_->count_data[i] < epsilon) {
84+
map_ptr_->max_height_data[i] = 0.0f;
85+
} else {
86+
map_ptr_->mean_height_data[i] /= map_ptr_->count_data[i];
87+
if (map_ptr_->mean_intensity_data != nullptr) {
88+
map_ptr_->mean_intensity_data[i] /= map_ptr_->count_data[i];
89+
}
90+
map_ptr_->nonempty_data[i] = 1.0f;
91+
}
92+
map_ptr_->count_data[i] = calcApproximateLog(map_ptr_->count_data[i]);
93+
}
94+
return map_ptr_;
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/feature_map.hpp"
16+
17+
#include "lidar_apollo_instance_segmentation/util.hpp"
18+
19+
#include <cmath>
20+
21+
FeatureMapInterface::FeatureMapInterface(
22+
const int _channels, const int _width, const int _height, const int _range)
23+
: channels(_channels),
24+
width(_width),
25+
height(_height),
26+
range(_range),
27+
max_height_data(nullptr),
28+
mean_height_data(nullptr),
29+
count_data(nullptr),
30+
direction_data(nullptr),
31+
top_intensity_data(nullptr),
32+
mean_intensity_data(nullptr),
33+
distance_data(nullptr),
34+
nonempty_data(nullptr)
35+
{
36+
map_data.resize(width * height * channels);
37+
}
38+
39+
FeatureMap::FeatureMap(const int width, const int height, const int range)
40+
: FeatureMapInterface(4, width, height, range)
41+
{
42+
max_height_data = &(map_data[0]) + width * height * 0;
43+
mean_height_data = &(map_data[0]) + width * height * 1;
44+
count_data = &(map_data[0]) + width * height * 2;
45+
nonempty_data = &(map_data[0]) + width * height * 3;
46+
}
47+
void FeatureMap::initializeMap([[maybe_unused]] std::vector<float> & map) {}
48+
void FeatureMap::resetMap([[maybe_unused]] std::vector<float> & map)
49+
{
50+
const int size = width * height;
51+
for (int i = 0; i < size; ++i) {
52+
max_height_data[i] = -5.0f;
53+
mean_height_data[i] = 0.0f;
54+
count_data[i] = 0.0f;
55+
nonempty_data[i] = 0.0f;
56+
}
57+
}
58+
59+
FeatureMapWithIntensity::FeatureMapWithIntensity(const int width, const int height, const int range)
60+
: FeatureMapInterface(6, width, height, range)
61+
{
62+
max_height_data = &(map_data[0]) + width * height * 0;
63+
mean_height_data = &(map_data[0]) + width * height * 1;
64+
count_data = &(map_data[0]) + width * height * 2;
65+
top_intensity_data = &(map_data[0]) + width * height * 3;
66+
mean_intensity_data = &(map_data[0]) + width * height * 4;
67+
nonempty_data = &(map_data[0]) + width * height * 5;
68+
}
69+
void FeatureMapWithIntensity::initializeMap([[maybe_unused]] std::vector<float> & map) {}
70+
void FeatureMapWithIntensity::resetMap([[maybe_unused]] std::vector<float> & map)
71+
{
72+
const int size = width * height;
73+
for (int i = 0; i < size; ++i) {
74+
max_height_data[i] = -5.0f;
75+
mean_height_data[i] = 0.0f;
76+
count_data[i] = 0.0f;
77+
top_intensity_data[i] = 0.0f;
78+
mean_intensity_data[i] = 0.0f;
79+
nonempty_data[i] = 0.0f;
80+
}
81+
}
82+
83+
FeatureMapWithConstant::FeatureMapWithConstant(const int width, const int height, const int range)
84+
: FeatureMapInterface(6, width, height, range)
85+
{
86+
max_height_data = &(map_data[0]) + width * height * 0;
87+
mean_height_data = &(map_data[0]) + width * height * 1;
88+
count_data = &(map_data[0]) + width * height * 2;
89+
direction_data = &(map_data[0]) + width * height * 3;
90+
distance_data = &(map_data[0]) + width * height * 4;
91+
nonempty_data = &(map_data[0]) + width * height * 5;
92+
}
93+
void FeatureMapWithConstant::initializeMap([[maybe_unused]] std::vector<float> & map)
94+
{
95+
for (int row = 0; row < height; ++row) {
96+
for (int col = 0; col < width; ++col) {
97+
int idx = row * width + col;
98+
// * row <-> x, column <-> y
99+
// return the distance from my car to center of the grid.
100+
// Pc means point cloud = real world scale. so transform pixel scale to
101+
// real world scale
102+
float center_x = Pixel2Pc(row, height, range);
103+
float center_y = Pixel2Pc(col, width, range);
104+
// normalization. -0.5~0.5
105+
direction_data[idx] = static_cast<float>(std::atan2(center_y, center_x) / (2.0 * M_PI));
106+
distance_data[idx] = static_cast<float>(std::hypot(center_x, center_y) / 60.0 - 0.5);
107+
}
108+
}
109+
}
110+
111+
void FeatureMapWithConstant::resetMap([[maybe_unused]] std::vector<float> & map)
112+
{
113+
const int size = width * height;
114+
for (int i = 0; i < size; ++i) {
115+
max_height_data[i] = -5.0f;
116+
mean_height_data[i] = 0.0f;
117+
count_data[i] = 0.0f;
118+
nonempty_data[i] = 0.0f;
119+
}
120+
}
121+
122+
FeatureMapWithConstantAndIntensity::FeatureMapWithConstantAndIntensity(
123+
const int width, const int height, const int range)
124+
: FeatureMapInterface(8, width, height, range)
125+
{
126+
max_height_data = &(map_data[0]) + width * height * 0;
127+
mean_height_data = &(map_data[0]) + width * height * 1;
128+
count_data = &(map_data[0]) + width * height * 2;
129+
direction_data = &(map_data[0]) + width * height * 3;
130+
top_intensity_data = &(map_data[0]) + width * height * 4;
131+
mean_intensity_data = &(map_data[0]) + width * height * 5;
132+
distance_data = &(map_data[0]) + width * height * 6;
133+
nonempty_data = &(map_data[0]) + width * height * 7;
134+
}
135+
void FeatureMapWithConstantAndIntensity::initializeMap([[maybe_unused]] std::vector<float> & map)
136+
{
137+
for (int row = 0; row < height; ++row) {
138+
for (int col = 0; col < width; ++col) {
139+
int idx = row * width + col;
140+
// * row <-> x, column <-> y
141+
// return the distance from my car to center of the grid.
142+
// Pc means point cloud = real world scale. so transform pixel scale to
143+
// real world scale
144+
float center_x = Pixel2Pc(row, height, range);
145+
float center_y = Pixel2Pc(col, width, range);
146+
// normalization. -0.5~0.5
147+
direction_data[idx] = static_cast<float>(std::atan2(center_y, center_x) / (2.0 * M_PI));
148+
distance_data[idx] = static_cast<float>(std::hypot(center_x, center_y) / 60.0 - 0.5);
149+
}
150+
}
151+
}
152+
153+
void FeatureMapWithConstantAndIntensity::resetMap([[maybe_unused]] std::vector<float> & map)
154+
{
155+
const int size = width * height;
156+
for (int i = 0; i < size; ++i) {
157+
max_height_data[i] = -5.0f;
158+
mean_height_data[i] = 0.0f;
159+
count_data[i] = 0.0f;
160+
top_intensity_data[i] = 0.0f;
161+
mean_intensity_data[i] = 0.0f;
162+
nonempty_data[i] = 0.0f;
163+
}
164+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/log_table.hpp"
16+
17+
#include <cmath>
18+
#include <string>
19+
#include <vector>
20+
21+
namespace
22+
{
23+
struct LogTable
24+
{
25+
std::vector<float> data;
26+
LogTable()
27+
{
28+
data.resize(256 * 10);
29+
for (size_t i = 0; i < data.size(); ++i) {
30+
data[i] = std::log1p(static_cast<float>(i / 10.0));
31+
}
32+
}
33+
};
34+
} // namespace
35+
36+
static ::LogTable log_table;
37+
38+
float calcApproximateLog(float num)
39+
{
40+
int integer_num = static_cast<int>(num * 10.0);
41+
if (integer_num < static_cast<int>(log_table.data.size())) {
42+
return log_table.data[integer_num];
43+
}
44+
return std::log(static_cast<float>(1.0 + num));
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2020 TierIV
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "lidar_apollo_instance_segmentation/node.hpp"
16+
17+
#include "lidar_apollo_instance_segmentation/detector.hpp"
18+
19+
LidarInstanceSegmentationNode::LidarInstanceSegmentationNode(
20+
const rclcpp::NodeOptions & node_options)
21+
: Node("lidar_apollo_instance_segmentation_node", node_options)
22+
{
23+
using std::placeholders::_1;
24+
detector_ptr_ = std::make_shared<LidarApolloInstanceSegmentation>(this);
25+
debugger_ptr_ = std::make_shared<Debugger>(this);
26+
pointcloud_sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
27+
"input/pointcloud", rclcpp::SensorDataQoS().keep_last(1),
28+
std::bind(&LidarInstanceSegmentationNode::pointCloudCallback, this, _1));
29+
dynamic_objects_pub_ =
30+
this->create_publisher<autoware_perception_msgs::msg::DetectedObjectsWithFeature>(
31+
"output/labeled_clusters", rclcpp::QoS{1});
32+
}
33+
34+
void LidarInstanceSegmentationNode::pointCloudCallback(
35+
const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
36+
{
37+
autoware_perception_msgs::msg::DetectedObjectsWithFeature output_msg;
38+
detector_ptr_->detectDynamicObjects(*msg, output_msg);
39+
dynamic_objects_pub_->publish(output_msg);
40+
debugger_ptr_->publishColoredPointCloud(output_msg);
41+
}
42+
43+
#include <rclcpp_components/register_node_macro.hpp>
44+
RCLCPP_COMPONENTS_REGISTER_NODE(LidarInstanceSegmentationNode)

0 commit comments

Comments
 (0)
Please sign in to comment.