Skip to content

Commit

Permalink
Add nms_rotated ort op (open-mmlab#312)
Browse files Browse the repository at this point in the history
* fix pose demo and windows build (open-mmlab#307)

* init

* Update nms_rotated.cpp

* add postprocessing_masks gpu version (open-mmlab#276)

* add postprocessing_masks gpu version

* default device cpu

* pre-commit fix

Co-authored-by: hadoop-basecv <[email protected]>

* fixed a bug causes text-recognizer to fail when (non-NULL) empty bboxes list is passed (open-mmlab#310)

* [Fix] include missing <type_traits> for formatter.h (open-mmlab#313)

* fix formatter

* relax GCC version requirement

* fix

* fix lint

* fix lint

* [Fix] MMEditing cannot save results when testing (open-mmlab#336)

* fix show

* lint

* remove redundant codes

* resolve comment

* type hint

* docs(build): fix typo (open-mmlab#352)

* docs(build): add missing build option

* docs(build): add onnx install

* style(doc): trim whitespace

* docs(build): revert install onnx

* docs(build): add ncnn LD_LIBRARY_PATH

* docs(build): fix path error

* fix openvino export tmp model, add binary flag (open-mmlab#353)

* init circleci (open-mmlab#348)

* fix wrong input mat type (open-mmlab#362)

* fix wrong input mat type

* fix lint

* fix(docs): remove redundant doc tree (open-mmlab#360)

* fix missing ncnn_DIR & InferenceEngine_DIR (open-mmlab#364)

* update doc

Co-authored-by: Chen Xin <[email protected]>
Co-authored-by: Shengxi Li <[email protected]>
Co-authored-by: hadoop-basecv <[email protected]>
Co-authored-by: lzhangzz <[email protected]>
Co-authored-by: Yifan Zhou <[email protected]>
Co-authored-by: tpoisonooo <[email protected]>
Co-authored-by: lvhan028 <[email protected]>
  • Loading branch information
8 people authored Apr 18, 2022
1 parent c54d574 commit 9411fe0
Show file tree
Hide file tree
Showing 26 changed files with 674 additions and 56 deletions.
39 changes: 39 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
lint:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/python:3.7.4
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- run:
name: Install pre-commit hook
command: |
sudo apt-add-repository ppa:brightbox/ruby-ng -y
sudo apt-get update
sudo apt-get install -y ruby2.7
pip install pre-commit
pre-commit install
- run:
name: Linting
command: pre-commit run --all-files
- run:
name: Check docstring coverage
command: |
pip install interrogate
interrogate -v --ignore-init-method --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmdeploy
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
pr_stage_test:
jobs:
- lint
4 changes: 2 additions & 2 deletions csrc/apis/c/classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ int mmdeploy_classifier_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_

Value input{Value::kArray};
for (int i = 0; i < mat_count; ++i) {
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats->type), mats[i].data, Device{"cpu"}};
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats[i].type), mats[i].data, Device{"cpu"}};
input.front().push_back({{"ori_img", _mat}});
}

Expand Down
4 changes: 2 additions & 2 deletions csrc/apis/c/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ int mmdeploy_detector_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_co

Value input{Value::kArray};
for (int i = 0; i < mat_count; ++i) {
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats->type), mats[i].data, Device{"cpu"}};
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats[i].type), mats[i].data, Device{"cpu"}};
input.front().push_back({{"ori_img", _mat}});
}

Expand Down
4 changes: 2 additions & 2 deletions csrc/apis/c/pose_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ int mmdeploy_pose_detector_apply_bbox(mm_handle_t handle, const mm_mat_t* mats,
Value input{Value::kArray};
auto result_count = 0;
for (int i = 0; i < mat_count; ++i) {
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats->type), mats[i].data, Device{"cpu"}};
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats[i].type), mats[i].data, Device{"cpu"}};

Value img_with_boxes;
if (bboxes && bbox_count) {
Expand Down
4 changes: 2 additions & 2 deletions csrc/apis/c/segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ int mmdeploy_segmentor_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_c

Value input{Value::kArray};
for (int i = 0; i < mat_count; ++i) {
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats->type), mats[i].data, Device{"cpu"}};
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
DataType(mats[i].type), mats[i].data, Device{"cpu"}};
input.front().push_back({{"ori_img", _mat}});
}

Expand Down
59 changes: 38 additions & 21 deletions csrc/apis/c/text_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ int mmdeploy_text_recognizer_apply_bbox(mm_handle_t handle, const mm_mat_t *imag

try {
auto recognizer = static_cast<Handle *>(handle);
Value input{Value::kArray, Value::kArray};
Value::Array input_images;
Value::Array input_bboxes;
auto _bboxes = bboxes;
auto result_count = 0;
for (int i = 0; i < image_count; ++i) {
mmdeploy::Mat _mat{images[i].height, images[i].width, PixelFormat(images[i].format),
DataType(images->type), images[i].data, Device{"cpu"}};
input[0].push_back({{"ori_img", _mat}});

// mapping from image index to result index, -1 represents invalid image with no bboxes
// supplied.
std::vector<int> result_index(image_count, -1);

for (int i = 0; i < image_count; ++i) {
if (bboxes && bbox_count) {
if (bbox_count[i] == 0) {
// skip images with no bounding boxes (push nothing)
continue;
}
Value boxes(Value::kArray);
for (int j = 0; j < bbox_count[i]; ++j) {
Value box;
Expand All @@ -128,17 +134,26 @@ int mmdeploy_text_recognizer_apply_bbox(mm_handle_t handle, const mm_mat_t *imag
}
_bboxes += bbox_count[i];
result_count += bbox_count[i];
input[1].push_back({{"boxes", boxes}});
input_bboxes.push_back({{"boxes", boxes}});
} else {
input[1].push_back(Value::kNull);
// bboxes or bbox_count not supplied, use whole image
result_count += 1;
input_bboxes.push_back(Value::kNull);
}

result_index[i] = static_cast<int>(input_images.size());
mmdeploy::Mat _mat{images[i].height, images[i].width, PixelFormat(images[i].format),
DataType(images[i].type), images[i].data, Device{"cpu"}};
input_images.push_back({{"ori_img", _mat}});
}

auto output = recognizer->Run(std::move(input)).value().front();
std::vector<std::vector<mmocr::TextRecognizerOutput>> recognizer_outputs;

auto recognizer_outputs =
from_value<std::vector<std::vector<mmocr::TextRecognizerOutput>>>(output);
if (!input_images.empty()) {
Value input{std::move(input_images), std::move(input_bboxes)};
auto output = recognizer->Run(std::move(input)).value().front();
from_value(output, recognizer_outputs);
}

std::vector<int> counts;
if (bboxes && bbox_count) {
Expand All @@ -157,21 +172,23 @@ int mmdeploy_text_recognizer_apply_bbox(mm_handle_t handle, const mm_mat_t *imag
new mm_text_recognize_t[result_count]{}, deleter);

for (int i = 0; i < image_count; ++i) {
auto &recog_output = recognizer_outputs[i];
for (int j = 0; j < recog_output.size(); ++j) {
auto &res = _results[offsets[i] + j];
if (result_index[i] >= 0) {
auto &recog_output = recognizer_outputs[result_index[i]];
for (int j = 0; j < recog_output.size(); ++j) {
auto &res = _results[offsets[i] + j];

auto &box_result = recog_output[j];
auto &box_result = recog_output[j];

auto &score = box_result.score;
res.length = static_cast<int>(score.size());
auto &score = box_result.score;
res.length = static_cast<int>(score.size());

res.score = new float[score.size()];
std::copy_n(score.data(), score.size(), res.score);
res.score = new float[score.size()];
std::copy_n(score.data(), score.size(), res.score);

auto text = box_result.text;
res.text = new char[text.length() + 1];
std::copy_n(text.data(), text.length() + 1, res.text);
auto text = box_result.text;
res.text = new char[text.length() + 1];
std::copy_n(text.data(), text.length() + 1, res.text);
}
}
}
*results = _results.release();
Expand Down
Loading

0 comments on commit 9411fe0

Please sign in to comment.