Browse Source

!14558 fix export mindir failure for fasterrcnn

From: @zhouneng2
Reviewed-by: @linqingke,@liangchenghui
Signed-off-by: @linqingke
pull/14558/MERGE
mindspore-ci-bot Gitee 5 years ago
parent
commit
010cc0cecd
3 changed files with 18 additions and 8 deletions
  1. +12
    -7
      model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp
  2. +5
    -0
      model_zoo/official/cv/faster_rcnn/export.py
  3. +1
    -1
      model_zoo/official/cv/faster_rcnn/postprocess.py

+ 12
- 7
model_zoo/official/cv/faster_rcnn/ascend310_infer/src/AclProcess.cpp View File

@@ -284,19 +284,24 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) {
heightScale = static_cast<float>(resizeOutData->height) / inputImg->height;
}

float im_info[4];
im_info[0] = static_cast<float>(inputImg->height);
im_info[1] = static_cast<float>(inputImg->width);
im_info[2] = heightScale;
im_info[3] = widthScale;
aclFloat16 inputWidth = aclFloatToFloat16(static_cast<float>(inputImg->width));
aclFloat16 inputHeight = aclFloatToFloat16(static_cast<float>(inputImg->height));
aclFloat16 resizeWidthRatioFp16 = aclFloatToFloat16(widthScale);
aclFloat16 resizeHeightRatioFp16 = aclFloatToFloat16(heightScale);

aclFloat16 *im_info = reinterpret_cast<aclFloat16 *>(malloc(sizeof(aclFloat16) * 4));
im_info[0] = inputHeight;
im_info[1] = inputWidth;
im_info[2] = resizeHeightRatioFp16;
im_info[3] = resizeWidthRatioFp16;
void *imInfo_dst = nullptr;
int ret = aclrtMalloc(&imInfo_dst, 16, ACL_MEM_MALLOC_NORMAL_ONLY);
int ret = aclrtMalloc(&imInfo_dst, 8, ACL_MEM_MALLOC_NORMAL_ONLY);
if (ret != ACL_ERROR_NONE) {
std::cout << "aclrtMalloc failed, ret = " << ret << std::endl;
aclrtFree(imInfo_dst);
return ret;
}
ret = aclrtMemcpy(reinterpret_cast<uint8_t *>(imInfo_dst), 16, im_info, 16, ACL_MEMCPY_HOST_TO_DEVICE);
ret = aclrtMemcpy(reinterpret_cast<uint8_t *>(imInfo_dst), 8, im_info, 8, ACL_MEMCPY_HOST_TO_DEVICE);
if (ret != ACL_ERROR_NONE) {
std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl;
aclrtFree(imInfo_dst);


+ 5
- 0
model_zoo/official/cv/faster_rcnn/export.py View File

@@ -17,6 +17,7 @@ import argparse
import numpy as np

import mindspore as ms
import mindspore.common.dtype as mstype
from mindspore import Tensor, load_checkpoint, load_param_into_net, export, context

from src.FasterRcnn.faster_rcnn_r50 import FasterRcnn_Infer
@@ -46,6 +47,10 @@ if __name__ == '__main__':

load_param_into_net(net, param_dict_new)

device_type = "Ascend" if context.get_context("device_target") == "Ascend" else "Others"
if device_type == "Ascend":
net.to_float(mstype.float16)

img = Tensor(np.zeros([config.test_batch_size, 3, config.img_height, config.img_width]), ms.float32)
img_metas = Tensor(np.random.uniform(0.0, 1.0, size=[config.test_batch_size, 4]), ms.float32)



+ 1
- 1
model_zoo/official/cv/faster_rcnn/postprocess.py View File

@@ -45,7 +45,7 @@ def get_eval_result(ann_file):
label_result_file = result_path + file_id + "_1.bin"
mask_result_file = result_path + file_id + "_2.bin"

all_bbox = np.fromfile(bbox_result_file, dtype=np.float32).reshape(80000, 5)
all_bbox = np.fromfile(bbox_result_file, dtype=np.float16).reshape(80000, 5)
all_label = np.fromfile(label_result_file, dtype=np.int32).reshape(80000, 1)
all_mask = np.fromfile(mask_result_file, dtype=np.bool_).reshape(80000, 1)



Loading…
Cancel
Save