From d93a81c8027ed0c09dee5d26bd1ba8ad7b2ebf36 Mon Sep 17 00:00:00 2001 From: liyubo Date: Thu, 13 Nov 2025 11:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B1=E4=BA=AB=E7=9B=AE=E5=BD=95AI=E8=AF=86?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- predict/predict_yolo11seg.py | 28 ++++++++++------------------ yolo_api.py | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/predict/predict_yolo11seg.py b/predict/predict_yolo11seg.py index 1f2e6a2..95ddbbd 100644 --- a/predict/predict_yolo11seg.py +++ b/predict/predict_yolo11seg.py @@ -636,7 +636,7 @@ class YOLOSegmentationInference: print(f"处理目录失败: {e}") return results - def process_image_directory_share_dir(self, input_dir, user_name, pwd, output_dir: Optional[str] = None, + def process_image_directory_share_dir(self, task_id, input_dir, user_name, pwd, output_dir: Optional[str] = None, conf_threshold: float = 0.25, iou_threshold: float = 0.5, save_mask: bool = False, save_label: bool = False, show: bool = False, result_save: [] = None) -> List[ @@ -694,16 +694,8 @@ class YOLOSegmentationInference: # 推送识别数据到共享目录 pile_dict = get_pile_dict(image_path, user_name, pwd) process_dir(pile_dict, output_dir) - # 找到 图像类 文件夹 - found_paths = scanner.find_folders_by_name( - share_path=config['share'], - folder_name='图像类' - ) - if len(found_paths) > 0 : - tmpConf = get_conf(found_paths[0], user_name, pwd) - scanner.upload_directory(output_dir, config['share'], remote_dir=tmpConf['dir']+"_识别") - else : - print(f"错误: 远程共享目录 找不到【图像类】目录") + current_time = datetime.now().strftime("%Y%m%d%H%M%S") + scanner.upload_directory(output_dir, config['share'], remote_dir=input_dir+f"_识别/{task_id}/{current_time}") return results @@ -862,7 +854,7 @@ def predict_images(pt_name, zip_url, output_dir="predictions", conf_threshold=0. -def predict_images_share_dir(pt_name, zip_url, user_name, pwd, output_dir="predictions", conf_threshold=0.25, save_json=False): +def predict_images_share_dir(task_id, pt_name, zip_url, user_name, pwd, output_dir="predictions", conf_threshold=0.25, save_json=False): # 本地测试模式 - 请根据实际情况修改以下路径 # local_model_path = r"D:\project\verification\ultralytics-main\model\script\seg\pt\test.pttest.pt" local_model_path = r"../pt_save/road_crack.pt" @@ -905,12 +897,12 @@ def predict_images_share_dir(pt_name, zip_url, user_name, pwd, output_dir="predi folder_name='图像类' ) - target_path = "" - report_data_path = "" + target_path = "" # 识别图片目录 + flag_dir_path = "" # 标识目录 if len(found_paths) > 0: # 处理目录 - report_data_path = found_paths[0] - tmpConfig = get_conf(report_data_path, user_name, pwd) + flag_dir_path = found_paths[0] + tmpConfig = get_conf(flag_dir_path, user_name, pwd) found_paths = scanner.find_folders_by_name( share_path=config['share'], folder_name='Images', @@ -932,11 +924,11 @@ def predict_images_share_dir(pt_name, zip_url, user_name, pwd, output_dir="predi # ) # 创建并启动线程 - thread1 = threading.Thread(target=inference.process_image_directory_share_dir, args=(target_path,user_name,pwd,output_dir,conf_threshold,iou_threshold,save_mask,save_label,show,result_save)) + thread1 = threading.Thread(target=inference.process_image_directory_share_dir, args=(task_id, target_path,user_name,pwd,output_dir,conf_threshold,iou_threshold,save_mask,save_label,show,result_save)) # 启动线程 thread1.start() else: print(f"错误: 输入 {zip_url} 不是有效的文件或目录") - return f"{report_data_path}_识别", "success" \ No newline at end of file + return f"{target_path}_识别/{task_id}", "success" \ No newline at end of file diff --git a/yolo_api.py b/yolo_api.py index 77e0ab6..dc3a7f7 100644 --- a/yolo_api.py +++ b/yolo_api.py @@ -510,7 +510,7 @@ async def start_inference_share_dir(request): pwd = "abc@1234" output_dir = f"predictions/{task_id}" - inference_zip_url,message=predict_images_share_dir(pt_name, zip_url, user_name, pwd, output_dir=output_dir, conf_threshold=0.25, save_json=False) + inference_zip_url,message=predict_images_share_dir(task_id, pt_name, zip_url, user_name, pwd, output_dir=output_dir, conf_threshold=0.25, save_json=False) if inference_zip_url: return response.json({ "status": "success",