Skip to content

Commit 2b39c70

Browse files
zytx121irexycxizihadoop-basecvlzhangzz
authored
Add nms_rotated ort op (open-mmlab#312)
* 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]>
1 parent 4c42bf5 commit 2b39c70

File tree

26 files changed

+674
-56
lines changed

26 files changed

+674
-56
lines changed

.circleci/config.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use the latest 2.1 version of CircleCI pipeline process engine.
2+
# See: https://circleci.com/docs/2.0/configuration-reference
3+
version: 2.1
4+
5+
# Define a job to be invoked later in a workflow.
6+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
7+
jobs:
8+
lint:
9+
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
10+
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
11+
docker:
12+
- image: cimg/python:3.7.4
13+
# Add steps to the job
14+
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
15+
steps:
16+
- checkout
17+
- run:
18+
name: Install pre-commit hook
19+
command: |
20+
sudo apt-add-repository ppa:brightbox/ruby-ng -y
21+
sudo apt-get update
22+
sudo apt-get install -y ruby2.7
23+
pip install pre-commit
24+
pre-commit install
25+
- run:
26+
name: Linting
27+
command: pre-commit run --all-files
28+
- run:
29+
name: Check docstring coverage
30+
command: |
31+
pip install interrogate
32+
interrogate -v --ignore-init-method --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmdeploy
33+
34+
# Invoke jobs via workflows
35+
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
36+
workflows:
37+
pr_stage_test:
38+
jobs:
39+
- lint

csrc/apis/c/classifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ int mmdeploy_classifier_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_
8686

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

csrc/apis/c/detector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ int mmdeploy_detector_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_co
8585

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

csrc/apis/c/pose_detector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ int mmdeploy_pose_detector_apply_bbox(mm_handle_t handle, const mm_mat_t* mats,
104104
Value input{Value::kArray};
105105
auto result_count = 0;
106106
for (int i = 0; i < mat_count; ++i) {
107-
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
108-
DataType(mats->type), mats[i].data, Device{"cpu"}};
107+
mmdeploy::Mat _mat{mats[i].height, mats[i].width, PixelFormat(mats[i].format),
108+
DataType(mats[i].type), mats[i].data, Device{"cpu"}};
109109

110110
Value img_with_boxes;
111111
if (bboxes && bbox_count) {

csrc/apis/c/segmentor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ int mmdeploy_segmentor_apply(mm_handle_t handle, const mm_mat_t* mats, int mat_c
8484

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

csrc/apis/c/text_recognizer.cpp

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,21 @@ int mmdeploy_text_recognizer_apply_bbox(mm_handle_t handle, const mm_mat_t *imag
108108

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

116+
// mapping from image index to result index, -1 represents invalid image with no bboxes
117+
// supplied.
118+
std::vector<int> result_index(image_count, -1);
119+
120+
for (int i = 0; i < image_count; ++i) {
119121
if (bboxes && bbox_count) {
122+
if (bbox_count[i] == 0) {
123+
// skip images with no bounding boxes (push nothing)
124+
continue;
125+
}
120126
Value boxes(Value::kArray);
121127
for (int j = 0; j < bbox_count[i]; ++j) {
122128
Value box;
@@ -128,17 +134,26 @@ int mmdeploy_text_recognizer_apply_bbox(mm_handle_t handle, const mm_mat_t *imag
128134
}
129135
_bboxes += bbox_count[i];
130136
result_count += bbox_count[i];
131-
input[1].push_back({{"boxes", boxes}});
137+
input_bboxes.push_back({{"boxes", boxes}});
132138
} else {
133-
input[1].push_back(Value::kNull);
139+
// bboxes or bbox_count not supplied, use whole image
134140
result_count += 1;
141+
input_bboxes.push_back(Value::kNull);
135142
}
143+
144+
result_index[i] = static_cast<int>(input_images.size());
145+
mmdeploy::Mat _mat{images[i].height, images[i].width, PixelFormat(images[i].format),
146+
DataType(images[i].type), images[i].data, Device{"cpu"}};
147+
input_images.push_back({{"ori_img", _mat}});
136148
}
137149

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

140-
auto recognizer_outputs =
141-
from_value<std::vector<std::vector<mmocr::TextRecognizerOutput>>>(output);
152+
if (!input_images.empty()) {
153+
Value input{std::move(input_images), std::move(input_bboxes)};
154+
auto output = recognizer->Run(std::move(input)).value().front();
155+
from_value(output, recognizer_outputs);
156+
}
142157

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

159174
for (int i = 0; i < image_count; ++i) {
160-
auto &recog_output = recognizer_outputs[i];
161-
for (int j = 0; j < recog_output.size(); ++j) {
162-
auto &res = _results[offsets[i] + j];
175+
if (result_index[i] >= 0) {
176+
auto &recog_output = recognizer_outputs[result_index[i]];
177+
for (int j = 0; j < recog_output.size(); ++j) {
178+
auto &res = _results[offsets[i] + j];
163179

164-
auto &box_result = recog_output[j];
180+
auto &box_result = recog_output[j];
165181

166-
auto &score = box_result.score;
167-
res.length = static_cast<int>(score.size());
182+
auto &score = box_result.score;
183+
res.length = static_cast<int>(score.size());
168184

169-
res.score = new float[score.size()];
170-
std::copy_n(score.data(), score.size(), res.score);
185+
res.score = new float[score.size()];
186+
std::copy_n(score.data(), score.size(), res.score);
171187

172-
auto text = box_result.text;
173-
res.text = new char[text.length() + 1];
174-
std::copy_n(text.data(), text.length() + 1, res.text);
188+
auto text = box_result.text;
189+
res.text = new char[text.length() + 1];
190+
std::copy_n(text.data(), text.length() + 1, res.text);
191+
}
175192
}
176193
}
177194
*results = _results.release();

0 commit comments

Comments
 (0)