共享目录AI识别

This commit is contained in:
liyubo 2025-11-13 11:59:22 +08:00
parent 06bafccb4e
commit d93a81c802
2 changed files with 11 additions and 19 deletions

View File

@ -636,7 +636,7 @@ class YOLOSegmentationInference:
print(f"处理目录失败: {e}") print(f"处理目录失败: {e}")
return results 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, conf_threshold: float = 0.25, iou_threshold: float = 0.5,
save_mask: bool = False, save_label: bool = False, show: bool = False, save_mask: bool = False, save_label: bool = False, show: bool = False,
result_save: [] = None) -> List[ result_save: [] = None) -> List[
@ -694,16 +694,8 @@ class YOLOSegmentationInference:
# 推送识别数据到共享目录 # 推送识别数据到共享目录
pile_dict = get_pile_dict(image_path, user_name, pwd) pile_dict = get_pile_dict(image_path, user_name, pwd)
process_dir(pile_dict, output_dir) process_dir(pile_dict, output_dir)
# 找到 图像类 文件夹 current_time = datetime.now().strftime("%Y%m%d%H%M%S")
found_paths = scanner.find_folders_by_name( scanner.upload_directory(output_dir, config['share'], remote_dir=input_dir+f"_识别/{task_id}/{current_time}")
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"错误: 远程共享目录 找不到【图像类】目录")
return results 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"D:\project\verification\ultralytics-main\model\script\seg\pt\test.pttest.pt"
local_model_path = r"../pt_save/road_crack.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='图像类' folder_name='图像类'
) )
target_path = "" target_path = "" # 识别图片目录
report_data_path = "" flag_dir_path = "" # 标识目录
if len(found_paths) > 0: if len(found_paths) > 0:
# 处理目录 # 处理目录
report_data_path = found_paths[0] flag_dir_path = found_paths[0]
tmpConfig = get_conf(report_data_path, user_name, pwd) tmpConfig = get_conf(flag_dir_path, user_name, pwd)
found_paths = scanner.find_folders_by_name( found_paths = scanner.find_folders_by_name(
share_path=config['share'], share_path=config['share'],
folder_name='Images', 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() thread1.start()
else: else:
print(f"错误: 输入 {zip_url} 不是有效的文件或目录") print(f"错误: 输入 {zip_url} 不是有效的文件或目录")
return f"{report_data_path}_识别", "success" return f"{target_path}_识别/{task_id}", "success"

View File

@ -510,7 +510,7 @@ async def start_inference_share_dir(request):
pwd = "abc@1234" pwd = "abc@1234"
output_dir = f"predictions/{task_id}" 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: if inference_zip_url:
return response.json({ return response.json({
"status": "success", "status": "success",