diff --git a/research/cv/AVA_hpa/README.md b/research/cv/AVA_hpa/README.md
index 80a76f4eb528d679cece52cc145c4c6d34ed2a47..6332d965b42156fd962bf68b36b5d0acb16ec91f 100644
--- a/research/cv/AVA_hpa/README.md
+++ b/research/cv/AVA_hpa/README.md
@@ -11,6 +11,10 @@
- [Pre-training Process](#pre-training-process)
- [Training Process](#training-process)
- [Evaluation](#evaluation)
+ - [Inference Process](#inference-process)
+ - [Export MindIR](#export-mindir)
+ - [Infer on Ascend310](#infer-on-ascend310)
+ - [result](#result)
# [AVA_hpa Description](#contents)
@@ -254,3 +258,32 @@ The value of performance will be achieved as follows:
```shell
{'results_return': ( 0.6975821515082009, 0.7734114826162249, 0.9415286419176973)} #macroF1,microF1,auc
```
+
+## Inference Process
+
+### [Export MindIR](#contents)
+
+```shell
+python export.py --ckpt_path [CKPT_PATH] --model_arch [MODEL_ARCH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
+```
+
+- The `CKPT_PATH` parameter is required.
+- `MODEL_ARCH` is model architecture, should be in ['resnet18', 'resnet50', 'resnet101'].
+- `file_format` should be in ["AIR", "MINDIR"]
+
+### Infer on Ascend310
+
+Before performing inference, the mindir file must be exported by `export.py` script. We only provide an example of inference using MINDIR model.
+
+```shell
+# Ascend310 inference
+bash run_infer_310.sh [MINDIR_PATH] [DATASET_PATH] [NEED_PREPROCESS] [DEVICE_ID]
+```
+
+- `DATASET_PATH` is the hpa dataset path.
+- `NEED_PREPROCESS` means weather need preprocess or not, it's value is 'y' or 'n'.
+- `DEVICE_ID` is optional, default value is 0.
+
+### result
+
+Inference result is saved in current path, you can find result like this in acc.log file.
diff --git a/research/cv/AVA_hpa/ascend310_infer/CMakeLists.txt b/research/cv/AVA_hpa/ascend310_infer/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..ee3c85447340e0449ff2b70ed24f60a17e07b2b6
--- /dev/null
+++ b/research/cv/AVA_hpa/ascend310_infer/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.14.1)
+project(Ascend310Infer)
+add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -std=c++17 -Werror -Wall -fPIE -Wl,--allow-shlib-undefined")
+set(PROJECT_SRC_ROOT ${CMAKE_CURRENT_LIST_DIR}/)
+option(MINDSPORE_PATH "mindspore install path" "")
+include_directories(${MINDSPORE_PATH})
+include_directories(${MINDSPORE_PATH}/include)
+include_directories(${PROJECT_SRC_ROOT})
+find_library(MS_LIB libmindspore.so ${MINDSPORE_PATH}/lib)
+file(GLOB_RECURSE MD_LIB ${MINDSPORE_PATH}/_c_dataengine*)
+
+add_executable(main src/main.cc src/utils.cc)
+target_link_libraries(main ${MS_LIB} ${MD_LIB} gflags)
diff --git a/research/cv/AVA_hpa/ascend310_infer/build.sh b/research/cv/AVA_hpa/ascend310_infer/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c7aac7196661fcfa50c3de063336355bf3831286
--- /dev/null
+++ b/research/cv/AVA_hpa/ascend310_infer/build.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+if [ -d out ]; then
+ rm -rf out
+fi
+
+mkdir out
+cd out || exit
+
+if [ -f "Makefile" ]; then
+ make clean
+fi
+
+cmake .. \
+ -DMINDSPORE_PATH="`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`"
+make
\ No newline at end of file
diff --git a/research/cv/AVA_hpa/ascend310_infer/inc/utils.h b/research/cv/AVA_hpa/ascend310_infer/inc/utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..0b400632f51ee34707a5becc00f7f5ba05899b3a
--- /dev/null
+++ b/research/cv/AVA_hpa/ascend310_infer/inc/utils.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MINDSPORE_INFERENCE_UTILS_H_
+#define MINDSPORE_INFERENCE_UTILS_H_
+
+#include <sys/stat.h>
+#include <dirent.h>
+#include <vector>
+#include <string>
+#include <memory>
+#include "include/api/types.h"
+
+DIR *OpenDir(std::string_view dirName);
+std::string RealPath(std::string_view path);
+mindspore::MSTensor ReadFileToTensor(const std::string &file);
+int WriteResult(const std::string& imageFile, const std::vector<mindspore::MSTensor> &outputs);
+std::vector<std::string> GetAllFiles(std::string dir_name);
+
+#endif
diff --git a/research/cv/AVA_hpa/ascend310_infer/src/main.cc b/research/cv/AVA_hpa/ascend310_infer/src/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..39789a5e6c8ed72bd7c13a063ed8bf69fed7ef09
--- /dev/null
+++ b/research/cv/AVA_hpa/ascend310_infer/src/main.cc
@@ -0,0 +1,142 @@
+/**
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <sys/time.h>
+#include <gflags/gflags.h>
+#include <dirent.h>
+#include <iostream>
+#include <string>
+#include <algorithm>
+#include <iosfwd>
+#include <vector>
+#include <fstream>
+#include <sstream>
+
+#include "include/api/model.h"
+#include "include/api/context.h"
+#include "include/api/types.h"
+#include "include/api/serialization.h"
+#include "include/dataset/vision_ascend.h"
+#include "include/dataset/execute.h"
+#include "include/dataset/transforms.h"
+#include "include/dataset/vision.h"
+#include "inc/utils.h"
+
+using mindspore::Context;
+using mindspore::Serialization;
+using mindspore::Model;
+using mindspore::Status;
+using mindspore::ModelType;
+using mindspore::GraphCell;
+using mindspore::kSuccess;
+using mindspore::MSTensor;
+using mindspore::dataset::Execute;
+using mindspore::dataset::vision::Decode;
+using mindspore::dataset::vision::Resize;
+using mindspore::dataset::vision::CenterCrop;
+using mindspore::dataset::vision::Normalize;
+using mindspore::dataset::vision::HWC2CHW;
+
+
+DEFINE_string(mindir_path, "", "mindir path");
+DEFINE_string(input0_path, ".", "input0 path");
+DEFINE_int32(device_id, 0, "device id");
+
+int load_model(Model *model, std::vector<MSTensor> *model_inputs, std::string mindir_path, int device_id) {
+ if (RealPath(mindir_path).empty()) {
+ std::cout << "Invalid mindir" << std::endl;
+ return 1;
+ }
+
+ auto context = std::make_shared<Context>();
+ auto ascend310 = std::make_shared<mindspore::Ascend310DeviceInfo>();
+ ascend310->SetDeviceID(device_id);
+ context->MutableDeviceInfo().push_back(ascend310);
+ mindspore::Graph graph;
+ Serialization::Load(mindir_path, ModelType::kMindIR, &graph);
+
+ Status ret = model->Build(GraphCell(graph), context);
+ if (ret != kSuccess) {
+ std::cout << "ERROR: Build failed." << std::endl;
+ return 1;
+ }
+
+ *model_inputs = model->GetInputs();
+ if (model_inputs->empty()) {
+ std::cout << "Invalid model, inputs is empty." << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ gflags::ParseCommandLineFlags(&argc, &argv, true);
+
+ Model model;
+ std::vector<MSTensor> model_inputs;
+ load_model(&model, &model_inputs, FLAGS_mindir_path, FLAGS_device_id);
+
+ auto input0_files = GetAllFiles(FLAGS_input0_path);
+ if (input0_files.empty()) {
+ std::cout << "ERROR: no input data." << std::endl;
+ return 1;
+ }
+ std::map<double, double> costTime_map;
+ struct timeval start = {0};
+ struct timeval end = {0};
+ size_t size = input0_files.size();
+ for (size_t i = 0; i < size; ++i) {
+ double startTimeMs;
+ double endTimeMs;
+ std::vector<MSTensor> inputs;
+ std::vector<MSTensor> outputs;
+ std::cout << "Start predict input files:" << input0_files[i] <<std::endl;
+ auto input0 = ReadFileToTensor(input0_files[i]);
+ inputs.emplace_back(model_inputs[0].Name(), model_inputs[0].DataType(), model_inputs[0].Shape(),
+ input0.Data().get(), input0.DataSize());
+
+ gettimeofday(&start, nullptr);
+ Status ret = model.Predict(inputs, &outputs);
+ gettimeofday(&end, nullptr);
+ if (ret != kSuccess) {
+ std::cout << "Predict " << input0_files[i] << " failed." << std::endl;
+ return 1;
+ }
+ startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000;
+ endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000;
+ costTime_map.insert(std::pair<double, double>(startTimeMs, endTimeMs));
+ WriteResult(input0_files[i], outputs);
+ }
+
+ double average = 0.0;
+ int inferCount = 0;
+
+ for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
+ double diff = 0.0;
+ diff = iter->second - iter->first;
+ average += diff;
+ inferCount++;
+ }
+ average = average / inferCount;
+ std::stringstream timeCost;
+ timeCost << "NN inference cost average time: "<< average << " ms of infer_count " << inferCount << std::endl;
+ std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl;
+ std::string fileName = "./time_Result" + std::string("/test_perform_static.txt");
+ std::ofstream fileStream(fileName.c_str(), std::ios::trunc);
+ fileStream << timeCost.str();
+ fileStream.close();
+ costTime_map.clear();
+ return 0;
+}
diff --git a/research/cv/AVA_hpa/ascend310_infer/src/utils.cc b/research/cv/AVA_hpa/ascend310_infer/src/utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..728d57d93624e69f25fc0cd9a3c45afe80dab858
--- /dev/null
+++ b/research/cv/AVA_hpa/ascend310_infer/src/utils.cc
@@ -0,0 +1,145 @@
+/**
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <fstream>
+#include <algorithm>
+#include <iostream>
+#include "inc/utils.h"
+
+using mindspore::MSTensor;
+using mindspore::DataType;
+
+std::vector<std::string> GetAllFiles(std::string dirName) {
+ struct dirent *filename;
+ DIR *dir = OpenDir(dirName);
+ if (dir == nullptr) {
+ return {};
+ }
+ std::vector<std::string> dirs;
+ std::vector<std::string> files;
+ while ((filename = readdir(dir)) != nullptr) {
+ std::string dName = std::string(filename->d_name);
+ if (dName == "." || dName == "..") {
+ continue;
+ } else if (filename->d_type == DT_DIR) {
+ dirs.emplace_back(std::string(dirName) + "/" + filename->d_name);
+ } else if (filename->d_type == DT_REG) {
+ files.emplace_back(std::string(dirName) + "/" + filename->d_name);
+ } else {
+ continue;
+ }
+ }
+
+ for (auto d : dirs) {
+ dir = OpenDir(d);
+ while ((filename = readdir(dir)) != nullptr) {
+ std::string dName = std::string(filename->d_name);
+ if (dName == "." || dName == ".." || filename->d_type != DT_REG) {
+ continue;
+ }
+ files.emplace_back(std::string(d) + "/" + filename->d_name);
+ }
+ }
+ std::sort(files.begin(), files.end());
+ for (auto &f : files) {
+ std::cout << "image file: " << f << std::endl;
+ }
+ return files;
+}
+
+int WriteResult(const std::string& imageFile, const std::vector<MSTensor> &outputs) {
+ 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();
+ 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");
+ fwrite(netOutput.get(), outputSize, sizeof(char), outputFile);
+ fclose(outputFile);
+ outputFile = nullptr;
+ }
+ return 0;
+}
+
+mindspore::MSTensor ReadFileToTensor(const std::string &file) {
+ if (file.empty()) {
+ std::cout << "Pointer file is nullptr" << std::endl;
+ return mindspore::MSTensor();
+ }
+
+ std::ifstream ifs(file);
+ if (!ifs.good()) {
+ std::cout << "File: " << file << " is not exist" << std::endl;
+ return mindspore::MSTensor();
+ }
+
+ if (!ifs.is_open()) {
+ std::cout << "File: " << file << "open failed" << std::endl;
+ return mindspore::MSTensor();
+ }
+
+ ifs.seekg(0, std::ios::end);
+ size_t size = ifs.tellg();
+ mindspore::MSTensor buffer(file, mindspore::DataType::kNumberTypeUInt8, {static_cast<int64_t>(size)}, nullptr, size);
+
+ ifs.seekg(0, std::ios::beg);
+ ifs.read(reinterpret_cast<char *>(buffer.MutableData()), size);
+ ifs.close();
+
+ return buffer;
+}
+
+
+DIR *OpenDir(std::string_view dirName) {
+ if (dirName.empty()) {
+ std::cout << " dirName is null ! " << std::endl;
+ return nullptr;
+ }
+ std::string realPath = RealPath(dirName);
+ struct stat s;
+ lstat(realPath.c_str(), &s);
+ if (!S_ISDIR(s.st_mode)) {
+ std::cout << "dirName is not a valid directory !" << std::endl;
+ return nullptr;
+ }
+ DIR *dir;
+ dir = opendir(realPath.c_str());
+ if (dir == nullptr) {
+ std::cout << "Can not open dir " << dirName << std::endl;
+ return nullptr;
+ }
+ std::cout << "Successfully opened the dir " << dirName << std::endl;
+ return dir;
+}
+
+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 "";
+ }
+
+ std::string realPath(realPathMem);
+ std::cout << path << " realpath is: " << realPath << std::endl;
+ return realPath;
+}
diff --git a/research/cv/AVA_hpa/export.py b/research/cv/AVA_hpa/export.py
new file mode 100644
index 0000000000000000000000000000000000000000..fa004ae1897c15b09582bf92bb23ba8c65a0e28d
--- /dev/null
+++ b/research/cv/AVA_hpa/export.py
@@ -0,0 +1,67 @@
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+"""export"""
+import argparse
+import numpy as np
+
+from mindspore import context, Tensor
+from mindspore.train.serialization import load_checkpoint, load_param_into_net, export
+
+from src.resnet import resnet18, resnet50, resnet101
+from src.network_define_eval import EvalCell310
+
+parser = argparse.ArgumentParser(description="export")
+parser.add_argument("--device_id", type=int, default=0,
+ help="Device id, default is 0.")
+parser.add_argument("--device_num", type=int, default=1,
+ help="Use device nums, default is 1.")
+parser.add_argument('--device_target', type=str,
+ default="Ascend", help='Device target')
+parser.add_argument('--ckpt_path', type=str, default="",
+ help='model checkpoint path')
+parser.add_argument("--model_arch", type=str, default="resnet18",
+ choices=['resnet18', 'resnet50', 'resnet101'], help='model architecture')
+parser.add_argument("--classes", type=int, default=10, help='class number')
+parser.add_argument("--file_name", type=str, default="ava_hpa", help='model name')
+parser.add_argument("--file_format", type=str, default="MINDIR",
+ choices=['AIR', 'MINDIR'], help='model format')
+
+args_opt = parser.parse_args()
+
+if __name__ == "__main__":
+ context.set_context(mode=context.GRAPH_MODE,
+ device_target=args_opt.device_target)
+ if args_opt.device_target == "Ascend":
+ context.set_context(device_id=args_opt.device_id)
+ ckpt_path = args_opt.ckpt_path
+
+ if args_opt.model_arch == 'resnet18':
+ resnet = resnet18(pretrain=False, classes=args_opt.classes)
+ elif args_opt.model_arch == 'resnet50':
+ resnet = resnet50(pretrain=False, classes=args_opt.classes)
+ elif args_opt.model_arch == 'resnet101':
+ resnet = resnet101(pretrain=False, classes=args_opt.classes)
+ else:
+ raise "Unsupported net work!"
+ param_dict = load_checkpoint(args_opt.ckpt_path)
+ load_param_into_net(resnet, param_dict)
+
+ bag_size_for_eval = 20
+ image_shape = (224, 224)
+ input_shape = (bag_size_for_eval, 3) + image_shape
+
+ test_network = EvalCell310(resnet)
+ input_data0 = Tensor(np.random.uniform(low=0, high=1.0, size=input_shape).astype(np.float32))
+ export(test_network, input_data0, file_name=args_opt.file_name, file_format=args_opt.file_format)
diff --git a/research/cv/AVA_hpa/postprocess.py b/research/cv/AVA_hpa/postprocess.py
new file mode 100644
index 0000000000000000000000000000000000000000..86c819bb757f406ef994477712009f5e95636a78
--- /dev/null
+++ b/research/cv/AVA_hpa/postprocess.py
@@ -0,0 +1,51 @@
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+"""postprocess."""
+import os
+import argparse
+import numpy as np
+
+from mindspore import Tensor
+from src.network_define_eval import EvalMetric
+
+parser = argparse.ArgumentParser(description="postprocess")
+parser.add_argument("--result_dir", type=str, default="./result_Files",
+ help="infer result dataset directory")
+parser.add_argument("--label_dir", type=str, default="",
+ help="label data file")
+parser.add_argument("--nslice_dir", type=str, default="",
+ help="nslice data file")
+parser.add_argument("--save_eval_path", type=str, default="./eval_result",
+ help="eval result path")
+parser.add_argument("--classes", type=int, default=10, help='class number')
+args_opt = parser.parse_args()
+
+if __name__ == '__main__':
+ batch_size = 1
+ bag_size_for_eval = 20
+ acc = EvalMetric(path=args_opt.save_eval_path)
+ result_num = len(os.listdir(args_opt.result_dir))
+ label_list = np.load(args_opt.label_dir)
+ nslice_list = np.load(args_opt.nslice_dir)
+ for i in range(result_num):
+ f = "ava_bs" + str(batch_size) + "_" + str(i) + "_0.bin"
+ feature = np.fromfile(os.path.join(args_opt.result_dir, f), np.float32)
+ feature = Tensor(feature.reshape(bag_size_for_eval, args_opt.classes))
+ label = Tensor(label_list[i])
+ nslice = Tensor(nslice_list[i])
+ inputs = (feature, label, nslice)
+ acc.update(*inputs)
+ result_return = acc.eval()
+ print("The result is {}.".format(result_return))
diff --git a/research/cv/AVA_hpa/preprocess.py b/research/cv/AVA_hpa/preprocess.py
new file mode 100644
index 0000000000000000000000000000000000000000..0f926220f580d6b28f9a57878b122842de358b52
--- /dev/null
+++ b/research/cv/AVA_hpa/preprocess.py
@@ -0,0 +1,53 @@
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+"""preprocess."""
+
+import os
+import argparse
+import numpy as np
+
+from src.datasets import makeup_dataset
+
+
+parser = argparse.ArgumentParser(description="preprocess")
+parser.add_argument("--data_dir", type=str, default="", help="dataset path")
+parser.add_argument("--classes", type=int, default=10, help='class number')
+parser.add_argument("--pre_result_dir", type=str, default="./preprocess_Result",
+ help="preprocess data path")
+args_opt = parser.parse_args()
+
+if __name__ == '__main__':
+ batch_size = 1
+ data_dir = args_opt.data_dir
+
+ test_dataset = makeup_dataset(data_dir=data_dir, mode='test', batch_size=1, bag_size=20, classes=args_opt.classes,
+ num_parallel_workers=8)
+ test_dataset.__loop_size__ = 1
+
+ image_path = os.path.join(args_opt.pre_result_dir, "00_data")
+ label_path = os.path.join(args_opt.pre_result_dir, "label.npy")
+ nslice_path = os.path.join(args_opt.pre_result_dir, "nslice.npy")
+ os.makedirs(image_path, exist_ok=True)
+ label_list = []
+ nslice_list = []
+ for i, data in enumerate(test_dataset.create_dict_iterator(output_numpy=True)):
+ file_name = "ava_bs" + str(batch_size) + "_" + str(i) + ".bin"
+ file_path = os.path.join(image_path, file_name)
+ data["imgs"].tofile(file_path)
+ label_list.append(data["labels"])
+ nslice_list.append(data["nslice"])
+ np.save(os.path.join(label_path), label_list)
+ np.save(os.path.join(nslice_path), nslice_list)
+ print("=" * 20, "export bin files finished", "=" * 20)
diff --git a/research/cv/AVA_hpa/scripts/run_infer_310.sh b/research/cv/AVA_hpa/scripts/run_infer_310.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7a044eaf7e40a6e276e1b9cf6a4ad3da16fe5ff8
--- /dev/null
+++ b/research/cv/AVA_hpa/scripts/run_infer_310.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============================================================================
+
+if [[ $# -lt 3 || $# -gt 4 ]]; then
+ echo "Usage: bash run_infer_310.sh [MINDIR_PATH] [DATASET_PATH] [NEED_PREPROCESS] [DEVICE_ID]
+ NEED_PREPROCESS means weather need preprocess or not, it's value is 'y' or 'n'.
+ DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero"
+exit 1
+fi
+
+get_real_path(){
+ if [ "${1:0:1}" == "/" ]; then
+ echo "$1"
+ else
+ echo "$(realpath -m $PWD/$1)"
+ fi
+}
+model=$(get_real_path $1)
+dataset_path=$(get_real_path $2)
+
+if [ $3 == 'y' ] || [ $3 == 'n' ]; then
+ need_preprocess=$3
+else
+ echo "weather need preprocess or not, it's value must be in [y, n]"
+ exit 1
+fi
+
+device_id=0
+if [ $# == 4 ]; then
+ device_id=$4
+fi
+
+echo "mindir name: "$model
+echo "dataset path: "$dataset_path
+echo "need preprocess: "$need_preprocess
+echo "device id: "$device_id
+
+export ASCEND_HOME=/usr/local/Ascend/
+if [ -d ${ASCEND_HOME}/ascend-toolkit ]; then
+ export PATH=$ASCEND_HOME/fwkacllib/bin:$ASCEND_HOME/fwkacllib/ccec_compiler/bin:$ASCEND_HOME/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin:$ASCEND_HOME/ascend-toolkit/latest/atc/bin:$PATH
+ export LD_LIBRARY_PATH=$ASCEND_HOME/fwkacllib/lib64:/usr/local/lib:$ASCEND_HOME/ascend-toolkit/latest/atc/lib64:$ASCEND_HOME/ascend-toolkit/latest/fwkacllib/lib64:$ASCEND_HOME/driver/lib64:$ASCEND_HOME/add-ons:$LD_LIBRARY_PATH
+ export TBE_IMPL_PATH=$ASCEND_HOME/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe
+ export PYTHONPATH=$ASCEND_HOME/fwkacllib/python/site-packages:${TBE_IMPL_PATH}:$ASCEND_HOME/ascend-toolkit/latest/fwkacllib/python/site-packages:$PYTHONPATH
+ export ASCEND_OPP_PATH=$ASCEND_HOME/ascend-toolkit/latest/opp
+else
+ export PATH=$ASCEND_HOME/fwkacllib/bin:$ASCEND_HOME/fwkacllib/ccec_compiler/bin:$ASCEND_HOME/atc/ccec_compiler/bin:$ASCEND_HOME/atc/bin:$PATH
+ export LD_LIBRARY_PATH=$ASCEND_HOME/fwkacllib/lib64:/usr/local/lib:$ASCEND_HOME/atc/lib64:$ASCEND_HOME/acllib/lib64:$ASCEND_HOME/driver/lib64:$ASCEND_HOME/add-ons:$LD_LIBRARY_PATH
+ export PYTHONPATH=$ASCEND_HOME/fwkacllib/python/site-packages:$ASCEND_HOME/atc/python/site-packages:$PYTHONPATH
+ export ASCEND_OPP_PATH=$ASCEND_HOME/opp
+fi
+
+function compile_app()
+{
+ cd ../ascend310_infer/ || exit
+ bash build.sh &> build.log
+}
+
+function preprocess_data()
+{
+ if [ -d preprocess_Result ]; then
+ rm -rf ./preprocess_Result
+ fi
+ mkdir preprocess_Result
+ rm -rf enhanced.csv && cp ../enhanced.csv .
+ if [ $? -ne 0 ]; then
+ echo "enhanced.csv missed, please check."
+ exit 1
+ fi
+ python ../preprocess.py --data_dir $dataset_path
+}
+
+function infer()
+{
+ cd - || exit
+ if [ -d result_Files ]; then
+ rm -rf ./result_Files
+ fi
+ if [ -d time_Result ]; then
+ rm -rf ./time_Result
+ fi
+ mkdir result_Files
+ mkdir time_Result
+ ../ascend310_infer/out/main --mindir_path=$model --input0_path=./preprocess_Result/00_data --device_id=$device_id &> infer.log
+}
+
+function cal_acc()
+{
+ python ../postprocess.py --result_dir=./result_Files --label_dir=./preprocess_Result/label.npy --nslice_dir=./preprocess_Result/nslice.npy &> acc.log
+}
+
+if [ $need_preprocess == "y" ]; then
+ preprocess_data
+ if [ $? -ne 0 ]; then
+ echo "preprocess data failed"
+ exit 1
+ fi
+fi
+
+compile_app
+if [ $? -ne 0 ]; then
+ echo "compile app code failed"
+ exit 1
+fi
+infer
+if [ $? -ne 0 ]; then
+ echo " execute inference failed"
+ exit 1
+fi
+cal_acc
+if [ $? -ne 0 ]; then
+ echo "calculate accuracy failed"
+ exit 1
+fi
\ No newline at end of file
diff --git a/research/cv/AVA_hpa/src/network_define_eval.py b/research/cv/AVA_hpa/src/network_define_eval.py
index 49e45bf0f3d73d5ba0c7852f92163668d2d7c450..8a47153a263300b49318b014b45a7e409981feba 100644
--- a/research/cv/AVA_hpa/src/network_define_eval.py
+++ b/research/cv/AVA_hpa/src/network_define_eval.py
@@ -62,6 +62,15 @@ class EvalCell(nn.Cell):
outputs = self._network(data)
return outputs, label, nslice
+class EvalCell310(nn.Cell):
+ """eval cell"""
+ def __init__(self, network):
+ super(EvalCell310, self).__init__(auto_prefix=False)
+ self._network = network
+
+ def construct(self, data):
+ outputs = self._network(data)
+ return outputs
class EvalMetric(nn.Metric):
"""eval metric"""