-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/refactoring #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…rrecting preprocessing scalling issue on long images
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR represents a significant refactoring of a Segment Anything Model (SAM) ONNX inference codebase, transitioning from a standalone C++ application to a ROS package with comprehensive testing infrastructure.
Key changes include:
- Migration from standalone executable to ROS catkin package structure
- Complete reorganization of include directories from
inc/
toinclude/
- Addition of comprehensive unit and integration tests using Google Test
- Refactoring of core functionality with improved error handling and code organization
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
test/test_utils.cpp | New comprehensive unit tests for Utils class covering image preprocessing and coordinate scaling |
test/sam_test.cpp | New integration tests for SAM inference pipeline with model file validation |
src/utils.cpp | Refactored preprocessing and postprocessing with improved error handling and cleaner code structure |
src/segmentation.cpp | New segmentation wrapper providing unified interface for SAM encoder/decoder operations |
src/sam_inference.cpp | Major refactoring with consistent naming conventions and improved session management |
src/main.cpp | Simplified main function using new segmentation interface |
include/*.h | New header files replacing old inc/ structure with improved organization |
CMakeLists.txt | Complete restructure for ROS catkin package with testing support |
package.xml | New ROS package manifest |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/segmentation.cpp
Outdated
std::vector<SEG::DL_RESULT> resSam; | ||
params_encoder.rectConfidenceThreshold = 0.1; | ||
params_encoder.iouThreshold = 0.5; | ||
params_encoder.modelPath = "/home/amigo//Documents/repos/sam_onnx_ros/build/SAM_encoder.onnx"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded absolute path with double slash '//' makes the code non-portable and fragile. Consider using relative paths or environment variables.
Copilot uses AI. Check for mistakes.
|
||
params_decoder = params_encoder; | ||
params_decoder.modelType = SEG::SAM_SEGMENT_DECODER; | ||
params_decoder.modelPath = "/home/amigo/Documents/repos/sam_onnx_ros/build/SAM_mask_decoder.onnx"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded absolute path makes the code non-portable. Consider using relative paths or environment variables for better maintainability.
Copilot uses AI. Check for mistakes.
src/main.cpp
Outdated
SEG::DL_RESULT res; | ||
std::tie(samSegmentors, params_encoder, params_decoder, res, resSam) = Initializer(); | ||
std::filesystem::path current_path = std::filesystem::current_path(); | ||
std::filesystem::path imgs_path = "/home/amigo/Documents/repos/hero_sam/sam_inference/build/images"; // current_path / <- you could use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded absolute path makes the code non-portable. The commented suggestion to use current_path /
would be more maintainable.
std::filesystem::path imgs_path = "/home/amigo/Documents/repos/hero_sam/sam_inference/build/images"; // current_path / <- you could use | |
std::filesystem::path imgs_path = current_path / "build/images"; // Use current_path for portability |
Copilot uses AI. Check for mistakes.
# -------------- ONNXRuntime ------------------# | ||
set(ONNXRUNTIME_VERSION 1.21.0) | ||
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../onnxruntime-linux-x64-gpu-1.21.1") | ||
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../hero_sam.bak/onnxruntime-linux-x64-gpu-1.21.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded relative path to a '.bak' directory is fragile and non-portable. Consider using find_package or environment variables to locate ONNX Runtime.
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../hero_sam.bak/onnxruntime-linux-x64-gpu-1.21.1") | |
# Allow user to specify ONNXRUNTIME_ROOT via CMake variable or environment variable | |
if(NOT DEFINED ONNXRUNTIME_ROOT) | |
if(DEFINED ENV{ONNXRUNTIME_ROOT}) | |
set(ONNXRUNTIME_ROOT $ENV{ONNXRUNTIME_ROOT}) | |
else() | |
message(FATAL_ERROR "ONNXRUNTIME_ROOT is not set. Please set the ONNXRUNTIME_ROOT environment variable or pass -DONNXRUNTIME_ROOT=... to cmake.") | |
endif() | |
endif() |
Copilot uses AI. Check for mistakes.
configure_file(~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_mask_decoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_mask_decoder.onnx COPYONLY) | ||
configure_file(~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_encoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_encoder.onnx COPYONLY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded absolute paths with tilde expansion and '.bak' directories are not portable and will fail on other systems. Consider using relative paths or making model paths configurable.
Copilot uses AI. Check for mistakes.
test/sam_test.cpp
Outdated
GTEST_SKIP() << "Models not found in build dir"; | ||
} | ||
|
||
auto masks = SegmentAnything(samSegmentors, params_encoder, params_decoder, testImage_realistic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function call doesn't match the signature. SegmentAnything
expects 6 parameters but only 4 are provided. Missing resSam
and res
parameters.
Copilot uses AI. Check for mistakes.
void SegmentAnything(std::vector<std::unique_ptr<SAM>> &samSegmentors, | ||
const SEG::DL_INIT_PARAM ¶ms_encoder, | ||
const SEG::DL_INIT_PARAM ¶ms_decoder, const cv::Mat &img, std::vector<SEG::DL_RESULT> &resSam, | ||
SEG::DL_RESULT &res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function returns void but the test expects it to return a vector of masks. Consider returning the results or updating the test to match the actual function signature.
Copilot uses AI. Check for mistakes.
… and segment anything interfaces changed) and added one more test to check the image dimensions W,H
964d95f
to
7cdf39a
Compare
No description provided.