diff --git a/contrib/Burpee_Detection/App_burpee_detection/app_main.py b/contrib/Burpee_Detection/App_burpee_detection/app_main.py deleted file mode 100644 index 81f7c6b89268888406462c7cf6f0d695427f7a6a..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/App_burpee_detection/app_main.py +++ /dev/null @@ -1,202 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -import shutil -import json -import os -import sys -import logging -import cv2 - -import MxpiDataType_pb2 as MxpiDataType -from StreamManagerApi import StreamManagerApi, MxDataInput, StringVector - -from qcloud_cos import CosConfig -from qcloud_cos import CosS3Client - - -class OStream: - def __init__(self, file): - self.file = file - - def __lshift__(self, obj): - self.file.write(str(obj)) - return self - - -cout = OStream(sys.stdout) -END_L = '\n' - -# The following belongs to the SDK Process -streamManagerApi = StreamManagerApi() -# Init stream manager -ret = streamManagerApi.InitManager() -if ret != 0: - cout << 'Failed to init Stream manager, ret=' << str(ret) << END_L - exit() -# Create streams by pipeline config file -# load pipline -with open("../pipeline/burpee_detection_p.pipeline", 'rb') as f: - pipelineStr = f.read() -ret = streamManagerApi.CreateMultipleStreams(pipelineStr) -# Print error message -if ret != 0: - cout << 'Failed to create Stream, ret=' << str(ret) << END_L - exit() - -# 正常情况日志级别使用INFO,需要定位时可以修改为DEBUG,此时SDK会打印和服务端的通信信息 -logging.basicConfig(level=logging.INFO, stream=sys.stdout) - -# 设置用户属性, 包括 secret_id, secret_key, region等。App_id 已在CosConfig中移除,请在参数 Bucket 中带上 App_id。Bucket 由 BucketName-App_id 组成 -SECRET_ID = '' # 替换为用户的 SecretId,登录https://console.cloud.tencent.com/cam/capi查看 -SECRET_KEY = '' # 替换为用户的 SecretKey,登录https://console.cloud.tencent.com/cam/capi查看 -REGION = '' # 替换为用户的 region,已创建桶的region可在https://console.cloud.tencent.com/cos5/bucket查看 -# COS支持的所有region列表参见https://cloud.tencent.com/document/product/436/6224 -TOKEN = None # 如果使用永久密钥不需填入token,若使用临时密钥需填入,临时密钥生成和使用见https://cloud.tencent.com/document/product/436/14048 -SCHEME = 'https' # 指定使用 http/https 协议来访问 COS,默认为 https,可不填 - -CONFIG = CosConfig(Region=REGION, SecretId=SECRET_ID, - SecretKey=SECRET_KEY, Token=TOKEN, Scheme=SCHEME) -CLIENT = CosS3Client(CONFIG) - -IMG_NUM = 0 -ACTION = "" -ACTION_CNT = 0 -STATE = 0 -INPUT_COUNT = 0 -ERR_FILE = False -FPS = 1 -INPUT_PATH = "./input/" -RESULT_PATH = 'result.txt' - -# Release the input -if os.path.exists(INPUT_PATH): - shutil.rmtree(INPUT_PATH) - -while True: - - # Check the state of app - RESPONSE = CLIENT.list_objects(Bucket='', # 替换为用户的 Bucket - Prefix='state') - - if len(RESPONSE['Contents']) == 2: - IMG_NUM = 0 - ACTION_CNT = 0 - STATE = 0 - INPUT_COUNT = 0 - if os.path.exists(INPUT_PATH): - shutil.rmtree(INPUT_PATH) - continue - - # Check the number of input images - RESPONSE = CLIENT.list_objects(Bucket='', # 替换为用户的 Bucket - Prefix='input') - - if len(RESPONSE['Contents']) < IMG_NUM + 2: - cout << 'wait for inputs' << END_L - continue - # Check the target input image - RESPONSE = CLIENT.object_exists(Bucket='', # 替换为用户的 Bucket - Key='input/img' + str(IMG_NUM) + '.jpg') - - if not RESPONSE: - cout << 'no such file' << END_L - continue - - # Download the data of input - if os.path.exists(INPUT_PATH) != 1: - os.makedirs("./input/") - - RESPONSE = CLIENT.get_object(Bucket='', # 替换为用户的 Bucket - Key='input/img' + str(IMG_NUM) + '.jpg') - RESPONSE['Body'].get_stream_to_file('/input/img' + str(IMG_NUM) + '.jpg') - cout << 'Get the input successfully' << END_L - - # Input object of streams -- detection target - IMG_PATH = os.path.join(INPUT_PATH, 'img' + str(IMG_NUM) + '.jpg') - - DATA_INPUT = MxDataInput() - if os.path.exists(IMG_PATH) != 1: - cout << 'The image does not exist.' << END_L - - with open(IMG_PATH, 'rb') as f: - DATA_INPUT.data = f.read() - - STREAM_NAME = b'detection' - IN_PLUGIN_ID = 0 - # Send data to streams by SendDataWithUniqueId() - UNIQUEID = streamManagerApi.SendDataWithUniqueId(STREAM_NAME, IN_PLUGIN_ID, DATA_INPUT) - - if UNIQUEID < 0: - cout << 'Failed to send data to stream.' << END_L - exit() - - # Get results from streams by GetResultWithUniqueId() - INFER_RESULT = streamManagerApi.GetResultWithUniqueId(STREAM_NAME, UNIQUEID, 3000) - if INFER_RESULT.errorCode != 0: - cout << 'GetResultWithUniqueId error. errorCode=' << INFER_RESULT.errorCode \ - << ', errorMsg=' << INFER_RESULT.data.decode() << END_L - exit() - - # Get Object class - RESULTS = json.loads(INFER_RESULT.data.decode()) - IMG = cv2.imread(IMG_PATH) - IMG_NUM = IMG_NUM + 1 - - BEST_CONFIDENCE = 0 - KEY = "MxpiObject" - - if KEY not in RESULTS.keys(): - continue - - # Save the best confidence and its information - for BBOX in RESULTS['MxpiObject']: - if round(BBOX['classVec'][0]['confidence'], 4) >= BEST_CONFIDENCE: - ACTION = BBOX['classVec'][0]['className'] - BEST_CONFIDENCE = round(BBOX['classVec'][0]['confidence'], 4) - - # State change - if STATE == 0: - if ACTION == "crouch": - STATE = 1 - elif STATE == 1: - if ACTION == "support": - STATE = 2 - elif STATE == 2: - if ACTION == "crouch": - STATE = 3 - elif STATE == 3: - if ACTION == "jump": - STATE = 0 - ACTION_CNT = ACTION_CNT + 1 - - # Save txt for results - FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL - if os.path.exists(RESULT_PATH): - os.remove(RESULT_PATH) - with os.fdopen(os.open('result.txt', FLAGS, 0o755), 'w') as f: - f.write(str(ACTION_CNT)) - # Upload the result file - with open('result.txt', 'rb') as fp: - RESPONSE = CLIENT.put_object( - Bucket='', # 替换为用户的 Bucket - Body=fp, - Key='result/result.txt', - StorageClass='STANDARD', - EnableMD5=False - ) - cout << 'upload the result file successfully!!!' << END_L - -# Destroy All Streams -streamManagerApi.DestroyAllStreams() diff --git a/contrib/Burpee_Detection/App_burpee_detection/run.sh b/contrib/Burpee_Detection/App_burpee_detection/run.sh deleted file mode 100644 index fb4e528953f5e6b247a2ae8db986f832b35a00d8..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/App_burpee_detection/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -# load envs -source ../envs/env.sh - -# running inference process -python3.9.2 app_main.py diff --git a/contrib/Burpee_Detection/Pic_burpee_detection/map_calculate.py b/contrib/Burpee_Detection/Pic_burpee_detection/map_calculate.py deleted file mode 100644 index d28a6fbe1924e37128d264bd18aacde8fd3277a7..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/Pic_burpee_detection/map_calculate.py +++ /dev/null @@ -1,407 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -import glob -import os -import sys -import argparse -import collections - -""" - 0,0 ------> x (width) - | - | (Left,Top) - | *_________ - | | | - | | - y |_________| - (height) * - (Right,Bottom) -""" - -MIN_OVERLAP = 0.5 # default value (defined in the PASCAL VOC2012 challenge) -TOP_MARGIN = 0.15 # in percentage of the figure height -BOTTOM_MARGIN = 0.05 # in percentage of the figure height - - -def file_lines_to_list(path): - """ - Convert the lines of a file to a list - """ - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def voc_ap(recall, precision): - """ - Calculate the AP given the recall and precision array - 1) We calculate a version of the measured - precision/recall curve with precision monotonically decreasing - 2) We calculate the AP as the area - under this curve by numerical integration. - """ - """ - --- Official matlab code VOC2012--- - m_recall=[0 ; recall ; 1]; - m_precision=[0 ; precision ; 0]; - for j=numeral(m_precision)-1:-1:1 - m_precision(i)=max(m_precision(j),m_precision(j+1)); - end - i=find(m_recall(2:end)~=m_recall(1:end-1))+1; - ap=sum((m_recall(i)-m_recall(i-1)).*m_precision(i)); - """ - recall.insert(0, 0.0) # insert 0.0 at beginning of list - recall.append(1.0) # insert 1.0 at end of list - m_recall = recall[:] - precision.insert(0, 0.0) # insert 0.0 at beginning of list - precision.append(0.0) # insert 0.0 at end of list - m_precision = precision[:] - """ - This part makes the precision monotonically decreasing - (goes from the end to the beginning) - matlab: for i=numeral(m_precision)-1:-1:1 - m_precision(i)=max(m_precision(i),m_precision(i+1)); - """ - - for i in range(len(m_precision) - 2, -1, -1): - m_precision[i] = max(m_precision[i], m_precision[i + 1]) - """ - This part creates a list of indexes where the recall changes - matlab: i=find(m_recall(2:end)~=m_recall(1:end-1))+1; - """ - i_list = [] - for i in range(1, len(m_recall)): - if m_recall[i] != m_recall[i - 1]: - i_list.append(i) # if it was matlab would be i + 1 - """ - The Average Precision (AP) is the area under the curve - (numerical integration) - matlab: ap=sum((m_recall(i)-m_recall(i-1)).*m_precision(i)); - """ - ap = 0.0 - for i in i_list: - ap += ((m_recall[i] - m_recall[i - 1]) * m_precision[i]) - return ap, m_recall, m_precision - - -def is_float_between_0_and_1(value): - """ - check if the number is a float between 0.0 and 1.0 - """ - try: - val = float(value) - if 0.0 < val < 1.0: - return True - else: - return False - except ValueError: - return False - - -def error(msg): - """ - throw error and exit - """ - print(msg) - sys.exit(0) - - -def check_args(args): - """ - check arguments - """ - if not (os.path.exists(args.label_path)): - error("annotation file:{} does not exist.".format(args.label_path)) - - if not (os.path.exists(args.npu_txt_path)): - error("txt path:{} does not exist.".format(args.npu_txt_path)) - - if args.ignore is None: - args.ignore = [] - return args - - -def parse_line(txt_file, lines_list, bounding_boxes, counter_per_class, already_seen_classes): - """ parse line - :param txt_file: - :param lines_list: - :param bounding_boxes: - :param counter_per_class: - :param already_seen_classes: - :return: bounding_boxes, counter_per_class - """ - for line in lines_list: - try: - class_name, left, top, right, bottom = line.split() - except ValueError: - error_msg = "Error: File " + txt_file + " in the wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - if class_name in arg.ignore: - continue - bbox = left + " " + top + " " + right + " " + bottom - if class_name == '0': - class_name = 'crouch' - elif class_name == '1': - class_name = 'support' - elif class_name == '2': - class_name = 'jump' - bounding_boxes.append({"class_name": class_name, "bbox": bbox, "used": False}) - counter_per_class[class_name] += 1 - - if class_name not in already_seen_classes: - already_seen_classes.append(class_name) - return bounding_boxes, counter_per_class - - -def get_label_list(file_path): - """ get label list via file paths - :param file_path: label file path - :return: ret - map , include file_bbox, classes, n_classes, counter_per_class - """ - files_list = glob.glob(file_path + '/*.txt') - if len(files_list) == 0: - error("Error: No ground-truth files found!") - files_list.sort() - # dictionary with counter per class - counter_per_class = collections.defaultdict(int) - file_bbox = {} - - for txt_file in files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - # check if there is a correspondent detection-results file - temp_path = os.path.join(file_path, (file_id + ".txt")) - if not os.path.exists(temp_path): - error_msg = "Error. File not found: {}\n".format(temp_path) - error(error_msg) - lines_list = file_lines_to_list(txt_file) - # create ground-truth dictionary - bounding_boxes = [] - already_seen_classes = [] - boxes, counter_per_class = parse_line(txt_file, lines_list, bounding_boxes, counter_per_class, - already_seen_classes) - file_bbox[file_id] = boxes - - classes = list(counter_per_class.keys()) - - # let's sort the classes alphabetically - classes = sorted(classes) - n_classes = len(classes) - ret = dict() - ret['file_bbox'] = file_bbox - ret['classes'] = classes - ret['n_classes'] = n_classes - ret['counter_per_class'] = counter_per_class - return ret - - -def get_predict_list(file_path, gt_classes): - """ get predict list with file paths and class names - :param file_path: predict txt file path - :param gt_classes: class information - :return: class_bbox bbox of every class - """ - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - class_bbox = {} - for class_index, class_name in enumerate(gt_classes): - bounding_boxes = [] - for txt_file in dr_files_list: - # the first time it checks - # if all the corresponding ground-truth files exist - file_id = os.path.splitext(txt_file)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - tmp_class_name, confidence, left, top, right, bottom = sl - if float(confidence) < float(arg.threshold): - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - if tmp_class_name == class_name: - bbox = left + " " + top + " " + right + " " + bottom - bounding_boxes.append({"confidence": confidence, "file_id": file_id, "bbox": bbox}) - # sort detection-results by decreasing confidence - bounding_boxes.sort(key=lambda x: float(x['confidence']), reverse=True) - class_bbox[class_name] = bounding_boxes - return class_bbox - - -def calculate_pr(sum_ap, fp, tp, counter_per_class, class_name): - """ - @description: calculate PR - @param sum_ap - @param fp - @param tp - @param counter_per_class - @param class_name - @return ret - map, include sum_AP, text, prec, rec - """ - cumsum = 0 - for idx, val in enumerate(fp): - fp[idx] += cumsum - cumsum += val - cumsum = 0 - for idx, val in enumerate(tp): - tp[idx] += cumsum - cumsum += val - rec = tp[:] - for idx, val in enumerate(tp): - rec[idx] = float(tp[idx]) / counter_per_class[class_name] - prec = tp[:] - for idx, val in enumerate(tp): - prec[idx] = float(tp[idx]) / (fp[idx] + tp[idx]) - - ap, mrec, mprec = voc_ap(rec[:], prec[:]) - sum_ap += ap - text = "{0:.2f}%".format(ap * 100) + " = " + class_name + " AP " - ret = dict() - ret['sum_ap'] = sum_ap - ret['text'] = text - ret['p_rec'] = prec - ret['rec'] = rec - return ret - - -def calculate_ap(output_file, gt_classes, labels, class_bbox, counter_per_class): - """ - Calculate the AP for each class - :param output_file: - :param gt_classes: [80] - :param labels: {file_index:[{"class_name": class_name, "bbox": bbox, "used": False}]} - :param class_bbox: {class_name:[{"confidence": confidence, - "file_id": file_id, "bbox": bbox}]} - :param counter_per_class - :return: - """ - sum_ap = 0.0 - if os.path.exists(output_file): - os.remove(output_file) - flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL - writer = os.fdopen(os.open(output_file, flags, 0o755), 'w') - writer.write("# AP and precision/recall per class\n") - count_true_positives = {} - n_classes = len(gt_classes) - for class_index, class_name in enumerate(gt_classes): - count_true_positives[class_name] = 0 - """ - Load detection-results of that class - Assign detection-results to ground-truth objects - """ - dr_data = class_bbox[class_name] - nd = len(dr_data) - tp = [0] * nd # creates an array of zeros of size nd - fp = [0] * nd - for idx, detection in enumerate(dr_data): - file_id = detection["file_id"] - ground_truth_data = labels[file_id] - - ov_max = -1 - gt_match = -1 - # load detected object bounding-box - bb = [float(x) for x in detection["bbox"].split()] - for obj in ground_truth_data: - # look for a class_name match - if obj["class_name"] == class_name: - bbgt = [float(x) for x in obj["bbox"].split()] - bi = [max(bb[0], bbgt[0]), max(bb[1], bbgt[1]), - min(bb[2], bbgt[2]), min(bb[3], bbgt[3])] - iw = bi[2] - bi[0] + 1 - ih = bi[3] - bi[1] + 1 - if iw > 0 and ih > 0: - # compute overlap (IoU) - ua = (bb[2] - bb[0] + 1) * (bb[3] - bb[1] + 1) + \ - (bbgt[2] - bbgt[0] + 1) * \ - (bbgt[3] - bbgt[1] + 1) - iw * ih - ov = iw * ih / ua - if ov > ov_max: - ov_max = ov - gt_match = obj - - # set minimum overlap - min_overlap = MIN_OVERLAP - if ov_max >= min_overlap: - if "difficult" not in gt_match: - if not bool(gt_match["used"]): - # true positive - tp[idx] = 1 - gt_match["used"] = True - count_true_positives[class_name] += 1 - else: - # false positive (multiple detection) - fp[idx] = 1 - else: - # false positive - fp[idx] = 1 - # compute precision / recall - ret = calculate_pr(sum_ap, fp, tp, counter_per_class, class_name) - sum_ap = ret.get('sum_ap', "abc") - text = ret.get('text', "abc") - p_rec = ret.get('p_rec', "abc") - rec = ret.get('rec', "abc") - value = sum_ap and text and p_rec and rec - if value: - pass - else: - return - print(text) - rounded_p_rec = ['%.2f' % elem for elem in p_rec] - rounded_rec = ['%.2f' % elem for elem in rec] - writer.write(text + "\n Precision: " + str(rounded_p_rec) + - "\n Recall :" + str(rounded_rec) + "\n\n") - writer.write("\n# m_ap of all classes\n") - m_ap = sum_ap / n_classes - text = "m_ap = {0:.2f}%".format(m_ap * 100) - writer.write(text + "\n") - print(text) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mAP calculate') - parser.add_argument('-i', '--ignore', nargs='+', type=str, - help="ignore a list of classes.") - parser.add_argument('--label_path', default="../data/labels/test", help='the path of the label files') - parser.add_argument('--npu_txt_path', default="./result_test", help='the path of the predict result') - parser.add_argument('--output_file', default="./result.txt", help='save result file') - parser.add_argument('--threshold', default=0, help='threshold of the object score') - - arg = parser.parse_args() - arg = check_args(arg) - - label_list = get_label_list(arg.label_path) - gt_file_bbox = label_list.get('file_bbox', "abc") - get_classes = label_list.get('classes', "abc") - gt_n_classes = label_list.get('n_classes', "abc") - count_per_class = label_list.get('counter_per_class', "abc") - - key_value = gt_file_bbox and get_classes and gt_n_classes and count_per_class - if key_value: - predict_bbox = get_predict_list(arg.npu_txt_path, get_classes) - calculate_ap(arg.output_file, get_classes, gt_file_bbox, predict_bbox, count_per_class) - else: - print("no label exists") - diff --git a/contrib/Burpee_Detection/Pic_burpee_detection/pic_main.py b/contrib/Burpee_Detection/Pic_burpee_detection/pic_main.py deleted file mode 100644 index 5e40c17a5f5169b16961355ffb55ffe57847b0f0..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/Pic_burpee_detection/pic_main.py +++ /dev/null @@ -1,197 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -import shutil -import json -import os -import sys -import time -import cv2 - -import MxpiDataType_pb2 as MxpiDataType -from StreamManagerApi import StreamManagerApi, MxDataInput, StringVector - - -class OStream: - def __init__(self, file): - self.file = file - - def __lshift__(self, obj): - self.file.write(str(obj)) - return self - - -cout = OStream(sys.stdout) -END_L = '\n' - -# Init the directory of input and output -INPUT_PATH = [".././data/images/test/"] # the path of input - -OUTPUT_PATH = ["./result_test/"] # the output path of txt file - -OUTPUT_PIC_PATH = ["./result_test_pic/"] # the output path of pictures - -for path in INPUT_PATH: - if len(os.listdir(path)) == 0: - cout << 'The folder is empty:' << path << END_L - exit() - -# The following belongs to the SDK Process -streamManagerApi = StreamManagerApi() -# Init stream manager -ret = streamManagerApi.InitManager() -if ret != 0: - cout << 'Failed to init Stream manager, ret=' << str(ret) << END_L - exit() -# Mark start time -start = time.time() -# Create streams by pipeline config file -# Load pipline -with open(".././pipeline/burpee_detection_p.pipeline", 'rb') as f: - PIPELINE_STR = f.read() -ret = streamManagerApi.CreateMultipleStreams(PIPELINE_STR) -# Print error message -if ret != 0: - cout << 'Failed to create Stream, ret=' << str(ret) << END_L - exit() - -DET_IMG_COUNT = 0 # the number of detected pictures - - -for index, path in enumerate(INPUT_PATH): - - RESULT_PATH = OUTPUT_PATH[index] - - # Create the output directory - if os.path.exists(RESULT_PATH) != 1: - os.makedirs(RESULT_PATH) - else: - shutil.rmtree(RESULT_PATH) - os.makedirs(RESULT_PATH) - - if os.path.exists(OUTPUT_PIC_PATH[index]) != 1: - os.makedirs(OUTPUT_PIC_PATH[index]) - else: - shutil.rmtree(OUTPUT_PIC_PATH[index]) - os.makedirs(OUTPUT_PIC_PATH[index]) - - # Input object of streams -- detection target - for item in os.listdir(path): - IMG_PATH = os.path.join(path, item) - cout << 'read file path:' << IMG_PATH << END_L - IMG_NAME = os.path.splitext(item)[0] - IMG_TXT = RESULT_PATH + IMG_NAME + ".txt" - if os.path.exists(IMG_TXT): - os.remove(IMG_TXT) - DATA_INPUT = MxDataInput() - if os.path.exists(IMG_PATH) != 1: - cout << 'The image does not exist:' << IMG_PATH << END_L - continue - with open(IMG_PATH, 'rb') as f: - DATA_INPUT.data = f.read() - STREAM_NAME = b'detection' - IN_PLUGIN_ID = 0 - # Send data to streams by SendDataWithUniqueId() - UNIQUE_ID = streamManagerApi.SendDataWithUniqueId(STREAM_NAME, IN_PLUGIN_ID, DATA_INPUT) - - if UNIQUE_ID < 0: - cout << 'Failed to send data to stream.' << END_L - exit() - - # Get results from streams by GetResultWithUniqueId() - INFER_RESULT = streamManagerApi.GetResultWithUniqueId(STREAM_NAME, UNIQUE_ID, 3000) - if INFER_RESULT.errorCode != 0: - cout << 'GetResultWithUniqueId error. errorCode=' << INFER_RESULT.errorCode \ - << ', errorMsg=' << INFER_RESULT.data.decode() << END_L - exit() - - DET_IMG_COUNT = DET_IMG_COUNT + 1 - - # Get ObjectList - RESULTS = json.loads(INFER_RESULT.data.decode()) - - IMG = cv2.imread(IMG_PATH) - BBOXES = [] - best_class = {} - TEXT = "" - BEST_CONFIDENCE = 0 - KEY = "MxpiObject" - if KEY not in RESULTS.keys(): - continue - for BBOX in RESULTS['MxpiObject']: - BBOXES = {'x0': int(BBOX['x0']), - 'x1': int(BBOX['x1']), - 'y0': int(BBOX['y0']), - 'y1': int(BBOX['y1']), - 'confidence': round(BBOX['classVec'][0]['confidence'], 4), - 'text': BBOX['classVec'][0]['className']} - key_value = BBOXES.get('confidence', "abc") - if key_value: - pass - else: - continue - if key_value > BEST_CONFIDENCE: - L1 = [] - # Convert the label as Yolo label - x_center = round((BBOXES['x1'] + BBOXES['x0']) * 0.5 / IMG.shape[1], 6) - y_center = round((BBOXES['y1'] + BBOXES['y0']) * 0.5 / IMG.shape[0], 6) - w_nor = round((BBOXES['x1'] - BBOXES['x0']) / IMG.shape[1], 6) - h_nor = round((BBOXES['y1'] - BBOXES['y0']) / IMG.shape[0], 6) - L1.append(x_center) - L1.append(y_center) - L1.append(w_nor) - L1.append(h_nor) - L1.append(BBOXES['confidence']) - L1.append(BBOXES['text']) - BEST_CONFIDENCE = BBOXES['confidence'] - TEXT = "{}{}".format(str(BBOXES['confidence']), " ") - for CONTENT in BBOXES['text']: - TEXT += CONTENT - best_class = {'x0': int(BBOX['x0']), - 'x1': int(BBOX['x1']), - 'y0': int(BBOX['y0']), - 'y1': int(BBOX['y1']), - 'confidence': round(BBOX['classVec'][0]['confidence'], 4), - 'text': BBOX['classVec'][0]['className']} - # Draw rectangle and txt for visualization - key_value = (best_class.get('x0', "abc") and best_class.get('y0', "abc")) and \ - (best_class.get('x1', "abc") and best_class.get('y1', "abc")) - if key_value: - pass - else: - continue - cv2.putText(IMG, TEXT, (best_class['x0'] + 10, best_class['y0'] + 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0, - (0, 100, 255), 2) - cv2.rectangle(IMG, (best_class['x0'], best_class['y0']), (best_class['x1'], best_class['y1']), - (255, 0, 0), 2) - - # Save picture - originImgFile = OUTPUT_PIC_PATH[index] + IMG_NAME + '.jpg' - cv2.imwrite(originImgFile, IMG) - - # Save txt for results - FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL - with os.fdopen(os.open(IMG_TXT, FLAGS, 0o755), 'w') as f: - CONTENT = '{} {} {} {} {} {}'.format(L1[5], L1[4], L1[0], L1[1], L1[2], L1[3]) - f.write(CONTENT) - f.write('\n') - -end = time.time() -cost_time = end - start -# Mark spend time -cout << 'Image count:' << DET_IMG_COUNT << END_L -cout << 'Spend time:' << cost_time << END_L -cout << 'fps:' << (DET_IMG_COUNT / cost_time) << END_L -# Destroy All Streams -streamManagerApi.DestroyAllStreams() diff --git a/contrib/Burpee_Detection/Pic_burpee_detection/run.sh b/contrib/Burpee_Detection/Pic_burpee_detection/run.sh deleted file mode 100644 index 3812774fa07855781c70994c013cc2f52138cd62..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/Pic_burpee_detection/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -# load envs -source ../envs/env.sh - -# running inference process -python3.9.2 pic_main.py diff --git a/contrib/Burpee_Detection/README.md b/contrib/Burpee_Detection/README.md index c5acbd07016945b8c639d13592390ce4bf648a1f..eccaf8d070f2c7135951b26bce212f82de111707 100644 --- a/contrib/Burpee_Detection/README.md +++ b/contrib/Burpee_Detection/README.md @@ -1,264 +1,106 @@ -# 波比跳运动小程序 +# 波比跳运动检测 -## 1 介绍 +## 1、 介绍 -波比跳运动小程序基于 MindX SDK 开发,在 Ascend 310 芯片上进行目标检测,将检测结果保存成视频。项目主要流程: +### 1.1 简介 -1)视频流程:通过 live555 服务器进行拉流输入视频,然后进行视频解码将 H.264 格式的视频解码为图片,图片缩放后经过模型推理进行波比跳检测,识别结果经过后处理后利用 cv 可视化识别框,以视频的形式输出,同时生成文本文件记录视频中完成的波比跳个数。 +基于昇腾硬件和MindX SDK 实现波比跳运动检测,并将检测结果保存成视频。 +主要流程:通过 live555 服务器进行拉流输入视频,然后进行视频解码,将H.264格式的视频解码为图片,图片缩放后经过模型推理进行波比跳检测,识别结果经过后处理后利用 cv 可视化识别框,以视频的形式输出,同时生成文本文件记录视频中完成的波比跳个数。 -2)小程序流程:通过微信小程序开发者将摄像头截取的图片数据上传至腾讯云桶中,然后后端将桶中数据下载至本地并将数据输入至流水线内,接着进行图片解码和缩放,最后经过模型推理进行波比跳检测,识别结果经过后处理后上传至腾讯云桶中,为前端小程序使用。 +### 1.2 支持的产品 -### 1.1 支持的产品 +本项目支持昇腾Atlas 300I pro、 Atlas300V pro -昇腾 310(推理) +### 1.3 支持的版本 -### 1.2 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | -本样例配套的 CANN 版本为 [5.1.RC1](https://gitee.com/link?target=https%3A%2F%2Fwww.hiascend.com%2Fsoftware%2Fcann%2Fcommercial),MindX SDK 版本为 [3.0.RC3](https://www.hiascend.com/software/Mindx-sdk)。 +### 1.4 三方依赖 -MindX SDK 安装前准备可参考《用户指南》,[安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/quickStart/1-1安装SDK开发套件.md) - -### 1.3 软件方案介绍 - -基于 MindX SDK 的波比跳运动小程序业务流程为:通过微信小程序开发者将摄像头截取的图片数据上传至腾讯云桶中,然后后端将桶中数据下载至本地并经`mxpi_appsrc`拉流插件输入,然后使用图片解码插件`mxpi_imagedecoder`将图片解码,再通过图像缩放插件`mxpi_imageresize`将图像缩放至满足检测模型要求的输入图像大小要求,缩放后的图像输入模型推理插件`mxpi_modelinfer`得到检测结果,根据检测结果改变波比跳识别的状态机状态,并更新波比跳识别个数,最后上传记录波比跳识别个数的txt文件到腾讯云桶中,以供小程序使用。 +| 软件名称 | 版本 | +| ------------- | ---------------- | +| scipy | 1.13.1 | +| opencv-python | 4.10.0.84 | +| google | 3.0.0 | +| protobuf | 3.19.0 | +| numpy | 1.24.0 | +| live555 | 1.09 | 实现视频转rstp进行推流 | [链接](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/Live555%E7%A6%BB%E7%BA%BF%E8%A7%86%E9%A2%91%E8%BD%ACRTSP%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md) | ### 1.4 代码目录结构与说明 本 Sample 工程名称为 **Burpee_Detection**,工程目录如下图所示: ``` -├── envs -│   └── env.sh //基础环境变量与atc转换需要的环境变量 -├── readme_img //ReadMe图片资源 -│   ├── app_1.jpg -│   ├── app_2.jpg -│   ├── app_3.jpg -│   ├── app_4.jpg -│   ├── app_5.jpg -│   ├── dataset.jpg -│   ├── video.jpg -│   ├── app_flow.jpg -│   ├── video_flow.jpg -│   └── dark.jpg ├── model │   ├── atc.sh //atc运行脚本 ├── pipeline -│ ├── burpee_detection_p.pipeline //图片识别使用的pipeline文件 │   └── burpee_detection_v.pipeline //视频流识别使用的pipeline文件 -├── App_burpee_detection -│ ├── app_main.py //识别,保存结果,并进行性能测试 -| └── run.sh //运行脚本 -├── Pic_burpee_detection -│ ├── map_calculate.py //mAP计算(精度计算) -│ ├── pic_main.py //识别,保存结果,并进行性能测试 -| └── run.sh //运行脚本 ├── Video_burpee_detection │ ├── video_main.py //识别,保存结果,并进行性能测试 -| └── run.sh //运行脚本 └── README.md ``` -### 1.5 技术实现流程图 -视频识别: - -![video-flow](readme_img/video_flow.jpg) - -小程序应用后端流程: - -![app-flow](readme_img/app_flow.jpg) - -### 1.6 特性及使用场景举例 - - 该应用特色在于mindsdk与小程序的结合,其并不局限于波比跳的计数,该应用模式仍适用于其他实时图像识别类小程序功能的开发。 - 对于画面内单人,且光线正常的情况下小程序都能正常且精准的计数。在精度和性能上,该应用实现流程都超过了要求水平,但仍有一些场景,情况不适用: - -· 光线极暗的情况下,由于前端获取的数据的清晰度较低且mindsdk中图片解码插件只适用jpg,精度会大幅下降 -· mindsdk只存在rtsp拉流的插件,如若推流以视频形式在小程序与后端之间传输,需自行编写新的推流插件 -· 当画面人物为正对摄像头做波比跳时,会出现检测不到动作的情况,用户应侧对摄像头。正对很难判断动作是否标准。 - -## 2 环境依赖 - -| 软件名称 | 版本 | 说明 | 获取方式 | -|:-------------------:|:------------:|:---------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| -| MindX SDK | 3.0.RC3 | mxVision软件包 | [链接](https://www.hiascend.com/zh/software/mindx-sdk/mxVision/community) | -| ubuntu | 18.04.1 LTS | 操作系统 | Ubuntu官网获取 | -| Ascend-CANN-toolkit | 5.1.RC1 | Ascend-cann-toolkit开发套件包 | [链接](https://gitee.com/link?target=https%3A%2F%2Fwww.hiascend.com%2Fsoftware%2Fcann%2Fcommercial) | -| live555 | 1.09 | 实现视频转 rtsp 进行推流 | [链接](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/参考资料/Live555离线视频转RTSP说明文档.md) | -| ffmpeg | 2021-10-14 | 实现 mp4 格式视频转为 H.264 格式视频 | [链接](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/参考资料/pc端ffmpeg安装教程.md#https://gitee.com/link?target=https%3A%2F%2Fffmpeg.org%2Fdownload.html) | -| 微信开发者工具 | 1.06.2207210 | 实现小程序的使用 | [链接](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html) | -| 小程序导入代码 | - | 微信小程序代码 | [链接](https://burpee.obs.cn-east-3.myhuaweicloud.com:443/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81.zip?AccessKeyId=3M18UT7HRLKP58NPPFUO&Expires=1690270238&Signature=SHjFgSLUrGMPGbYNYyNgS3VmBMw%3D) | -| 腾讯桶内文件夹格式 | - | 压缩包解压后文件夹内文件形式即为桶内文件形式 | [链接](https://burpee.obs.cn-east-3.myhuaweicloud.com/%E6%A1%B6%E5%86%85%E6%96%87%E4%BB%B6.zip) | -| 对象储存 python sdk | - | 小程序相关python sdk快速入门 | [链接](https://cloud.tencent.com/document/product/436/12269) | -| 模型文件 | - | pt 模型文件,onnx 模型文件,om 模型文件,names文件,模型配置文件 | [链接](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/Burpee/models%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.zip) | - -在运行项目需要的环境变量如下,运行前不需要特别设置,环境依赖已经写入脚本中,脚本在`Burpee_Detection/envs`目录下: - - ```bash - export MX_SDK_path=""# mxVision 安装路径 - export Ascend_toolkit_path=""#CANN 安装路径 - - # MindXSDK 环境变量: - . /${MX_SDK_path}/set_env.sh - - # CANN 环境变量: - . /${Ascend_toolkit_path}/set_env.sh - ``` - -注:其中`${MX_SDK_path}`替换为用户的SDK安装路径;`Ascend_toolkit_path`替换为ascend-toolkit开发套件包所在路径。 - -## 3 模型转换以及依赖安装 +## 2、 设置环境变量 -本项目使用的模型是波比跳识别的模型。模型文件可以直接下载。(下载链接在第二小节) +在编译运行项目前,需要设置环境变量: -### 3.1 模型转换 - -使用模型转换工具 ATC 将 onnx 模型转换为 om 模型,模型转换工具相关介绍参考链接:[ATC模型转换工具指南](https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/tutorials/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99.md) 。 - -步骤如下: - -- **步骤1** 下载`onnx`模型,请移动至`Burpee_Detection/model`目录下;若下载`om`模型文件,请跳过模型转换步骤。(下载链接在第二小节) - -- **步骤2** 将`best.onnx`文件移动至`Burpee_Detection/model`目录下,然后运行model目录下的`atc.sh` - - ```bash - bash /model/atc.sh - ``` - - 执行该命令后会在当前文件夹下生成项目需要的模型文件 - - ``` - ATC start working now, please wait for a moment. - ATC run success, welcome to the next use. - ``` - - 表示命令执行成功。 - -### 3.2 准备 - -按照第3小节**软件依赖**安装 live555 和 ffmpeg,按照 [Live555离线视频转RTSP说明文档](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/参考资料/Live555离线视频转RTSP说明文档.md)将 mp4 视频转换为 H.264 格式。并将生成的 H.264 格式的视频上传到`live/mediaServer`目录下,然后修改`pipeline`目录下的`burpee_detection_v.pipeline`文件中`mxpi_rtspsrc0`的内容。 - -```json -"mxpi_rtspsrc0": { - "props": { - "rtspUrl":"rtsp://xxx.xxx.xxx.xxx:xxxx/xxx.264", // 修改为自己所使用的的服务器和文件名 - }, - "factory": "mxpi_rtspsrc", - "next": "mxpi_videodecoder0" -} +```bash +. /usr/local/Ascend/ascend-toolkit/set_env.sh #toolkit默认安装路径,根据实际安装路径修改 +. ${SDK_INSTALL_PATH}/mxVision/set_env.sh #sdk安装路径,根据实际安装路径修改 ``` -## 4 运行与测试 - -### 4.1 运行 +## 3、 准备模型 -#### 4.1.1 视频 +**步骤1**: onnx模型下载 -- **步骤1** 按照第 2 小节 **环境依赖** 中的步骤设置环境变量。 +[下载链接](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/Burpee/models%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.zip) -- **步骤2** 按照第 3 小节 **模型转换** 中的步骤获得 `om` 模型文件,放置在 `Burpee_Detection/models` 目录下。 +**步骤2**:模型转换 -- **步骤3** 修改`burpee_detection_v.pipeline`中`mxpi_modelinfer0`中`postProcessLibPath`的值`${MX_SDK_path}`为 MindX SDK 的安装路径 - -- **步骤4** 按照 3 小节 **准备** 中的步骤创建rtsp流以实现本地视频的rtsp拉流操作。 - -- **步骤5** 运行。在 `Burpee_Detection/Video_burpee_detection` 目录下执行命令: +将步骤1中下载的models.zpi压缩包放到项目目录的modle文件夹并解压。拷贝其中的burpee_detection.onnx,yolov5.cfg,yolov5.names文件到modle文件夹。执行以下命令: ```bash -bash run.sh +bash ./atc.sh ``` - -运行可视化结果会以`video_result.mp4`视频形式保存在`Burpee_Detection/Video_burpee_detection`目录下 -波比跳识别个数会以`result.txt`文件形式保存在`Burpee_Detection/Video_burpee_detection`目录下 - -![dataset](readme_img/video.jpg) - -#### 4.1.2 小程序 - -- **步骤1** 按照第 4 小节 **视频** 中的**步骤1**到**步骤3**搭建小程序后端环境。 -- **步骤2** 运行。在 `Burpee_Detection/App_burpee_detection` 目录下执行命令: - +执行完模型转换脚本后,会在model文件夹生成相应的burpee_detection.om模型文件: ```bash -bash run.sh +ATC start working now, please wait for a moment. +ATC run success, welcome to the next use. ``` -- **步骤3** 创建obs桶内文件夹和文件,如下所示 -``` -├── input //存放小程序获取数据 -├── result //存放后端处理的数据输出结果 -├── state //用于判断小程序状态(前端改写,后端查看) -├── state.txt //前端放入state文件夹的文件 -├── result.txt//存放后端处理的计数值 -``` -- **步骤4** 下载`微信开发者工具`并登录,在微信公众平台注册小程序并获取AppID - - -- ![app_1](readme_img/app_1.jpg) - - -- **步骤5** 点击导入,选择小程序代码文件夹并打开(代码可下载,下载链接在第二小节),点击编译模式选中`pages`目录下的子目录`bind`并选择`bind`,点击`详情-本地设置`,选中不效验合法域名后(可在小程序公众平台开发管理-开发设置中,配置合法域名),点击`真机调试`,然后用手机扫描二维码 +## 4、 运行 -- ![app_2](readme_img/app_2.jpg) - ![app_3](readme_img/app_3.jpg) - ![app_4](readme_img/app_4.jpg) +**步骤1**:安装live555并创建视频流。 +按照 [Live555离线视频转RTSP说明文档](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/参考资料/Live555离线视频转RTSP说明文档.md),使用h264视频创建rtsp视频流。 -- **步骤6** 进入微信小程序页面,点击`开始计数`,小程序将摄像头以40ms(fps=25)的速率拍摄照片,并上传至腾讯云桶内,后台接收图片并处理 -- -- ![app_5](readme_img/app_5.jpg) -- -- **步骤7** 人物在摄像头前进行波比跳,后台实时更新波比跳个数并将结果发送至桶内,小程序端以0.1s的速率刷新页面展示的个数 +**步骤2**:修改流程编排文件。 +进入pipeline文件夹, +把burpee_detection_v.pipeline文件中的流地址替换为实际的地址: -- **步骤8** 点击`结束`,小程序停止发送图像并清理上传至桶内的图片释放内存,后端等待小程序下次开始计数 - - - -### 4.2 性能与精度测试 - -- **步骤1** 准备测试数据集(数据集内应有数据以及对应的标签,格式为yolo),并将`data`文件夹放在`Burpee_Detection`目录下 - - ![dataset](readme_img/dataset.jpg) - -- **步骤2** 打开`Burpee_Detection/Pic_burpee_detection`目录下`pic_burpee_detection.py`文件,将变量 `INPUT_PATH` ,`OUTPUT_PATH` ,`OUTPUT_PIC_PATH`分别初始化为 `["../data/images/test/"]`,`[".././Pic_burpee_detection/result_test/"]`,`[".././Pic_burpee_detection/result_test_pic/"]` - - -- **步骤3** 在`Burpee_Detection/Pic_burpee_detection`目录下运行`run.sh`脚本,对`data/images/test`目录下的图片进行识别并输出结果 - - ```bash - bash run.sh - ``` +```bash +#第8行 "rtspUrl": "rtsp://xxx.xxx.x.x:xxxx/burpee_detection.264", +``` - 运行脚本后会生成经过 SDK 后的推理结果结果保留在`result_test`目录下以`.txt`格式保存。 - 结果可视化效果保留在`result_test_pic`目录下以`.jpg`格式保存 - 运行结果中会有`Spend time:`是识别所有图片所用的时间,`fps:`计算得到的帧数 -- - ```bash - Image count:237 - Spend time:5.785876989364624 - fps:40.961811050536376 - ``` +**步骤3**:运行检测程序。 +进入Video_burpee_detection文件夹,执行以下命令: +```bash +python3 video_main.py +``` +注意:检测程序不会自动停止,需要执行ctrl+c键盘命令停止程序。 -- **步骤4** 在`Burpee_Detection/Pic_burpee_detection`目录下运行`map_calculate.py`脚本,计算精度。 +**步骤3**:查看结果。 - ```bash - python3.9.2 map_calculate.py - ``` +- 运行可视化结果会以`video_result.mp4`视频形式保存在`Burpee_Detection/Video_burpee_detection`目录下。 - 测试结果 +- 波比跳识别个数会以`result.txt`文件形式保存在`Burpee_Detection/Video_burpee_detection`目录下。 - ```bash - 98.67% = crouch AP - 84.93% = jump AP - 94.91% = support AP - m_ap = 92.83% - ``` +- 检测过程中的帧图片会保存在`Burpee_Detection/Video_burpee_detection/result_pic`目录下。 -### 4.3 特殊情况测试 - 数据为光线较暗时(无光源的情况下)图片 - ![dataset](readme_img/dark.jpg) - 测试结果: - ```bash - No objects detected!!! - ``` - 当测试无目标时会有对应报错 \ No newline at end of file diff --git a/contrib/Burpee_Detection/Video_burpee_detection/run.sh b/contrib/Burpee_Detection/Video_burpee_detection/run.sh deleted file mode 100644 index 8b09c7eb9bea4b23abf5d4cd4b1c18f73bc0bdb3..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/Video_burpee_detection/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -# load envs -source ../envs/env.sh - -# running inference process -python3.9.2 video_main.py diff --git a/contrib/Burpee_Detection/Video_burpee_detection/video_main.py b/contrib/Burpee_Detection/Video_burpee_detection/video_main.py index 12a51b6b673d63c5d3533fb54787a6c3570338df..843a92ca7df9258a4f2a09f0340f18d5473fff29 100644 --- a/contrib/Burpee_Detection/Video_burpee_detection/video_main.py +++ b/contrib/Burpee_Detection/Video_burpee_detection/video_main.py @@ -64,125 +64,120 @@ ACTION_CNT = 0 fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter('video_result.mp4', fourcc, 30, (1280, 720)) -while True: - - # Get data through GetResult - infer_result = streamManagerApi.GetResult(STREAM_NAME, b'appsink0', keyVec) - - # Determine whether the output is empty - if infer_result.metadataVec.size() == 0: - cout << 'infer_result is null' << END_L - continue - - # Frame information structure - frameList = MxpiDataType.MxpiFrameInfo() - frameList.ParseFromString(infer_result.metadataVec[0].serializedMetadata) - - # Object postprocessor information - objectList = MxpiDataType.MxpiObjectList() - objectList.ParseFromString(infer_result.metadataVec[1].serializedMetadata) - - # Video-decoder information - visionList = MxpiDataType.MxpiVisionList() - visionList.ParseFromString(infer_result.metadataVec[2].serializedMetadata) - vision_data = visionList.visionVec[0].visionData.dataStr - visionInfo = visionList.visionVec[0].visionInfo - - # cv2 func YUV to BGR - YUV_BYTES_NU = 3 - YUV_BYTES_DE = 2 - img_yuv = np.frombuffer(vision_data, np.uint8) - # Reshape - img_bgr = img_yuv.reshape(visionInfo.heightAligned * YUV_BYTES_NU // YUV_BYTES_DE, - visionInfo.widthAligned) - # Color gamut conversion - img = cv2.cvtColor(img_bgr, getattr(cv2, "COLOR_YUV2BGR_NV12")) - - BEST_CONFIDENCE = 0 - TEXT = "" - best_bboxes = {} - - if len(objectList.objectVec) == 0: - continue - - for i in range(len(objectList.objectVec)): - # Get ObjectList - results = objectList.objectVec[i] - # Get the confidence - confidence = round(results.classVec[0].confidence, 4) - # Save the best confidence and its information - if confidence > BEST_CONFIDENCE: - BEST_CONFIDENCE = confidence - best_bboxes = {'x0': int(results.x0), - 'x1': int(results.x1), - 'y0': int(results.y0), - 'y1': int(results.y1), - 'text': results.classVec[0].className} - key_value = best_bboxes.get('text', "abc") - if key_value: - pass - else: - continue - action = key_value - TEXT = "{}{}".format(str(BEST_CONFIDENCE), " ") - - # Draw rectangle and txt for visualization - key_value = best_bboxes.get('text', "abc") - if key_value: - pass - else: - continue - for item in best_bboxes['text']: - TEXT += item - key_value = (best_bboxes.get('x0', "abc") and best_bboxes.get('y0', "abc")) and \ - (best_bboxes.get('x1', "abc") and best_bboxes.get('y1', "abc")) - if key_value: - pass - else: - continue - cv2.putText(img, TEXT, (best_bboxes['x0'] + 10, best_bboxes['y0'] + 10), - cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 0, 0), 1) - cv2.rectangle(img, (best_bboxes['x0'], best_bboxes['y0']), (best_bboxes['x1'], best_bboxes['y1']), - (255, 0, 0), 2) - - # State change - if STATE == 0: - if action == "crouch": - STATE = 1 - elif STATE == 1: - if action == "support": - STATE = 2 - elif STATE == 2: - if action == "crouch": - STATE = 3 - elif STATE == 3: - if action == "jump": - STATE = 0 - ACTION_CNT = ACTION_CNT + 1 - - # Save txt for results - FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL - if os.path.exists("result.txt"): - os.remove("result.txt") - with os.fdopen(os.open('result.txt', FLAGS, 0o755), 'w') as f: - f.write(str(ACTION_CNT)) - - # Save picture - Id = frameList.frameId - RESULT_PIC_PATH = "./result_pic/" - if os.path.exists(RESULT_PIC_PATH) != 1: - os.makedirs(RESULT_PIC_PATH) - ORIGIN_IMG_FILE = './result_pic/image' + '-' + str(Id) + '.jpg' - cv2.imwrite(ORIGIN_IMG_FILE, img) - - # Write the video - out.write(img) - - # Stop detection when it is the lase frame - # Or when the frame id comes to be the number you set - if frameList.isEos or Id > 63: - out.release() - break - -# Destroy All Streams -streamManagerApi.DestroyAllStreams() +try: + while True: + + # Get data through GetResult + infer_result = streamManagerApi.GetResult(STREAM_NAME, b'appsink0', keyVec) + + # Determine whether the output is empty + if infer_result.metadataVec.size() == 0: + cout << 'infer_result is null' << END_L + continue + + # Frame information structure + frameList = MxpiDataType.MxpiFrameInfo() + frameList.ParseFromString(infer_result.metadataVec[0].serializedMetadata) + + # Object postprocessor information + objectList = MxpiDataType.MxpiObjectList() + objectList.ParseFromString(infer_result.metadataVec[1].serializedMetadata) + + # Video-decoder information + visionList = MxpiDataType.MxpiVisionList() + visionList.ParseFromString(infer_result.metadataVec[2].serializedMetadata) + vision_data = visionList.visionVec[0].visionData.dataStr + visionInfo = visionList.visionVec[0].visionInfo + + # cv2 func YUV to BGR + YUV_BYTES_NU = 3 + YUV_BYTES_DE = 2 + img_yuv = np.frombuffer(vision_data, np.uint8) + # Reshape + img_bgr = img_yuv.reshape(visionInfo.heightAligned * YUV_BYTES_NU // YUV_BYTES_DE, + visionInfo.widthAligned) + # Color gamut conversion + img = cv2.cvtColor(img_bgr, getattr(cv2, "COLOR_YUV2BGR_NV12")) + + BEST_CONFIDENCE = 0 + TEXT = "" + best_bboxes = {} + + if len(objectList.objectVec) == 0: + continue + + for i in range(len(objectList.objectVec)): + # Get ObjectList + results = objectList.objectVec[i] + # Get the confidence + confidence = round(results.classVec[0].confidence, 4) + # Save the best confidence and its information + if confidence > BEST_CONFIDENCE: + BEST_CONFIDENCE = confidence + best_bboxes = {'x0': int(results.x0), + 'x1': int(results.x1), + 'y0': int(results.y0), + 'y1': int(results.y1), + 'text': results.classVec[0].className} + key_value = best_bboxes.get('text', "abc") + if key_value: + pass + else: + continue + action = key_value + TEXT = "{}{}".format(str(BEST_CONFIDENCE), " ") + + # Draw rectangle and txt for visualization + key_value = best_bboxes.get('text', "abc") + if key_value: + pass + else: + continue + for item in best_bboxes['text']: + TEXT += item + key_value = (best_bboxes.get('x0', "abc") and best_bboxes.get('y0', "abc")) and \ + (best_bboxes.get('x1', "abc") and best_bboxes.get('y1', "abc")) + if key_value: + pass + else: + continue + cv2.putText(img, TEXT, (best_bboxes['x0'] + 10, best_bboxes['y0'] + 10), + cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 0, 0), 1) + cv2.rectangle(img, (best_bboxes['x0'], best_bboxes['y0']), (best_bboxes['x1'], best_bboxes['y1']), + (255, 0, 0), 2) + + # State change + if STATE == 0: + if action == "crouch": + STATE = 1 + elif STATE == 1: + if action == "support": + STATE = 2 + elif STATE == 2: + if action == "crouch": + STATE = 3 + elif STATE == 3: + if action == "jump": + STATE = 0 + ACTION_CNT = ACTION_CNT + 1 + + # Save txt for results + FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL + if os.path.exists("result.txt"): + os.remove("result.txt") + with os.fdopen(os.open('result.txt', FLAGS, 0o755), 'w') as f: + f.write(str(ACTION_CNT)) + + # Save picture + Id = frameList.frameId + RESULT_PIC_PATH = "./result_pic/" + if os.path.exists(RESULT_PIC_PATH) != 1: + os.makedirs(RESULT_PIC_PATH) + ORIGIN_IMG_FILE = './result_pic/image' + '-' + str(Id) + '.jpg' + cv2.imwrite(ORIGIN_IMG_FILE, img) + + # Write the video + out.write(img) +except KeyboardInterrupt: + # Destroy All Streams + streamManagerApi.DestroyAllStreams() diff --git a/contrib/Burpee_Detection/envs/env.sh b/contrib/Burpee_Detection/envs/env.sh deleted file mode 100644 index bd0667ebf4f58665285170757dc0f73b7adf8448..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/envs/env.sh +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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 MX_SDK_path=""# mxVision 安装路径 -export Ascend_toolkit_path=""# CANN 安装路径 - -# MindXSDK 环境变量: -. /${MX_SDK_path}/set_env.sh - -# CANN 环境变量: -. /${Ascend_toolkit_path}/set_env.sh - diff --git a/contrib/Burpee_Detection/model/atc.sh b/contrib/Burpee_Detection/model/atc.sh index e7c23da8a7f3ef961b3af8e8f0ad16ca7d9f6345..38d4d5b4aa0c9bd9a32f216e4155491aef3e6614 100644 --- a/contrib/Burpee_Detection/model/atc.sh +++ b/contrib/Burpee_Detection/model/atc.sh @@ -1,21 +1,3 @@ -# Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -# atc environment -source ../envs/env.sh - -# atc transform model atc \ --model=./burpee_detection.onnx \ --framework=5 \ @@ -25,6 +7,6 @@ atc \ --out_nodes="Transpose_213:0;Transpose_262:0;Transpose_311:0" \ --enable_small_channel=1 \ --insert_op_conf=./aipp_yolov5.cfg \ - --soc_version=Ascend310 \ + --soc_version=Ascend310P3 \ --log=info diff --git a/contrib/Burpee_Detection/pipeline/burpee_detection_p.pipeline b/contrib/Burpee_Detection/pipeline/burpee_detection_p.pipeline deleted file mode 100644 index b4d8910bb150255c0dca7057a4b2b8d24b6a9eec..0000000000000000000000000000000000000000 --- a/contrib/Burpee_Detection/pipeline/burpee_detection_p.pipeline +++ /dev/null @@ -1,54 +0,0 @@ -{ - "detection": { - "stream_config": { - "deviceId": "0" - }, - "appsrc0": { - "props": { - "blocksize": "409600" - }, - "factory": "appsrc", - "next": "mxpi_imagedecoder0" - }, - "mxpi_imagedecoder0": { - "props": { - "deviceId": "0" - }, - "factory": "mxpi_imagedecoder", - "next": "mxpi_imageresize0" - }, - "mxpi_imageresize0": { - "props": { - "dataSource": "mxpi_imagedecoder0", - "resizeHeight": "640", - "resizeWidth": "640", - "resizeType": "Resizer_KeepAspectRatio_Fit" - }, - "factory": "mxpi_imageresize", - "next": "mxpi_modelinfer0" - }, - "mxpi_modelinfer0": { - "props": { - "modelPath": ".././model/burpee_detection.om", - "postProcessConfigPath": ".././model/yolov5.cfg", - "labelPath": ".././model/yolov5.names", - "postProcessLibPath": "../.././Ascend/mindx_sdk/mxVision-2.0.4/lib/libMpYOLOv5PostProcessor.so" - }, - "factory": "mxpi_modelinfer", - "next": "mxpi_dataserialize0" - }, - "mxpi_dataserialize0": { - "props": { - "outputDataKeys": "mxpi_modelinfer0" - }, - "factory": "mxpi_dataserialize", - "next": "appsink0" - }, - "appsink0": { - "props": { - "blocksize": "4096000" - }, - "factory": "appsink" - } - } -} diff --git a/contrib/Burpee_Detection/pipeline/burpee_detection_v.pipeline b/contrib/Burpee_Detection/pipeline/burpee_detection_v.pipeline index a73612c3442218bfd83e51f896fd98280ef29f39..549de9836b00323f24587e342061700c60fd3eab 100644 --- a/contrib/Burpee_Detection/pipeline/burpee_detection_v.pipeline +++ b/contrib/Burpee_Detection/pipeline/burpee_detection_v.pipeline @@ -33,10 +33,10 @@ "mxpi_modelinfer0": { "props": { "dataSource": "mxpi_imageresize0", - "modelPath": ".././model/burpee_detection.om", - "postProcessConfigPath": ".././model/yolov5.cfg", - "labelPath": ".././model/yolov5.names", - "postProcessLibPath": "../.././Ascend/mindx_sdk/mxVision-2.0.4/lib/libMpYOLOv5PostProcessor.so", + "modelPath": "../model/burpee_detection.om", + "postProcessConfigPath": "../model/yolov5.cfg", + "labelPath": "../model/yolov5.names", + "postProcessLibPath": "libMpYOLOv5PostProcessor.so", "deviceId": "0" }, "factory": "mxpi_modelinfer", diff --git a/contrib/Burpee_Detection/readme_img/app_1.jpg b/contrib/Burpee_Detection/readme_img/app_1.jpg deleted file mode 100644 index 9d56cc7976396199691287c08c01c476492d27e3..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_1.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/app_2.jpg b/contrib/Burpee_Detection/readme_img/app_2.jpg deleted file mode 100644 index f67c0c31a0d3960c5ba6c61e707eb5dd88d8fe1c..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_2.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/app_3.jpg b/contrib/Burpee_Detection/readme_img/app_3.jpg deleted file mode 100644 index 47980330bc16184f356724d8cb4bd17cc35e0a48..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_3.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/app_4.jpg b/contrib/Burpee_Detection/readme_img/app_4.jpg deleted file mode 100644 index 2aa4851813a254e5fe5043264939a65a4c5db368..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_4.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/app_5.jpg b/contrib/Burpee_Detection/readme_img/app_5.jpg deleted file mode 100644 index 7d80b6fd43bf17aa6e103d6e83961186fa38bc0b..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_5.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/app_flow.jpg b/contrib/Burpee_Detection/readme_img/app_flow.jpg deleted file mode 100644 index 4a81113f7dc164f1009a26d216b042b6210012ae..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/app_flow.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/dark.jpg b/contrib/Burpee_Detection/readme_img/dark.jpg deleted file mode 100644 index c07a7ffb0dae6956ae23cf83cce91b2d9fe905e2..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/dark.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/dataset.jpg b/contrib/Burpee_Detection/readme_img/dataset.jpg deleted file mode 100644 index e0d64809eee663dc6e04126da46578b061a394c6..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/dataset.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/video.jpg b/contrib/Burpee_Detection/readme_img/video.jpg deleted file mode 100644 index c3c07c23babd4859fad6418583d7ab55c2c3e552..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/video.jpg and /dev/null differ diff --git a/contrib/Burpee_Detection/readme_img/video_flow.jpg b/contrib/Burpee_Detection/readme_img/video_flow.jpg deleted file mode 100644 index 49365d320111ee4a58296c4ff3483d9ab5c74961..0000000000000000000000000000000000000000 Binary files a/contrib/Burpee_Detection/readme_img/video_flow.jpg and /dev/null differ diff --git a/contrib/CamouflagedObjectDetection/README.md b/contrib/CamouflagedObjectDetection/README.md index 9497ea82c88f52b64921e9d2d112c3cf5b881ad4..69fc5a1392333554ba278ef916277939479cf61d 100644 --- a/contrib/CamouflagedObjectDetection/README.md +++ b/contrib/CamouflagedObjectDetection/README.md @@ -55,17 +55,17 @@ ### 3.1 模型获取 -**步骤1** +**步骤1**:下载DGNet (Efficient-B4) 的ONNX模型 -下载DGNet (Efficient-B4) 的ONNX模型:[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/snapshots/DGNet.zip) +[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/snapshots/DGNet.zip) ### 3.2 模型转换 -**步骤1** +**步骤1**:准备文件 在项目目录./CamouflagedObjectDetection下创建models文件夹,将上一小节下载的模型文件解压后,把其中的DGNet.onnx模型文件拷贝至models文件夹 -**步骤2** +**步骤2**:执行转换命令 在模型所在的文件夹执行以下命令 @@ -85,27 +85,24 @@ ATC run success, welcome to the next use. ## 4、 运行 -步骤如下: -**步骤1** +**步骤1**:数据集下载 下载测试数据集并放到项目文件夹./CamouflagedObjectDetection:[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/snapshots/data.tar) -**步骤2** - 执行以下命令将下载后的文件解压缩 ```bash tar -xf data.tar ``` -**步骤3** +**步骤2**:创建项目输出文件夹 执行以下命令创建项目输出文件夹 ```bash mkdir result ``` -**步骤4** +**步骤4**:运行 执行离线推理Python脚本 ```bash @@ -114,9 +111,9 @@ python3 inference_om.py --om_path ./models/DGNet.om --save_path ./result/ --data **注意:由于数据集图片较多,推理时间较长,可选择性输入部分图片来进行推理验证** -**步骤5** +**步骤5**:查看结果 -查看结果 + 推理完成的输出图片在result文件夹中 输入输出如下两图所示 diff --git a/contrib/IAT/README.md b/contrib/IAT/README.md index f4d81a6f9cc66e42d8f153a55e0c9fff6d5fd4c0..231c368b20da287cbf23f1ef252f733b2188fdb0 100644 --- a/contrib/IAT/README.md +++ b/contrib/IAT/README.md @@ -38,13 +38,13 @@ ## 3、 准备模型 -**步骤1** +**步骤1**:模型文件下载 原始pth模型源码[地址](https://github.com/cuiziteng/illumination-adaptive-transformer) 本文提供已从pth模型转换好的onnx模型直接使用:[IAT_lol-sim.onnx](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/IAT/IAT_lol-sim.onnx) 下载后放到项目根目录的models文件夹下。 -**步骤2** +**步骤2**:模型转换 将模型转换为om模型,在models文件夹下,执行以下命令生成om模型: ``` @@ -59,22 +59,20 @@ ATC run success, welcome to the next use. ## 4、 运行 -**步骤1** - -将要推理的test.png图片放到本项目./data/文件夹下,执行以下命令: +**步骤1**:将要推理的test.png图片放到本项目./data/文件夹下,执行以下命令: ``` python3 main.py ``` -**步骤2** +**步骤2**:查看结果 -查看结果:运行命令后即可在./data/文件夹下得到推理后的结果result.png文件。 +运行命令后即可在./data/文件夹下得到推理后的结果result.png文件。 ## 5、 精度验证 -**步骤1** +**步骤1**:数据集下载 下载LOLv1数据集,在[论文地址](https://daooshee.github.io/BMVC2018website/)Download Links章节下载LOL数据集。 将数据集解压后,把其中的测试集目录(eval15)和文件放到本项目./data/文件夹下,如下图所示: @@ -91,7 +89,7 @@ python3 main.py ├──... ``` -**步骤2** +**步骤2**:运行 切换到项目根目录下,将main.py中的主函数改为调用test_precision(),修改如下: @@ -104,9 +102,8 @@ python3 main.py python3 main.py ``` -**步骤3** +**步骤3**:查看结果 -查看结果: 运行后可得到精度测试结果,屏幕输出类似如下信息: ``` diff --git a/contrib/TSM/README.md b/contrib/TSM/README.md index cc897719e9c3bd2f087929e50ac67288dbae066f..a5c5a395575329cf625c46c4ddd16fce57dd64f2 100644 --- a/contrib/TSM/README.md +++ b/contrib/TSM/README.md @@ -54,14 +54,14 @@ ## 2、 设置环境变量 -**步骤1** 设置CANN和mxVision相关环境变量 +**步骤1**:设置CANN和mxVision相关环境变量 ```bash . /usr/local/Ascend/ascend-toolkit/set_env.sh #toolkit默认安装路径,根据实际安装路径修改 . ${SDK_INSTALL_PATH}/mxVision/set_env.sh #sdk安装路径,根据实际安装路径修改 ``` -**步骤2** 安装并设置ffmpeg相关环境变量 +**步骤2**:安装并设置ffmpeg相关环境变量 下载[ffmpeg](https://github.com/FFmpeg/FFmpeg/archive/n4.2.1.tar.gz),解压进入并执行以下命令安装: @@ -80,10 +80,13 @@ export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH ## 3、 准备模型 -**步骤1** -下载[模型](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/TSM/offline_models.zip) TSM.onnx, 将下载好压缩包解压并把模型放在“${TSM代码根目录}/model”目录下。 +**步骤1**:模型文件下载 + +TSM.onnx模型[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/TSM/offline_models.zip) , 将下载好压缩包解压并把模型放在“${TSM代码根目录}/model”目录下。 + +**步骤2**:模型转换 + -**步骤2** 将模型转换为om模型,在“model”目录下,执行以下命令生成om模型 ```shell @@ -93,8 +96,7 @@ bash onnx2om.sh ## 4、 运行 -**步骤1** -Kinetics-400数据集下载 +**步骤1**:Kinetics-400数据集下载 参考[Kinetics-400 数据准备](https://github.com/PaddlePaddle/PaddleVideo/blob/develop/docs/zh-CN/dataset/k400.md#%E4%B8%8B%E8%BD%BDvideo%E6%95%B0%E6%8D%AE)中的脚本下载操作,下载验证集链接列表文件val_link.list并编写下载脚本download.sh。放在代码根目录的"download_data"目录下。 @@ -129,7 +131,7 @@ bash k400_extractor.sh ├── zumba ``` -**步骤2** 数据集预处理 +**步骤2**:数据集预处理 1、视频抽帧 @@ -198,7 +200,7 @@ python3 vid2img_kinetics.py ../data ../dataset/ python3 gen_label_kinetics.py ``` -**步骤3** 运行精度测试 +**步骤3**:运行精度测试 修改${TSM代码根目录}/ops/dataset_config.py 脚本中参数root_data、filename_imglist_train和filename_imglist_val,若仅进行离线精度测试则可忽略filename_imglist_train设置。