From: @zhouneng2 Reviewed-by: @linqingke,@liangchenghui Signed-off-by: @linqingkepull/14558/MERGE
| @@ -284,19 +284,24 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) { | |||||
| heightScale = static_cast<float>(resizeOutData->height) / inputImg->height; | 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; | 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) { | if (ret != ACL_ERROR_NONE) { | ||||
| std::cout << "aclrtMalloc failed, ret = " << ret << std::endl; | std::cout << "aclrtMalloc failed, ret = " << ret << std::endl; | ||||
| aclrtFree(imInfo_dst); | aclrtFree(imInfo_dst); | ||||
| return ret; | 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) { | if (ret != ACL_ERROR_NONE) { | ||||
| std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; | std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; | ||||
| aclrtFree(imInfo_dst); | aclrtFree(imInfo_dst); | ||||
| @@ -17,6 +17,7 @@ import argparse | |||||
| import numpy as np | import numpy as np | ||||
| import mindspore as ms | import mindspore as ms | ||||
| import mindspore.common.dtype as mstype | |||||
| from mindspore import Tensor, load_checkpoint, load_param_into_net, export, context | from mindspore import Tensor, load_checkpoint, load_param_into_net, export, context | ||||
| from src.FasterRcnn.faster_rcnn_r50 import FasterRcnn_Infer | from src.FasterRcnn.faster_rcnn_r50 import FasterRcnn_Infer | ||||
| @@ -46,6 +47,10 @@ if __name__ == '__main__': | |||||
| load_param_into_net(net, param_dict_new) | 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 = 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) | img_metas = Tensor(np.random.uniform(0.0, 1.0, size=[config.test_batch_size, 4]), ms.float32) | ||||
| @@ -45,7 +45,7 @@ def get_eval_result(ann_file): | |||||
| label_result_file = result_path + file_id + "_1.bin" | label_result_file = result_path + file_id + "_1.bin" | ||||
| mask_result_file = result_path + file_id + "_2.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_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) | all_mask = np.fromfile(mask_result_file, dtype=np.bool_).reshape(80000, 1) | ||||