Browse Source

!15936 fix codex

From: @yuzhenhua666
Reviewed-by: @c_34,@oacjiewen
Signed-off-by: @c_34
pull/15936/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
cb6e055736
11 changed files with 38 additions and 55 deletions
  1. +5
    -5
      model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc
  2. +2
    -4
      model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc
  3. +3
    -2
      model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc
  4. +3
    -6
      model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc
  5. +0
    -1
      model_zoo/official/cv/resnet/ascend310_infer/src/main.cc
  6. +6
    -6
      model_zoo/official/cv/unet/ascend310_infer/src/main.cc
  7. +12
    -25
      model_zoo/official/cv/unet/postprocess.py
  8. +4
    -0
      model_zoo/official/cv/unet/preprocess.py
  9. +1
    -2
      model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc
  10. +1
    -2
      model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp
  11. +1
    -2
      model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp

+ 5
- 5
model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc View File

@@ -99,11 +99,11 @@ int main(int argc, char **argv) {
return 1;
}

std::shared_ptr<TensorTransform> decode(new Decode());
std::shared_ptr<TensorTransform> resize(new Resize({576, 960}));
std::shared_ptr<TensorTransform> normalize(new Normalize({123.675, 116.28, 103.53}, {58.395, 57.12, 57.375}));
std::shared_ptr<TensorTransform> hwc2chw(new HWC2CHW());
std::shared_ptr<TensorTransform> typeCast(new TypeCast(DataType::kNumberTypeFloat16));
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(DataType::kNumberTypeFloat16);

mindspore::dataset::Execute transformDecode(decode);
mindspore::dataset::Execute transform({resize, normalize, hwc2chw});


+ 2
- 4
model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc View File

@@ -48,8 +48,7 @@ int WriteResult(const std::string& imageFile, const std::vector<MSTensor> &outpu
std::string homePath = "./result_Files";
for (size_t i = 0; i < outputs.size(); ++i) {
size_t outputSize;
std::shared_ptr<const void> netOutput;
netOutput = outputs[i].Data();
std::shared_ptr<const void> 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;


+ 3
- 2
model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc View File

@@ -101,7 +101,8 @@ int main(int argc, char **argv) {
std::map<double, double> costTime_map;
size_t size = all_files.size();

Execute transform(std::shared_ptr<DvppDecodeResizeJpeg>(new DvppDecodeResizeJpeg({576, 960})));
auto dvppDecodeResizeJpeg = DvppDecodeResizeJpeg({576, 960});
Execute transform(dvppDecodeResizeJpeg);

for (size_t i = 0; i < size; ++i) {
struct timeval start;
@@ -141,7 +142,7 @@ int main(int argc, char **argv) {
infer_cnt++;
}

average = average/infer_cnt;
average = average / infer_cnt;
std::stringstream timeCost;
timeCost << "NN inference cost average time: "<< average << " ms of infer_count " << infer_cnt << std::endl;
std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl;


+ 3
- 6
model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc View File

@@ -48,14 +48,13 @@ int WriteResult(const std::string& imageFile, const std::vector<MSTensor> &outpu
std::string homePath = "./result_Files";
for (size_t i = 0; i < outputs.size(); ++i) {
size_t outputSize;
std::shared_ptr<const void> netOutput;
netOutput = outputs[i].Data();
std::shared_ptr<const void> 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 "";


+ 0
- 1
model_zoo/official/cv/resnet/ascend310_infer/src/main.cc View File

@@ -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;


+ 6
- 6
model_zoo/official/cv/unet/ascend310_infer/src/main.cc View File

@@ -72,7 +72,7 @@ int main(int argc, char **argv) {
Model model;
Status ret = model.Build(GraphCell(graph), context);
if (ret != kSuccess) {
std::cout << "EEEEEEEERROR Build failed." << std::endl;
std::cout << "ERROR Build failed." << std::endl;
return 1;
}

@@ -86,11 +86,11 @@ int main(int argc, char **argv) {
std::map<double, double> 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) {


+ 12
- 25
model_zoo/official/cv/unet/postprocess.py View File

@@ -18,7 +18,6 @@ import argparse
import cv2
import numpy as np

from src.data_loader import create_dataset, create_cell_nuclei_dataset
from src.config import cfg_unet

class dice_coeff():
@@ -74,25 +73,6 @@ class dice_coeff():
raise RuntimeError('Total samples num must not be 0.')
return (self._dice_coeff_sum / float(self._samples_num), self._iou_sum / float(self._samples_num))


def test_net(data_dir,
cross_valid_ind=1,
cfg=None):

if 'dataset' in cfg and cfg['dataset'] == "Cell_nuclei":
valid_dataset = create_cell_nuclei_dataset(data_dir, cfg['img_size'], 1, 1, is_train=False,
eval_resize=cfg["eval_resize"], split=0.8)
else:
_, valid_dataset = create_dataset(data_dir, 1, 1, False, cross_valid_ind, False, do_crop=cfg['crop'],
img_size=cfg['img_size'])
labels_list = []

for data in valid_dataset:
labels_list.append(data[1].asnumpy())

return labels_list


def get_args():
parser = argparse.ArgumentParser(description='Test the UNet on images and target masks',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -105,24 +85,31 @@ def get_args():


if __name__ == '__main__':

args = get_args()

label_list = test_net(data_dir=args.data_url, cross_valid_ind=cfg_unet['cross_valid_ind'], cfg=cfg_unet)
rst_path = args.rst_path
metrics = dice_coeff()

if 'dataset' in cfg_unet and cfg_unet['dataset'] == "Cell_nuclei":
img_size = tuple(cfg_unet['img_size'])
for i, bin_name in enumerate(os.listdir('./preprocess_Result/')):
bin_name_softmax = bin_name.replace(".png", "") + "_0.bin"
bin_name_argmax = bin_name.replace(".png", "") + "_1.bin"
f = bin_name.replace(".png", "")
bin_name_softmax = f + "_0.bin"
bin_name_argmax = f + "_1.bin"
file_name_sof = rst_path + bin_name_softmax
file_name_arg = rst_path + bin_name_argmax
softmax_out = np.fromfile(file_name_sof, np.float32).reshape(1, 96, 96, 2)
argmax_out = np.fromfile(file_name_arg, np.float32).reshape(1, 96, 96)
label = label_list[i]
mask = cv2.imread(os.path.join(args.data_url, f, "mask.png"), cv2.IMREAD_GRAYSCALE)
mask = cv2.resize(mask, img_size)
mask = mask.astype(np.float32) / 255
mask = (mask > 0.5).astype(np.int)
mask = (np.arange(2) == mask[..., None]).astype(int)
mask = mask.transpose(2, 0, 1).astype(np.float32)
label = mask.reshape(1, 2, 96, 96)
metrics.update((softmax_out, argmax_out), label)
else:
label_list = np.load('label.npy')
for j in range(len(os.listdir('./preprocess_Result/'))):
file_name_sof = rst_path + "ISBI_test_bs_1_" + str(j) + "_0" + ".bin"
file_name_arg = rst_path + "ISBI_test_bs_1_" + str(j) + "_1" + ".bin"


+ 4
- 0
model_zoo/official/cv/unet/preprocess.py View File

@@ -27,11 +27,15 @@ def preprocess_dataset(data_dir, result_path, cross_valid_ind=1, cfg=None):
_, valid_dataset = create_dataset(data_dir, 1, 1, False, cross_valid_ind, False, do_crop=cfg['crop'],
img_size=cfg['img_size'])

labels_list = []
for i, data in enumerate(valid_dataset):
file_name = "ISBI_test_bs_1_" + str(i) + ".bin"
file_path = result_path + file_name
data[0].asnumpy().tofile(file_path)

labels_list.append(data[1].asnumpy())

np.save("./label.npy", labels_list)

class CellNucleiDataset:
"""


+ 1
- 2
model_zoo/official/cv/yolov4/ascend310_infer/src/main.cc View File

@@ -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);
}
@@ -83,7 +82,7 @@ int main(int argc, char **argv) {
Model model;
Status ret = model.Build(GraphCell(graph), context);
if (ret != kSuccess) {
std::cout << "EEEEEEEERROR Build failed." << std::endl;
std::cout << "ERROR Build failed." << std::endl;
return 1;
}



+ 1
- 2
model_zoo/official/recommend/naml/ascend310_infer/src/sample_process.cpp View File

@@ -350,8 +350,7 @@ std::vector<std::string> 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());


+ 1
- 2
model_zoo/official/recommend/naml/ascend310_infer/src/utils.cpp View File

@@ -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;


Loading…
Cancel
Save