Skip to content

Commit 1e8ee16

Browse files
IasonTheodorouMatthijsBurgh
authored andcommitted
Resolved some PR comments
1 parent 0ad04c3 commit 1e8ee16

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

.vscode/launch.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"type": "cppdbg",
77
"request": "launch",
88
"program": "/home/amigo/ros/noetic/system/devel/lib/sam_onnx_ros/test_sam_onnx_ros", // Path to the executable
9-
"args": [], // Add any command-line arguments for your program here
9+
"args": ["/home/amigo/Documents/repos/hero_sam.bak/sam_inference/model/SAM_encoder.onnx",
10+
"/home/amigo/Documents/repos/hero_sam.bak/sam_inference/model/SAM_mask_decoder.onnx",
11+
"/home/amigo/Documents/repos/hero_sam.bak/pipeline/build/images"], // Add any command-line arguments for your program here
1012
"stopAtEntry": false,
1113
"cwd": "${workspaceFolder}/build", // Set the working directory
1214
"environment": [],
@@ -19,7 +21,7 @@
1921
"ignoreFailures": true
2022
}
2123
],
22-
"preLaunchTask": "build-sam-project" // Ensure the project is built before debugging
24+
// "preLaunchTask": "build-sam-project" // Ensure the project is built before debugging
2325
},
2426
{
2527
"name": "Debug GTest (pick binary)",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A high-performance C++ implementation for SAM (segment anything model) using ONN
2525
| Speed | 34ms | 11.176ms | 5.984|
2626
| **Whole Pipeline (Enc+Dec)** | | | |
2727
| Parameters | 9.66M | -| -|
28-
| Su of Speed | 92.92ms | - |- |
28+
| Sum of Speed | 92.92ms | - |- |
2929

3030

3131
## 📂 Project Structure

include/sam_onnx_ros/segmentation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Initialize(const std::filesystem::path& encoder_filename, const std::filesystem:
1616

1717
void SegmentAnything(
1818
std::vector<std::unique_ptr<SAM>>& samSegmentors,
19-
const SEG::_DL_INIT_PARAM& params_encoder,
20-
const SEG::_DL_INIT_PARAM& params_decoder,
19+
const SEG::DL_INIT_PARAM& params_encoder,
20+
const SEG::DL_INIT_PARAM& params_decoder,
2121
const cv::Mat& img,
2222
std::vector<SEG::DL_RESULT>& resSam,
2323
SEG::DL_RESULT& res

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
3434

3535
SegmentAnything(samSegmentors, params_encoder, params_decoder, img, resSam, res);
3636
#ifdef LOGGING
37-
for (const auto& result : results)
37+
for (const auto& result : resSam)
3838
{
3939
std::cout << "Image path: " << img_path << "\n"
4040
<< "# boxes: " << result.boxes.size() << "\n"

src/sam_inference.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const char* SAM::CreateSession(SEG::DL_INIT_PARAM& iParams)
6161
bool result = std::regex_search(iParams.modelPath, pattern);
6262
if (result)
6363
{
64-
Ret = "[SAM]:Your model path is error. Change your model path without chinese characters.";
64+
Ret = "[SAM]: Your model path is error. Change your model path without chinese characters.";
6565
CONSOLE_BRIDGE_logWarn("%s", Ret);
6666
return Ret;
6767
}
@@ -146,8 +146,8 @@ const char* SAM::RunSession(const cv::Mat& iImg, std::vector<SEG::DL_RESULT>& oR
146146
std::vector<int64_t> inputNodeDims;
147147
if (modelType == SEG::SAM_SEGMENT_ENCODER)
148148
{
149-
// NCHW with H=imgSize[1], W=imgSize[0] // FIX
150-
inputNodeDims = { 1, 3, imgSize_.at(1), imgSize_.at(0) }; // FIX
149+
// NCHW with H=imgSize[1], W=imgSize[0]
150+
inputNodeDims = { 1, 3, imgSize_.at(1), imgSize_.at(0) };
151151
}
152152
else if (modelType == SEG::SAM_SEGMENT_DECODER)
153153
{
@@ -334,7 +334,7 @@ const char* SAM::TensorProcess_(clock_t& starttime_1, const cv::Mat& iImg,
334334
break;
335335
}
336336
default:
337-
CONSOLE_BRIDGE_logError("[SAM]: " "Not support model type.");
337+
CONSOLE_BRIDGE_logError("[SAM]: Unsupported model type.");
338338
}
339339

340340
return RET_OK;
@@ -351,8 +351,8 @@ char* SAM::WarmUpSession_(SEG::MODEL_TYPE modelType)
351351
{
352352
float* blob = new float[iImg.total() * 3];
353353
utilities.BlobFromImage(processedImg, blob);
354-
// NCHW: H=imgSize[1], W=imgSize[0] // FIX
355-
std::vector<int64_t> SAM_input_node_dims = { 1, 3, imgSize_.at(1), imgSize_.at(0) }; // FIX
354+
// NCHW: H=imgSize[1], W=imgSize[0]
355+
std::vector<int64_t> SAM_input_node_dims = { 1, 3, imgSize_.at(1), imgSize_.at(0) };
356356
switch (modelType)
357357
{
358358
case SEG::SAM_SEGMENT_ENCODER:

src/utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ char* Utils::PreProcess(const cv::Mat& iImg, std::vector<int> iImgSize, cv::Mat&
2828
{
2929
// Width-dominant: scale by target width (iImgSize[0])
3030
resizeScales_ = iImg.cols / static_cast<float>(iImgSize.at(0));
31-
cv::resize(oImg, oImg, cv::Size(iImgSize.at(0), static_cast<int>(iImg.rows / resizeScales_))); // fixed
31+
// Resize to target width, scaling height to maintain aspect ratio
32+
cv::resize(oImg, oImg, cv::Size(iImgSize.at(0), static_cast<int>(iImg.rows / resizeScales_)));
3233
}
3334
else
3435
{
3536
// Height-dominant: scale by target height (iImgSize[1])
3637
resizeScales_ = iImg.rows / static_cast<float>(iImgSize.at(1));
37-
cv::resize(oImg, oImg, cv::Size(static_cast<int>(iImg.cols / resizeScales_), iImgSize.at(1))); // fixed
38+
// Resize width proportionally to target height to maintain aspect ratio (height-dominant case)
39+
cv::resize(oImg, oImg, cv::Size(static_cast<int>(iImg.cols / resizeScales_), iImgSize.at(1)));
3840
}
3941

4042
// Letterbox top-left into a canvas of size (H=iImgSize[1], W=iImgSize[0])

0 commit comments

Comments
 (0)