mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-11-01 20:32:52 +08:00
Improve Ascend
This commit is contained in:
@@ -22,24 +22,35 @@ 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);
|
||||
std::vector<float> value = {0, 0, 0};
|
||||
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), value);
|
||||
|
||||
} 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()), {0,0,0});
|
||||
// Pad to 320
|
||||
}
|
||||
}
|
||||
Resize::Run(mat, resize_w, img_h);
|
||||
std::vector<float> value = {0, 0, 0};
|
||||
Pad::Run(mat, 0, 0, 0, int(img_w - mat->Width()), value);
|
||||
}
|
||||
|
||||
void OcrRecognizerResizeImageOnAscend(FDMat* mat,
|
||||
@@ -91,11 +102,7 @@ bool RecognizerPreprocessor::Run(std::vector<FDMat>* images, std::vector<FDTenso
|
||||
real_index = indices[i];
|
||||
}
|
||||
FDMat* mat = &(images->at(real_index));
|
||||
#if defined(WITH_ASCEND) || defined(WITH_ASCEND_PYTHON)
|
||||
OcrRecognizerResizeImageOnAscend(mat, rec_image_shape_);
|
||||
#else
|
||||
OcrRecognizerResizeImage(mat, max_wh_ratio, rec_image_shape_);
|
||||
#endif
|
||||
OcrRecognizerResizeImage(mat, max_wh_ratio, rec_image_shape_, static_shape_);
|
||||
NormalizeAndPermute::Run(mat, mean_, scale_, is_scale_);
|
||||
}
|
||||
// Only have 1 output Tensor.
|
||||
|
||||
Reference in New Issue
Block a user