Skip to content

Conversation

IasonTheodorou
Copy link
Member

No description provided.

Copy link

@Copilot Copilot AI left a 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/ to include/
  • 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.

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";
Copy link
Preview

Copilot AI Sep 10, 2025

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";
Copy link
Preview

Copilot AI Sep 10, 2025

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
Copy link
Preview

Copilot AI Sep 10, 2025

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.

Suggested change
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")
Copy link
Preview

Copilot AI Sep 10, 2025

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.

Suggested change
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.

Comment on lines +87 to +88
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)
Copy link
Preview

Copilot AI Sep 10, 2025

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.

GTEST_SKIP() << "Models not found in build dir";
}

auto masks = SegmentAnything(samSegmentors, params_encoder, params_decoder, testImage_realistic);
Copy link
Preview

Copilot AI Sep 10, 2025

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.

Comment on lines +40 to +43
void SegmentAnything(std::vector<std::unique_ptr<SAM>> &samSegmentors,
const SEG::DL_INIT_PARAM &params_encoder,
const SEG::DL_INIT_PARAM &params_decoder, const cv::Mat &img, std::vector<SEG::DL_RESULT> &resSam,
SEG::DL_RESULT &res) {
Copy link
Preview

Copilot AI Sep 10, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant