[Backend] Add Huawei Ascend NPU deploy using PaddleLite CANN. (#757)

* Add Huawei Ascend NPU deploy through PaddleLite CANN

* Add NNAdapter interface for paddlelite

* Modify Huawei Ascend Cmake

* Update way for compiling Huawei Ascend NPU deployment

* remove UseLiteBackend in UseCANN

* Support compile python whlee

* Change names of nnadapter API

* Add nnadapter pybind and remove useless API

* Support Python deployment on Huawei Ascend NPU

* Add models suppor for ascend

* Add PPOCR rec reszie for ascend

* fix conflict for ascend

* Rename CANN to Ascend

* Rename CANN to Ascend

* Improve ascend

* fix ascend bug

* improve ascend docs

* improve ascend docs

* improve ascend docs

* Improve Ascend

* Improve Ascend

* Move ascend python demo

* Imporve ascend

* Improve ascend

* Improve ascend

* Improve ascend

* Improve ascend

* Imporve ascend

* Imporve ascend

* Improve ascend
This commit is contained in:
yunyaoXYY
2022-12-26 10:18:34 +08:00
committed by GitHub
parent 2d3d941372
commit d45382e3cc
42 changed files with 714 additions and 29 deletions

View File

@@ -22,27 +22,53 @@ namespace vision {
namespace ocr {
void OcrRecognizerResizeImage(FDMat* mat, float max_wh_ratio,
const std::vector<int>& rec_image_shape) {
int img_c, img_h, img_w;
img_c = rec_image_shape[0];
const std::vector<int>& rec_image_shape, bool static_shape) {
int img_h, img_w;
img_h = rec_image_shape[1];
img_w = rec_image_shape[2];
img_w = int(img_h * max_wh_ratio);
if (!static_shape) {
float ratio = float(mat->Width()) / float(mat->Height());
int resize_w;
if (ceilf(img_h * ratio) > img_w) {
resize_w = img_w;
}else{
resize_w = int(ceilf(img_h * ratio));
img_w = int(img_h * max_wh_ratio);
float ratio = float(mat->Width()) / float(mat->Height());
int resize_w;
if (ceilf(img_h * ratio) > img_w) {
resize_w = img_w;
} else {
resize_w = int(ceilf(img_h * ratio));
}
Resize::Run(mat, resize_w, img_h);
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), {127, 127, 127});
} else {
if (mat->Width() >= img_w) {
Resize::Run(mat, img_w, img_h); // Reszie W to 320
} else {
Resize::Run(mat, mat->Width(), img_h);
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), {127, 127, 127});
// Pad to 320
}
}
Resize::Run(mat, resize_w, img_h);
std::vector<float> value = {127, 127, 127};
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), value);
}
void OcrRecognizerResizeImageOnAscend(FDMat* mat,
const std::vector<int>& rec_image_shape) {
int img_h, img_w;
img_h = rec_image_shape[1];
img_w = rec_image_shape[2];
if (mat->Width() >= img_w) {
Resize::Run(mat, img_w, img_h); // Reszie W to 320
} else {
Resize::Run(mat, mat->Width(), img_h);
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), {0,0,0});
// Pad to 320
}
}
bool RecognizerPreprocessor::Run(std::vector<FDMat>* images, std::vector<FDTensor>* outputs) {
return Run(images, outputs, 0, images->size(), {});
}
@@ -75,7 +101,7 @@ bool RecognizerPreprocessor::Run(std::vector<FDMat>* images, std::vector<FDTenso
real_index = indices[i];
}
FDMat* mat = &(images->at(real_index));
OcrRecognizerResizeImage(mat, max_wh_ratio, rec_image_shape_);
OcrRecognizerResizeImage(mat, max_wh_ratio, rec_image_shape_, static_shape_);
NormalizeAndPermute::Run(mat, mean_, scale_, is_scale_);
}
// Only have 1 output Tensor.