-
Notifications
You must be signed in to change notification settings - Fork 668
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
fix(tensorrt_yolox): add run length encoding for sematic segmentation mask #7905
Merged
badai-nguyen
merged 18 commits into
autowarefoundation:main
from
badai-nguyen:fix/add_run_length_compressed
Aug 8, 2024
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f42cb41
fix: add rle compress
badai-nguyen 10bfceb
fix: rle compress
badai-nguyen c22d052
fix: move rle into utils
badai-nguyen a853f8f
chore: pre-commit
badai-nguyen f7facd5
Update perception/autoware_tensorrt_yolox/src/utils.cpp
badai-nguyen 12307ea
fix: remove unused variable
badai-nguyen bd3f0b0
Update perception/autoware_tensorrt_yolox/src/utils.cpp
badai-nguyen e581b4d
style(pre-commit): autofix
pre-commit-ci[bot] ce85d8b
feat: add unit test for utils
badai-nguyen 1dc4020
style(pre-commit): autofix
pre-commit-ci[bot] 7f8d44a
Merge branch 'main' into fix/add_run_length_compressed
badai-nguyen 44c6175
fix: unit test
badai-nguyen 3220095
chore: change to explicit index
badai-nguyen 191e2e3
style(pre-commit): autofix
pre-commit-ci[bot] a69a75a
fix: cuda cmake
badai-nguyen 6c190e3
Merge branch 'main' into fix/add_run_length_compressed
badai-nguyen 1293d0d
fix: separate unit test into different PR
badai-nguyen 4ced050
Merge branch 'main' into fix/add_run_length_compressed
badai-nguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
perception/autoware_tensorrt_yolox/include/autoware/tensorrt_yolox/utils.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_ | ||
#define AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_ | ||
#include <opencv2/opencv.hpp> | ||
|
||
#include <utility> | ||
#include <vector> | ||
|
||
namespace autoware::tensorrt_yolox | ||
{ | ||
std::vector<std::pair<uint8_t, int>> runLengthEncoder(const cv::Mat & mask); | ||
cv::Mat runLengthDecoder(const std::vector<uint8_t> & rle_data, const int rows, const int cols); | ||
} // namespace autoware::tensorrt_yolox | ||
|
||
#endif // AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 Tier IV, Inc. | ||
badai-nguyen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "autoware/tensorrt_yolox/utils.hpp" | ||
|
||
namespace autoware::tensorrt_yolox | ||
{ | ||
|
||
std::vector<std::pair<uint8_t, int>> runLengthEncoder(const cv::Mat & image) | ||
{ | ||
std::vector<std::pair<uint8_t, int>> compressed_data; | ||
const int rows = image.rows; | ||
const int cols = image.cols; | ||
compressed_data.emplace_back(image.at<uint8_t>(0, 0), 0); | ||
for (int i = 0; i < rows; ++i) { | ||
for (int j = 0; j < cols; ++j) { | ||
uint8_t current_value = image.at<uint8_t>(i, j); | ||
if (compressed_data.back().first == current_value) { | ||
++compressed_data.back().second; | ||
} else { | ||
compressed_data.emplace_back(current_value, 1); | ||
} | ||
} | ||
} | ||
return compressed_data; | ||
} | ||
|
||
cv::Mat runLengthDecoder(const std::vector<uint8_t> & rle_data, const int rows, const int cols) | ||
{ | ||
cv::Mat mask(rows, cols, CV_8UC1, cv::Scalar(0)); | ||
int idx = 0; | ||
int step = sizeof(uint8_t) + sizeof(int); | ||
int nb_pixels = 0; | ||
manato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (size_t i = 0; i < rle_data.size(); i += step) { | ||
uint8_t value; | ||
int length; | ||
std::memcpy(&value, &rle_data[i], sizeof(uint8_t)); | ||
std::memcpy(&length, &rle_data[i + sizeof(uint8_t)], sizeof(int)); | ||
badai-nguyen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nb_pixels += length; | ||
for (int j = 0; j < length; ++j) { | ||
int row_idx = static_cast<int>(idx / cols); | ||
int col_idx = static_cast<int>(idx % cols); | ||
mask.at<uint8_t>(row_idx, col_idx) = value; | ||
idx++; | ||
if (idx > rows * cols) { | ||
break; | ||
} | ||
} | ||
} | ||
return mask; | ||
} | ||
|
||
} // namespace autoware::tensorrt_yolox |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same as #7905 (comment)
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.
@manato I fixed at 3220095