Skip to content

Commit b4d5bcb

Browse files
Deleted redundant code and fixed some brackets
1 parent 386f546 commit b4d5bcb

File tree

4 files changed

+9
-35
lines changed

4 files changed

+9
-35
lines changed

include/dl_types.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ namespace SEG
1010
{
1111
enum MODEL_TYPE
1212
{
13-
// FLOAT32 MODEL
1413
SAM_SEGMENT_ENCODER = 1,
1514
SAM_SEGMENT_DECODER = 2,
16-
// YOLO_CLS = 3,
17-
18-
// FLOAT16 MODEL
19-
// YOLO_DETECT_V8_HALF = 4,
20-
// YOLO_POSE_V8_HALF = 5,
21-
// YOLO_CLS_HALF = 6
2215
};
2316

2417
typedef struct _DL_INIT_PARAM
@@ -27,13 +20,9 @@ namespace SEG
2720
std::string modelPath;
2821
MODEL_TYPE modelType = SAM_SEGMENT_ENCODER;
2922
std::vector<int> imgSize = {640, 640};
30-
float rectConfidenceThreshold = 0.6;
31-
float iouThreshold = 0.5;
32-
int keyPointsNum = 2; // Note:kpt number for pose
3323
bool cudaEnable = false;
3424
int logSeverityLevel = 3;
3525
int intraOpNumThreads = 1;
36-
// std::vector<cv::Rect> boxes; // For SAM encoder model, this will be filled with detected boxes
3726

3827
// Overloaded output operator for _DL_INIT_PARAM to print its contents
3928
friend std::ostream &operator<<(std::ostream &os, const _DL_INIT_PARAM &param)
@@ -44,9 +33,6 @@ namespace SEG
4433
for (const auto &size : param.imgSize)
4534
os << size << " ";
4635
os << "\n";
47-
os << "rectConfidenceThreshold: " << param.rectConfidenceThreshold << "\n";
48-
os << "iouThreshold: " << param.iouThreshold << "\n";
49-
os << "keyPointsNum: " << param.keyPointsNum << "\n";
5036
os << "cudaEnable: " << (param.cudaEnable ? "true" : "false") << "\n";
5137
os << "logSeverityLevel: " << param.logSeverityLevel << "\n";
5238
os << "intraOpNumThreads: " << param.intraOpNumThreads;
@@ -57,14 +43,10 @@ namespace SEG
5743

5844
typedef struct _DL_RESULT
5945
{
60-
61-
std::vector<cv::Rect> boxes; // For SAM encoder model, this will be filled with detected boxes
62-
std::vector<cv::Point2f> keyPoints;
63-
64-
// Sam Part
46+
// For SAM encoder model, this will be filled with detected boxes from object detection model.
47+
std::vector<cv::Rect> boxes;
6548
std::vector<float> embeddings;
66-
// Masks for SAM decoder model output
67-
std::vector<cv::Mat> masks; // Each cv::Mat represents a mask
49+
std::vector<cv::Mat> masks;
6850

6951
} DL_RESULT;
7052
} // namespace SEG

include/sam_inference.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class SAM
4343
SEG::MODEL_TYPE _modelType;
4444
std::vector<int> _imgSize;
4545
float _rectConfidenceThreshold;
46-
float _iouThreshold;
4746
};
4847

4948
#endif // SAMINFERENCE_H

src/sam_inference.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const char *SAM::CreateSession(SEG::DL_INIT_PARAM &iParams) {
5151
return Ret;
5252
}
5353
try {
54-
_rectConfidenceThreshold = iParams.rectConfidenceThreshold;
55-
_iouThreshold = iParams.iouThreshold;
5654
_imgSize = iParams.imgSize;
5755
_modelType = iParams.modelType;
5856
_cudaEnable = iParams.cudaEnable;
@@ -116,7 +114,8 @@ const char *SAM::CreateSession(SEG::DL_INIT_PARAM &iParams) {
116114

117115
const char *SAM::RunSession(const cv::Mat &iImg,
118116
std::vector<SEG::DL_RESULT> &oResult,
119-
SEG::MODEL_TYPE _modelType, SEG::DL_RESULT &result) {
117+
SEG::MODEL_TYPE _modelType, SEG::DL_RESULT &result)
118+
{
120119
#ifdef benchmark
121120
clock_t starttime_1 = clock();
122121
#endif // benchmark
@@ -133,19 +132,19 @@ const char *SAM::RunSession(const cv::Mat &iImg,
133132
} else if (_modelType == SEG::SAM_SEGMENT_DECODER) {
134133
inputNodeDims = {1, 256, 64, 64};
135134
}
136-
TensorProcess(starttime_1, iImg, blob, inputNodeDims, _modelType, oResult,
135+
TensorProcess_(starttime_1, iImg, blob, inputNodeDims, _modelType, oResult,
137136
utilities, result);
138137

139138
return Ret;
140139
}
141140

142141
template <typename N>
143-
const char *SAM::TensorProcess(clock_t &starttime_1, const cv::Mat &iImg,
142+
const char *SAM::TensorProcess_(clock_t &starttime_1, const cv::Mat &iImg,
144143
N &blob, std::vector<int64_t> &inputNodeDims,
145144
SEG::MODEL_TYPE _modelType,
146145
std::vector<SEG::DL_RESULT> &oResult,
147-
Utils &utilities, SEG::DL_RESULT &result) {
148-
146+
Utils &utilities, SEG::DL_RESULT &result)
147+
{
149148
switch (_modelType) {
150149
case SEG::SAM_SEGMENT_ENCODER:
151150
// case OTHER_SAM_MODEL:
@@ -235,7 +234,6 @@ const char *SAM::TensorProcess(clock_t &starttime_1, const cv::Mat &iImg,
235234
#ifdef ROI
236235
for (const auto &box : boundingBoxes)
237236
#else
238-
239237
for (const auto &box : result.boxes)
240238
#endif // ROI
241239
{
@@ -410,7 +408,6 @@ char *SAM::WarmUpSession(SEG::MODEL_TYPE _modelType) {
410408
inputTensors.size(), _outputNodeNames.data(), _outputNodeNames.size());
411409
}
412410

413-
_outputNodeNames.size();
414411
delete[] blob;
415412
clock_t starttime_4 = clock();
416413
double post_process_time =

src/segmentation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Initializer() {
1313
SEG::DL_INIT_PARAM params_decoder;
1414
SEG::DL_RESULT res;
1515
std::vector<SEG::DL_RESULT> resSam;
16-
params_encoder.rectConfidenceThreshold = 0.1;
17-
params_encoder.iouThreshold = 0.5;
1816
params_encoder.modelPath = "/home/amigo/Documents/repos/sam_onnx_ros/build/SAM_encoder.onnx";
1917
params_encoder.imgSize = {1024, 1024};
2018

@@ -42,8 +40,6 @@ void SegmentAnything(std::vector<std::unique_ptr<SAM>> &samSegmentors,
4240
const SEG::DL_INIT_PARAM &params_decoder, const cv::Mat &img, std::vector<SEG::DL_RESULT> &resSam,
4341
SEG::DL_RESULT &res) {
4442

45-
46-
4743
SEG::MODEL_TYPE modelTypeRef = params_encoder.modelType;
4844
samSegmentors[0]->RunSession(img, resSam, modelTypeRef, res);
4945

0 commit comments

Comments
 (0)