From b0ce11f987de6ce3853c14382fae45d295a286fe Mon Sep 17 00:00:00 2001 From: jiajie555 Date: Fri, 18 Apr 2025 15:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A8=E8=BF=B9=E6=95=B0=E4=B8=BA=E7=A9=BA.t?= =?UTF-8?q?xt=E6=97=B6=EF=BC=8C=E9=81=8D=E5=8E=86=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E4=BA=8B=E4=BB=B6=E5=90=8D=EF=BC=8C=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=B7=91pipline=E5=86=99=E5=85=A5=E8=BD=A8=E8=BF=B9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_process_addWrite.py | 54 ++++++++++++++++++++++++++---------- read_xlsx_filter_events.py | 6 ++-- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/pipeline_process_addWrite.py b/pipeline_process_addWrite.py index 6319d8c..55e0a30 100644 --- a/pipeline_process_addWrite.py +++ b/pipeline_process_addWrite.py @@ -142,13 +142,15 @@ def show_result(eventpath, event_tracks, yrtDict, savepath_pipe): def pipeline(dict_data, + pickle_exist, eventpath, SourceType, weights, DataType = "raw", #raw, pkl: images or videos, pkl, pickle file YoloVersion="V5", savepath = None, - saveimages = True + saveimages = True, + ): ## 构造购物事件字典 @@ -172,10 +174,11 @@ def pipeline(dict_data, yrt_out = [] if DataType == "raw": - ### 不重复执行已经过yolo-resnet-tracker - if pklpath.exists(): - print(f"Pickle file have saved: {evtname}.pickle") - return + if not pickle_exist: + ### 不重复执行已经过yolo-resnet-tracker + if pklpath.exists(): + print(f"Pickle file have saved: {evtname}.pickle") + return if SourceType == "video": vpaths = get_video_pairs(eventpath) @@ -441,7 +444,8 @@ def execute_pipeline(evtdir = r"D:\datasets\ym\后台数据\unzip", weight_yolo_v5 = r'./ckpts/best_cls10_0906.pt' , weight_yolo_v10 = r'./ckpts/best_v10s_width0375_1205.pt', saveimages = True, - max_col = 12 + max_col = 12, + track_txt = '' ): ''' 运行函数 pipeline(),遍历事件文件夹,每个文件夹是一个事件 @@ -481,18 +485,36 @@ def execute_pipeline(evtdir = r"D:\datasets\ym\后台数据\unzip", if csv_data == '': with open('no_datacsv.txt', 'a') as f: f.write(str(date_file) + '\n') - for item in date_file.iterdir(): - # dict_data = {} - if item.is_dir(): - # item = evtdir/Path("20241212-171505-f0afe929-fdfe-4efa-94d0-2fa748d65fbb_6907992518930") + if len(track_txt) == 0: ## 无track_txt时,遍历文件夹下的所有文件 + pickle_exist = False + for item in date_file.iterdir(): + # dict_data = {} + if item.is_dir(): + # item = evtdir/Path("20241212-171505-f0afe929-fdfe-4efa-94d0-2fa748d65fbb_6907992518930") + parmDict["eventpath"] = item + event_name = str(item.name) + dict_data = get_process_csv_data(csv_data, item) + dict_data_all = pipeline(dict_data, pickle_exist, **parmDict) + if dict_data_all is not None: #已保存pickle文件的事件返回为None + # print('dict_data_all', dict_data_all) + excelWriter.write_simi_add(wb, ws, sheet, max_col, event_name, dict_data_all, headers, excel_name) + else: ## 有track_txt时,遍历track_txt文件中的事件 + pickle_exist = True ##不判断pickle文件是否存在的标志 + txt_path = os.path.join(date_file, track_txt) + with open(txt_path, 'r') as f: + events = f.readlines() + events = [i.strip() for i in events] + for event in events: + item = date_file / event parmDict["eventpath"] = item event_name = str(item.name) dict_data = get_process_csv_data(csv_data, item) - print('dict_data', dict_data) - dict_data_all = pipeline(dict_data, **parmDict) - if dict_data_all is not None: #已保存pickle文件的事件返回为None + dict_data_all = pipeline(dict_data, pickle_exist, **parmDict) + if dict_data_all is not None: # 已保存pickle文件的事件返回为None # print('dict_data_all', dict_data_all) - excelWriter.write_simi_add(wb, ws, sheet, max_col, event_name, dict_data_all, headers, excel_name) + excelWriter.write_simi_add(wb, ws, sheet, max_col, event_name, dict_data_all, headers, + excel_name) + # try: # pipeline(**parmDict) @@ -516,6 +538,7 @@ if __name__ == "__main__": datapath = '/home/yujia/yj/gpu_code/callback_data_test_0417/' savepath = '/home/yujia/yj/gpu_code/result_0417_v10/' max_col = 12 ##excel表格列索引从0开始,从这列开始写入代码解析内容 + track_txt = '轨迹数为空.txt' execute_pipeline(evtdir=datapath, DataType = "raw", # raw, pkl @@ -526,7 +549,8 @@ if __name__ == "__main__": weight_yolo_v5 = '/home/yujia/yj/gpu_code/ckpts/best_cls10_0906.pt' , weight_yolo_v10 = '/home/yujia/yj/gpu_code/ckpts/best_v10s_width0375_1205.pt', saveimages = False, - max_col = max_col + max_col = max_col, + track_txt = track_txt ) diff --git a/read_xlsx_filter_events.py b/read_xlsx_filter_events.py index 7b342a2..44432af 100644 --- a/read_xlsx_filter_events.py +++ b/read_xlsx_filter_events.py @@ -43,11 +43,13 @@ def anlay_xlsx_filter_events(file_path, name, ch='轨迹数', classFlag=False): name_ = replace_str(name) if ch in name: ch_ = ch + '为空' - txt_path = os.path.join(date_path, date + '_' + ch_ + '.txt') + # txt_path = os.path.join(date_path, date + '_' + ch_ + '.txt') + txt_path = os.path.join(date_path, ch_ + '.txt') filter_df = df[(df[name].isnull())] else: - txt_path = os.path.join(date_path, date + '_' + name_ + '.txt') + # txt_path = os.path.join(date_path, date + '_' + name_ + '.txt') + txt_path = os.path.join(date_path, name_ + '.txt') filter_df = df[(df[name].notna()) & (df['是否购物现场'].str.contains('是'))] try: