From f3ccaed0628ba00beb0da30c20dc488ca0f8fa23 Mon Sep 17 00:00:00 2001 From: yuzhenhua Date: Tue, 13 Apr 2021 19:37:27 +0800 Subject: [PATCH] fix deeptext 310 inferenct bug and fasterrcnn bug --- model_zoo/official/cv/deeptext/postprocess.py | 2 +- .../ascend310_infer/src/AclProcess.cpp | 25 ++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/model_zoo/official/cv/deeptext/postprocess.py b/model_zoo/official/cv/deeptext/postprocess.py index 273131791a..55a0c41bd6 100644 --- a/model_zoo/official/cv/deeptext/postprocess.py +++ b/model_zoo/official/cv/deeptext/postprocess.py @@ -36,7 +36,7 @@ def get_pred(file, result_path): all_bbox_file = os.path.join(result_path, file_name + "_0.bin") all_label_file = os.path.join(result_path, file_name + "_1.bin") all_mask_file = os.path.join(result_path, file_name + "_2.bin") - all_bbox = np.fromfile(all_bbox_file, dtype=np.float16).reshape(config.test_batch_size, 1000, 5) + all_bbox = np.fromfile(all_bbox_file, dtype=np.float32).reshape(config.test_batch_size, 1000, 5) all_label = np.fromfile(all_label_file, dtype=np.int32).reshape(config.test_batch_size, 1000, 1) all_mask = np.fromfile(all_mask_file, dtype=np.bool).reshape(config.test_batch_size, 1000, 1) diff --git a/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp b/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp index afd044495d..1a37774642 100755 --- a/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp +++ b/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp @@ -23,7 +23,7 @@ * @attention context is passed in as a parameter after being created in ResourceManager::InitResource */ AclProcess::AclProcess(int deviceId, const std::string &om_path, uint32_t width, uint32_t height) - : deviceId_(deviceId), stream_(nullptr), modelProcess_(nullptr), dvppCommon_(nullptr), keepRatio_(false) { + : deviceId_(deviceId), stream_(nullptr), modelProcess_(nullptr), dvppCommon_(nullptr), keepRatio_(true) { modelInfo_.modelPath = om_path; modelInfo_.modelWidth = width; modelInfo_.modelHeight = height; @@ -284,29 +284,22 @@ int AclProcess::ModelInfer(std::map *costTime_map) { heightScale = static_cast(resizeOutData->height) / inputImg->height; } - aclFloat16 inputWidth = aclFloatToFloat16(static_cast(inputImg->width)); - aclFloat16 inputHeight = aclFloatToFloat16(static_cast(inputImg->height)); - aclFloat16 resizeWidthRatioFp16 = aclFloatToFloat16(widthScale); - aclFloat16 resizeHeightRatioFp16 = aclFloatToFloat16(heightScale); - - aclFloat16 *im_info = reinterpret_cast(malloc(sizeof(aclFloat16) * 4)); - im_info[0] = inputHeight; - im_info[1] = inputWidth; - im_info[2] = resizeHeightRatioFp16; - im_info[3] = resizeWidthRatioFp16; + float im_info[4]; + im_info[0] = static_cast(inputImg->height); + im_info[1] = static_cast(inputImg->width); + im_info[2] = heightScale; + im_info[3] = widthScale; void *imInfo_dst = nullptr; - int ret = aclrtMalloc(&imInfo_dst, 8, ACL_MEM_MALLOC_NORMAL_ONLY); + int ret = aclrtMalloc(&imInfo_dst, 16, ACL_MEM_MALLOC_NORMAL_ONLY); if (ret != ACL_ERROR_NONE) { std::cout << "aclrtMalloc failed, ret = " << ret << std::endl; aclrtFree(imInfo_dst); - free(im_info); return ret; } - ret = aclrtMemcpy(reinterpret_cast(imInfo_dst), 8, im_info, 8, ACL_MEMCPY_HOST_TO_DEVICE); + ret = aclrtMemcpy(reinterpret_cast(imInfo_dst), 16, im_info, 16, ACL_MEMCPY_HOST_TO_DEVICE); if (ret != ACL_ERROR_NONE) { std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; aclrtFree(imInfo_dst); - free(im_info); return ret; } @@ -320,7 +313,6 @@ int AclProcess::ModelInfer(std::map *costTime_map) { ret = modelProcess_->ModelInference(inputBuffers, inputSizes, outputBuffers_, outputSizes_, costTime_map); if (ret != OK) { aclrtFree(imInfo_dst); - free(im_info); std::cout << "Failed to execute the classification model, ret = " << ret << "." << std::endl; return ret; } @@ -330,7 +322,6 @@ int AclProcess::ModelInfer(std::map *costTime_map) { std::cout << "aclrtFree image info failed" << std::endl; return ret; } - free(im_info); RELEASE_DVPP_DATA(resizeOutData->data); return OK; }