From 4d5a8b93208f5409d0a0cf0e86375f5de40a4989 Mon Sep 17 00:00:00 2001 From: yuzhenhua Date: Thu, 29 Apr 2021 11:11:05 +0800 Subject: [PATCH] fix codex --- .../official/cv/ctpn/ascend310_infer/inc/utils.h | 6 +++--- .../official/cv/ctpn/ascend310_infer/src/main.cc | 10 +++++----- .../official/cv/ctpn/ascend310_infer/src/utils.cc | 12 +++++------- .../cv/deeptext/ascend310_infer/inc/utils.h | 6 +++--- .../cv/deeptext/ascend310_infer/src/main.cc | 3 ++- .../cv/deeptext/ascend310_infer/src/utils.cc | 15 ++++++--------- .../ascend310_infer/src/AclProcess.cpp | 3 +-- .../cv/faster_rcnn/ascend310_infer/src/main.cpp | 5 +++-- .../maskrcnn/ascend310_infer/src/AclProcess.cpp | 3 +++ .../cv/resnet/ascend310_infer/src/main.cc | 14 ++++++-------- .../official/cv/unet/ascend310_infer/src/main.cc | 10 +++++----- .../cv/yolov4/ascend310_infer/src/main.cc | 1 - .../naml/ascend310_infer/src/sample_process.cpp | 3 +-- .../recommend/naml/ascend310_infer/src/utils.cpp | 3 +-- 14 files changed, 44 insertions(+), 50 deletions(-) diff --git a/model_zoo/official/cv/ctpn/ascend310_infer/inc/utils.h b/model_zoo/official/cv/ctpn/ascend310_infer/inc/utils.h index efebe03a8c..abeb8fcbf1 100644 --- a/model_zoo/official/cv/ctpn/ascend310_infer/inc/utils.h +++ b/model_zoo/official/cv/ctpn/ascend310_infer/inc/utils.h @@ -1,12 +1,12 @@ /** * Copyright 2021 Huawei Technologies Co., Ltd - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc b/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc index fbd898070f..8fffc44e9f 100644 --- a/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc @@ -99,11 +99,11 @@ int main(int argc, char **argv) { return 1; } - std::shared_ptr decode(new Decode()); - std::shared_ptr resize(new Resize({576, 960})); - std::shared_ptr normalize(new Normalize({123.675, 116.28, 103.53}, {58.395, 57.12, 57.375})); - std::shared_ptr hwc2chw(new HWC2CHW()); - std::shared_ptr typeCast(new TypeCast("float16")); + auto decode = Decode(); + auto resize = Resize({576, 960}); + auto normalize = Normalize({123.675, 116.28, 103.53}, {58.395, 57.12, 57.375}); + auto hwc2chw = HWC2CHW(); + auto typeCast = TypeCast("float16"); mindspore::dataset::Execute transformDecode(decode); mindspore::dataset::Execute transform({resize, normalize, hwc2chw}); diff --git a/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc b/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc index e753dafa89..4557e1c345 100644 --- a/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc @@ -1,12 +1,12 @@ /** * Copyright 2021 Huawei Technologies Co., Ltd - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -48,8 +48,7 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu std::string homePath = "./result_Files"; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; - std::shared_ptr netOutput; - netOutput = outputs[i].Data(); + std::shared_ptr netOutput = outputs[i].Data(); outputSize = outputs[i].DataSize(); int pos = imageFile.rfind('/'); std::string fileName(imageFile, pos + 1); @@ -104,8 +103,7 @@ DIR *OpenDir(std::string_view dirName) { std::cout << "dirName is not a valid directory !" << std::endl; return nullptr; } - DIR *dir; - dir = opendir(realPath.c_str()); + DIR *dir = opendir(realPath.c_str()); if (dir == nullptr) { std::cout << "Can not open dir " << dirName << std::endl; return nullptr; diff --git a/model_zoo/official/cv/deeptext/ascend310_infer/inc/utils.h b/model_zoo/official/cv/deeptext/ascend310_infer/inc/utils.h index efebe03a8c..abeb8fcbf1 100644 --- a/model_zoo/official/cv/deeptext/ascend310_infer/inc/utils.h +++ b/model_zoo/official/cv/deeptext/ascend310_infer/inc/utils.h @@ -1,12 +1,12 @@ /** * Copyright 2021 Huawei Technologies Co., Ltd - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc b/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc index 66532a03b7..0066d6651b 100644 --- a/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc @@ -101,7 +101,8 @@ int main(int argc, char **argv) { std::map costTime_map; size_t size = all_files.size(); - Execute transform(std::shared_ptr(new DvppDecodeResizeJpeg({576, 960}))); + auto dvppDecodeResizeJpeg = DvppDecodeResizeJpeg({576, 960}); + Execute transform(dvppDecodeResizeJpeg); for (size_t i = 0; i < size; ++i) { struct timeval start; diff --git a/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc b/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc index b509c57f82..4557e1c345 100644 --- a/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc @@ -1,12 +1,12 @@ /** * Copyright 2021 Huawei Technologies Co., Ltd - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -48,14 +48,13 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu std::string homePath = "./result_Files"; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; - std::shared_ptr netOutput; - netOutput = outputs[i].Data(); + std::shared_ptr netOutput = outputs[i].Data(); outputSize = outputs[i].DataSize(); int pos = imageFile.rfind('/'); std::string fileName(imageFile, pos + 1); fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; - FILE * outputFile = fopen(outFileName.c_str(), "wb"); + FILE *outputFile = fopen(outFileName.c_str(), "wb"); fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); fclose(outputFile); outputFile = nullptr; @@ -104,8 +103,7 @@ DIR *OpenDir(std::string_view dirName) { std::cout << "dirName is not a valid directory !" << std::endl; return nullptr; } - DIR *dir; - dir = opendir(realPath.c_str()); + DIR *dir = opendir(realPath.c_str()); if (dir == nullptr) { std::cout << "Can not open dir " << dirName << std::endl; return nullptr; @@ -118,7 +116,6 @@ std::string RealPath(std::string_view path) { char realPathMem[PATH_MAX] = {0}; char *realPathRet = nullptr; realPathRet = realpath(path.data(), realPathMem); - if (realPathRet == nullptr) { std::cout << "File: " << path << " is not exist."; return ""; 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 8d27285793..a9e1bb0db8 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 @@ -142,8 +142,7 @@ int AclProcess::WriteResult(const std::string& imageFile) { void *resHostBuf = nullptr; for (size_t i = 0; i < outputBuffers_.size(); ++i) { size_t output_size; - void *netOutput; - netOutput = outputBuffers_[i]; + void *netOutput = outputBuffers_[i]; output_size = outputSizes_[i]; int ret = aclrtMallocHost(&resHostBuf, output_size); if (ret != OK) { diff --git a/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/main.cpp b/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/main.cpp index f9f9cd6620..b630febed6 100755 --- a/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/main.cpp +++ b/model_zoo/official/cv/faster_rcnn/ascend310_infer/src/main.cpp @@ -88,8 +88,7 @@ int main(int argc, char* argv[]) { } } else if (is_dir(FLAGS_data_path)) { struct dirent *filename; - DIR *dir; - dir = opendir(FLAGS_data_path.c_str()); + DIR *dir = opendir(FLAGS_data_path.c_str()); if (dir == nullptr) { aclProcess.Release(); return ERROR; @@ -104,9 +103,11 @@ int main(int argc, char* argv[]) { if (ret != OK) { std::cout << "model process failed, errno = " << ret << std::endl; aclProcess.Release(); + closedir(dir); return ret; } } + closedir(dir); } else { std::cout << " input image path error" << std::endl; } diff --git a/model_zoo/official/cv/maskrcnn/ascend310_infer/src/AclProcess.cpp b/model_zoo/official/cv/maskrcnn/ascend310_infer/src/AclProcess.cpp index f9a16badd4..7a1b806c05 100755 --- a/model_zoo/official/cv/maskrcnn/ascend310_infer/src/AclProcess.cpp +++ b/model_zoo/official/cv/maskrcnn/ascend310_infer/src/AclProcess.cpp @@ -298,12 +298,14 @@ int AclProcess::ModelInfer(std::map *costTime_map) { 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); if (ret != ACL_ERROR_NONE) { std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; aclrtFree(imInfo_dst); + free(im_info); return ret; } @@ -327,6 +329,7 @@ int AclProcess::ModelInfer(std::map *costTime_map) { return ret; } RELEASE_DVPP_DATA(resizeOutData->data); + free(im_info); return OK; } diff --git a/model_zoo/official/cv/resnet/ascend310_infer/src/main.cc b/model_zoo/official/cv/resnet/ascend310_infer/src/main.cc index 5bfaf218f0..03ab5841af 100644 --- a/model_zoo/official/cv/resnet/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/resnet/ascend310_infer/src/main.cc @@ -70,7 +70,6 @@ int main(int argc, char **argv) { Serialization::Load(FLAGS_mindir_path, ModelType::kMindIR, &graph); Model model; Status ret = model.Build(GraphCell(graph), context); - if (ret != kSuccess) { std::cout << "ERROR: Build failed." << std::endl; return 1; @@ -90,14 +89,13 @@ int main(int argc, char **argv) { std::vector mean = {0.485 * 255, 0.456 * 255, 0.406 * 255}; std::vector std = {0.229 * 255, 0.224 * 255, 0.225 * 255}; - std::shared_ptr decode(new Decode()); - std::shared_ptr resize(new Resize(resize_paras)); - std::shared_ptr centercrop(new CenterCrop(crop_paras)); - std::shared_ptr normalize(new Normalize(mean, std)); - std::shared_ptr hwc2chw(new HWC2CHW()); + auto decode = Decode(); + auto resize = Resize(resize_paras); + auto centercrop = CenterCrop(crop_paras); + auto normalize = Normalize(mean, std); + auto hwc2chw = HWC2CHW(); - std::vector> trans_list = {decode, resize, centercrop, normalize, hwc2chw}; - mindspore::dataset::Execute SingleOp(trans_list); + mindspore::dataset::Execute SingleOp({decode, resize, centercrop, normalize, hwc2chw}); for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < all_files[i].size(); ++j) { diff --git a/model_zoo/official/cv/unet/ascend310_infer/src/main.cc b/model_zoo/official/cv/unet/ascend310_infer/src/main.cc index cfb4e971a4..a8cb78e463 100644 --- a/model_zoo/official/cv/unet/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/unet/ascend310_infer/src/main.cc @@ -86,11 +86,11 @@ int main(int argc, char **argv) { std::map costTime_map; size_t size = all_files.size(); - auto decode(new Decode()); - auto swapredblue(new SwapRedBlue()); - auto resize(new Resize({96, 96})); - auto normalize(new Normalize({127.5, 127.5, 127.5}, {127.5, 127.5, 127.5})); - auto hwc2chw(new HWC2CHW()); + auto decode = Decode(); + auto swapredblue = SwapRedBlue(); + auto resize = Resize({96, 96}); + auto normalize = Normalize({127.5, 127.5, 127.5}, {127.5, 127.5, 127.5}); + auto hwc2chw = HWC2CHW(); Execute preprocess({decode, swapredblue, resize, normalize, hwc2chw}); for (size_t i = 0; i < size; ++i) { diff --git a/model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc b/model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc index edd36be602..b14875cd1d 100644 --- a/model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc @@ -69,7 +69,6 @@ int main(int argc, char **argv) { mindspore::Graph graph; Serialization::Load(FLAGS_mindir_path, ModelType::kMindIR, &graph); - if (!FLAGS_precision_mode.empty()) { ascend310->SetPrecisionMode(FLAGS_precision_mode); } diff --git a/model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp b/model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp index 9e5614bf0c..e0772ca09b 100644 --- a/model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp +++ b/model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp @@ -350,8 +350,7 @@ std::vector SampleProcess::GetModelExecCostTimeInfo() { " ms of infer_count " << infer_cnt << std::endl; result.emplace_back(timeCost.str()); - double totalCostTime; - totalCostTime = totalCostTime_map_.begin()->second - totalCostTime_map_.begin()->first; + double totalCostTime = totalCostTime_map_.begin()->second - totalCostTime_map_.begin()->first; std::stringstream totalTimeCost; totalTimeCost << "total inference cost time: "<< totalCostTime << " ms; count " << infer_cnt << std::endl; result.emplace_back(totalTimeCost.str()); diff --git a/model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp b/model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp index 085dcde12b..6898dc6770 100644 --- a/model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp +++ b/model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp @@ -157,8 +157,7 @@ DIR *Utils::OpenDir(std::string dir_name) { return nullptr; } - DIR *dir; - dir = opendir(real_path.c_str()); + DIR *dir = opendir(real_path.c_str()); if (dir == nullptr) { std::cout << "Can not open dir " << dir_name << std::endl; return nullptr;