diff --git a/predict/predict_yolo11seg.py b/predict/predict_yolo11seg.py index 71685b3..da34098 100644 --- a/predict/predict_yolo11seg.py +++ b/predict/predict_yolo11seg.py @@ -462,13 +462,13 @@ class YOLOSegmentationInference: h, w = mask.shape points = [] for point in approx: - x = point[0][0] / w - y = point[0][1] / h + x = max(0.0, min(1.0, point[0][0] / w)) + y = max(0.0, min(1.0, point[0][1] / h)) points.extend([x, y]) # 写入标签文件 if len(points) >= 6: # 至少3个点 - line = f"{class_id} {' '.join(map(lambda x: f'{x:.6f}', points))} {score:.6f}\n" + line = f"{class_id} {' '.join(map(lambda x: f'{x:.6f}', points))}\n" f.write(line) print(f"标签文件已保存: {label_path}") @@ -1027,4 +1027,8 @@ def predict_images_share_dir(task_id, pt_name, zip_url, user_name, pwd, output_d else : print(f"错误: 输入 {zip_url} 不是有效的文件或目录") - return standardized_path(f"{target_path}_识别/{task_id}/{current_time}/{task_id}.zip"), "success" \ No newline at end of file + return standardized_path(f"{target_path}_识别/{task_id}/{current_time}/{task_id}.zip"), "success" + +if __name__ == '__main__': + predict_images + #predict_images_share_dir(1, "road_crack", "smb://192.168.1.100/share/ai_train_platform/train.zip", "admin", "admin.123", "predictions", 0.25, True) \ No newline at end of file