diff --git a/Bank_second_part/xbank_detect_process/.vscode/launch.json b/Bank_second_part/xbank_detect_process/.vscode/launch.json new file mode 100644 index 0000000..d2d8eac --- /dev/null +++ b/Bank_second_part/xbank_detect_process/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "cwd": "${fileDirname}", + "justMyCode": true, + "purpose": ["debug-in-terminal"], + } + ] +} \ No newline at end of file diff --git a/Bank_second_part/xbank_detect_process/.vscode/settings.json b/Bank_second_part/xbank_detect_process/.vscode/settings.json new file mode 100644 index 0000000..58e008a --- /dev/null +++ b/Bank_second_part/xbank_detect_process/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "cSpell.words": [ + "fastdeploy", + "imread", + "imshow", + "rtsp", + "yolov" + ], + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-310.pyc deleted file mode 100644 index ec83fdb..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-38.pyc deleted file mode 100644 index 94c4516..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/config_load.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-310.pyc deleted file mode 100644 index 558768f..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-38.pyc deleted file mode 100644 index e36d261..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_dir_file.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-310.pyc deleted file mode 100644 index e150cfe..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-38.pyc deleted file mode 100644 index bb716d1..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_load.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-310.pyc deleted file mode 100644 index 90a5f4c..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-38.pyc deleted file mode 100644 index 30a50a4..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_data/__pycache__/data_rtsp.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_data/config_load.py b/Bank_second_part/xbank_detect_process/analysis_data/config_load.py index dcc6737..b1089bd 100644 --- a/Bank_second_part/xbank_detect_process/analysis_data/config_load.py +++ b/Bank_second_part/xbank_detect_process/analysis_data/config_load.py @@ -1,7 +1,7 @@ import yaml from pathlib import Path -def get_configs(ymal_files): - yaml_path = Path(__file__).parent / ymal_files +def get_configs(yaml_files): + yaml_path = Path(__file__).parent.parent / yaml_files with yaml_path.open("r", encoding="utf-8") as f: return yaml.load(f, Loader=yaml.FullLoader) \ No newline at end of file diff --git a/Bank_second_part/xbank_detect_process/analysis_data/data_rtsp.py b/Bank_second_part/xbank_detect_process/analysis_data/data_rtsp.py deleted file mode 100644 index 8bf1c8c..0000000 --- a/Bank_second_part/xbank_detect_process/analysis_data/data_rtsp.py +++ /dev/null @@ -1,9 +0,0 @@ - - -def rtsp_para(scource): - - if scource.split('://')[0] == 'rtsp': - return True - else: - return False - diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-310.pyc deleted file mode 100644 index 6de70cf..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-311.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-311.pyc deleted file mode 100644 index 18ee408..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-311.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-38.pyc deleted file mode 100644 index 5ac50d5..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/get_model_result.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-310.pyc deleted file mode 100644 index 7d217d1..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-311.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-311.pyc deleted file mode 100644 index 98e977d..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-311.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-38.pyc deleted file mode 100644 index 240cfef..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/same_model_img.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-310.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-310.pyc deleted file mode 100644 index dd18cf5..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-311.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-311.pyc deleted file mode 100644 index b899f83..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-311.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-38.pyc b/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-38.pyc deleted file mode 100644 index 7171fde..0000000 Binary files a/Bank_second_part/xbank_detect_process/analysis_result/__pycache__/tools_analysis.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/analysis_result/get_model_result.py b/Bank_second_part/xbank_detect_process/analysis_result/get_model_result.py index d763d2a..93976ca 100644 --- a/Bank_second_part/xbank_detect_process/analysis_result/get_model_result.py +++ b/Bank_second_part/xbank_detect_process/analysis_result/get_model_result.py @@ -2,6 +2,8 @@ def det_img(model_inference,images_frame,confidence,label_name_list): + assert images_frame is not None + result = model_inference.predict(images_frame) bbox_list = result.boxes diff --git a/Bank_second_part/xbank_detect_process/config_det.yaml b/Bank_second_part/xbank_detect_process/config_det.yaml index e973387..fe0a64b 100644 --- a/Bank_second_part/xbank_detect_process/config_det.yaml +++ b/Bank_second_part/xbank_detect_process/config_det.yaml @@ -1,18 +1,18 @@ detect_0: - source : rtsp://admin:@192.168.10.18 - model: /home/yaxin/xbank/xbank_poc_test/config_phone.yaml + source : /home/tp/taojx/xbank_test_videos/0711-1/0711-1_10.avi + model: ./config_phone.yaml -detect_1: - source : rtsp://admin:@192.168.10.12 - model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml +# detect_1: +# source : rtsp://admin:@192.168.10.12 +# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml -detect_2: - source : rtsp://admin:@192.168.10.18 - model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml +# detect_2: +# source : rtsp://admin:@192.168.10.18 +# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml -detect_3: - source : rtsp://admin:@192.168.10.11 - model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml +# detect_3: +# source : rtsp://admin:@192.168.10.11 +# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml # detect_4: # source : rtsp://admin:@192.168.10.11 diff --git a/Bank_second_part/xbank_detect_process/config_phone.yaml b/Bank_second_part/xbank_detect_process/config_phone.yaml index 2340545..e7b383d 100644 --- a/Bank_second_part/xbank_detect_process/config_phone.yaml +++ b/Bank_second_part/xbank_detect_process/config_phone.yaml @@ -1,6 +1,6 @@ # load model file -model: /home/yaxin/xbank/xbank_poc_test/model_file/yolov5.onnx -model_cache: /home/yaxin/xbank/xbank_poc_test/tensort_cache/yolov5.trt +model: ./model_file/yolov5.onnx +model_cache: ./tensort_cache/yolov5.trt # label and bbox message set model_parameter: @@ -11,7 +11,7 @@ model_parameter: relevancy_para : 0 confidence : 0.2 -save_path : /home/yaxin/xbank/xbank_poc_test/save_path/hands +save_path : ./save_path/hands # save_path_original : /home/yaxin/xbank/xbank_poc_test/save_path_original/hands # test_path : /home/yaxin/xbank/xbank_poc_test/test_save_path/hands save_path_original : False diff --git a/Bank_second_part/xbank_detect_process/config_sleep.yaml b/Bank_second_part/xbank_detect_process/config_sleep.yaml index 5010c56..023a921 100644 --- a/Bank_second_part/xbank_detect_process/config_sleep.yaml +++ b/Bank_second_part/xbank_detect_process/config_sleep.yaml @@ -1,6 +1,6 @@ # load model file -model: /home/yaxin/xbank/xbank_poc_test/model_file/yolov8.onnx -model_cache: /home/yaxin/xbank/xbank_poc_test/tensort_cache/yolov8.trt +model: ./model_file/yolov8.onnx +model_cache: ./tensort_cache/yolov8.trt # label and bbox message set model_parameter: @@ -11,7 +11,7 @@ model_parameter: relevancy_para : False confidence : 0.2 -save_path : /home/yaxin/xbank/xbank_poc_test/save_path/sleep +save_path : ./save_path/sleep # save_path_original : /home/yaxin/xbank/xbank_poc_test/save_path_original/sleep # test_path : /home/yaxin/xbank/xbank_poc_test/test_save_path/sleep save_path_original : False diff --git a/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-310.pyc b/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-310.pyc deleted file mode 100644 index 8f91a70..0000000 Binary files a/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-38.pyc b/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-38.pyc deleted file mode 100644 index 8404379..0000000 Binary files a/Bank_second_part/xbank_detect_process/drawing_img/__pycache__/drawing_img.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/main.py b/Bank_second_part/xbank_detect_process/main.py index 96ca808..7b5d61c 100644 --- a/Bank_second_part/xbank_detect_process/main.py +++ b/Bank_second_part/xbank_detect_process/main.py @@ -1,9 +1,6 @@ #coding: utf-8 from main_process import data_load -import multiprocessing from analysis_data.config_load import get_configs -from model_load.model_load import Load_model -import time from multiprocessing import Pool @@ -25,12 +22,14 @@ def get_args_list(args_data): if __name__ == "__main__": # 加载配置文件 - args = '/home/yaxin/xbank/xbank_poc_test/config_det.yaml' - args_data = get_configs(ymal_files=args) + args = './config_det.yaml' + args_data = get_configs(yaml_files=args) args_list = get_args_list(args_data) process_num = len(args_list) + print(f"args_list:{args_list}") + with Pool(process_num) as pool: pool.map(data_load, args_list) diff --git a/Bank_second_part/xbank_detect_process/main_process.py b/Bank_second_part/xbank_detect_process/main_process.py index 096c08d..cf72b0b 100644 --- a/Bank_second_part/xbank_detect_process/main_process.py +++ b/Bank_second_part/xbank_detect_process/main_process.py @@ -1,16 +1,13 @@ from analysis_result.get_model_result import det_img from analysis_result.same_model_img import same_model_img_analysis_labels, model_labels_selet -from model_load.model_load import Load_model +from model_load.model_load import load_model from drawing_img.drawing_img import drawing_frame -from analysis_data.data_rtsp import rtsp_para -from analysis_data.data_dir_file import get_dir_file, get_imgframe -from analysis_data.data_load import data_load +from analysis_data.data_dir_file import get_dir_file from analysis_data.config_load import get_configs +from utils import is_image_file, is_rtsp_or_video -import yaml import cv2 import os -from pathlib import Path import time from datetime import datetime @@ -20,20 +17,20 @@ def data_load(args): # print('正在运行的进程',msg) # print(args) source = args[0] - model_ymal = args[1] + model_yaml = args[1] # 数据加载 - rtsp_source = rtsp_para(source) + rtsp_or_video_source = is_rtsp_or_video(source) dir_source = os.path.isdir(source) - file_source = os.path.isfile(source) + img_source = is_image_file(source) # # 模型加载 - model_data = get_configs(model_ymal) - model_inference = Load_model(model_file=model_data["model"], + model_data = get_configs(model_yaml) + model_inference = load_model(model_file=model_data["model"], device=model_data["model_parameter"]['device'], cache_file=model_data["model_cache"]) - if rtsp_source: + if rtsp_or_video_source: cap = cv2.VideoCapture(source) @@ -49,15 +46,11 @@ def data_load(args): # cv2.imshow('18',frame) - t1 = time.time() - imgframe_dict = {"path": source, 'frame': frame} + img_frame_dict = {"path": source, 'frame': frame} images_update = img_process( - imgframe_dict, model_inference, model_data) + img_frame_dict, model_inference, model_data) # print(type(images_update['frame'])) - t2 = time.time() - tx = t2 - t1 - print('检测一张图片的时间为:',tx) # if source == 'rtsp://admin:@192.168.10.18': # cv2.namedWindow('18',0) @@ -87,10 +80,10 @@ def data_load(args): t1 = time.time() images = cv2.imread(img) - imgframe_dict = {"path": img, 'frame': images} + img_frame_dict = {"path": img, 'frame': images} images_update = img_process( - imgframe_dict, model_inference, model_data) + img_frame_dict, model_inference, model_data) t2 = time.time() tx = t2 - t1 @@ -101,21 +94,22 @@ def data_load(args): pass - if file_source: + if img_source: img_para = True if img_para: images = cv2.imread(source) - imgframe_dict = {"path": source, 'frame': images} + img_frame_dict = {"path": source, 'frame': images} images_update = img_process( - imgframe_dict, model_inference, model_data) + img_frame_dict, model_inference, model_data) def img_process(images, model_inference, model_data): - # t1 = time.time() + start_point = time.perf_counter() + # 检测每帧图片,返回推理结果 results = det_img(model_inference=model_inference, images_frame=images['frame'], @@ -149,10 +143,10 @@ def img_process(images, model_inference, model_data): images.update({"frame": img_save}) - imgname = images_save( + img_name = images_save( images=images['frame'], save_path=model_data["save_path"]) - print('sleep:', images['path'], imgname) + print('sleep:', images['path'], img_name) if model_data['save_path_original']: images_save(images=images['frame'], @@ -162,9 +156,9 @@ def img_process(images, model_inference, model_data): else: # 没检测出来的图片是否保存 if model_data["test_path"]: - imgname = images_save( + img_name = images_save( images=images['frame'], save_path=model_data["test_path"]) - # print('no:',images['path'],imgname) + # print('no:',images['path'],img_name) else: pass @@ -178,6 +172,11 @@ def img_process(images, model_inference, model_data): # t2 = time.time() + end_point = time.perf_counter() + cost = end_point - start_point + + print(f"Predicted in {cost * 1000:.2f}ms. {1.0 / cost:.2f} FPS") + return images diff --git a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-310.pyc b/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-310.pyc deleted file mode 100644 index 103ad3b..0000000 Binary files a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-310.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-311.pyc b/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-311.pyc deleted file mode 100644 index cd306a7..0000000 Binary files a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-311.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-38.pyc b/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-38.pyc deleted file mode 100644 index 37e468f..0000000 Binary files a/Bank_second_part/xbank_detect_process/model_load/__pycache__/model_load.cpython-38.pyc and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/model_load/model_load.py b/Bank_second_part/xbank_detect_process/model_load/model_load.py index d9a60e4..1b09eb5 100644 --- a/Bank_second_part/xbank_detect_process/model_load/model_load.py +++ b/Bank_second_part/xbank_detect_process/model_load/model_load.py @@ -19,7 +19,7 @@ def build_option(device, backend, cache_file): return option -def Load_model(model_file, device, cache_file): +def load_model(model_file, device, cache_file): """ 加载模型的tensorRT引擎 model_file:模型权重 格式:".onnx" diff --git a/Bank_second_part/xbank_detect_process/tensort_cache/yolov5.trt b/Bank_second_part/xbank_detect_process/tensort_cache/yolov5.trt deleted file mode 100644 index 0c72967..0000000 Binary files a/Bank_second_part/xbank_detect_process/tensort_cache/yolov5.trt and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/tensort_cache/yolov8.trt b/Bank_second_part/xbank_detect_process/tensort_cache/yolov8.trt deleted file mode 100644 index a01c384..0000000 Binary files a/Bank_second_part/xbank_detect_process/tensort_cache/yolov8.trt and /dev/null differ diff --git a/Bank_second_part/xbank_detect_process/utils.py b/Bank_second_part/xbank_detect_process/utils.py new file mode 100644 index 0000000..370a4b3 --- /dev/null +++ b/Bank_second_part/xbank_detect_process/utils.py @@ -0,0 +1,14 @@ +def is_image_file(filename): + image_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp"] + # 获取文件扩展名并转换为小写 + file_extension = filename.split(".")[-1].lower() + return file_extension in image_extensions + + +def is_rtsp_or_video(source): + if source.startswith("rtsp://"): + return True + + video_exts = ["mp4", "avi"] + file_extension = source.split(".")[-1].lower() + return file_extension in video_exts