yolov8 分割任务切块推理库 patched_yolo_infer
这个Python库简化了类似SAHI的推理,例如分割任务,从而能够检测图像中的小对象。它同时满足对象检测和实例分割任务,支持广泛的Ultralytics模型。
该库还为所有模型的推理结果可视化提供了流畅的定制,包括标准方法(直接网络运行)和独特的基于补丁的变体。
模型支持:该库提供对多个超解析深度学习模型的支持,如YOLOv8、YOLOv8-seg、YOLOv9、YOLOv29-seg、FastSAM和RTDETR。用户可以从预先训练的选项中进行选择,也可以使用自定义训练的模型来最好地满足他们的任务要求。
https://github.com/Koldim2001/YOLO-Patch-Based-Inference
代码测试:
点击查看代码
import cv2
from patched_yolo_infer import MakeCropsDetectThem, CombineDetections
from patched_yolo_infer import visualize_results
# Load the image
img_path = r'D:\gzj\pic\see\0510\a001.jpg'
img = cv2.imread(img_path)
element_crops = MakeCropsDetectThem(
image=img,
# model_path=r"E:\03_PythonProjects\granule_server_cngr_2\y_models\primary_b.pt",
model_path=r"E:\03_PythonProjects\granule_server_cngr_2\y_models\dakeli_weifen_suiqiu.pt",
conf=0.7,
segment=True,
shape_x=640,
shape_y=640,
overlap_x=50,
overlap_y=50,
# conf=0.3,
iou=0.7,
resize_initial_size=True,
)
result = CombineDetections(element_crops, nms_threshold=0.05, match_metric='IOS')
# Final Results:
img=result.image
confidences=result.filtered_confidences
print("confidencs:",confidences)
boxes=result.filtered_boxes
masks=result.filtered_masks
classes_ids=result.filtered_classes_id
print("classes_ids",classes_ids)
classes_names=result.filtered_classes_names
print("classes_names",classes_names)
# Visualizing the results using the visualize_results function
visualize_results(
img=result.image,
confidences=result.filtered_confidences,
boxes=result.filtered_boxes,
masks=result.filtered_masks,
classes_ids=result.filtered_classes_id,
classes_names=result.filtered_classes_names,
show_confidences=True,
show_boxes=False,
segment=True,
show_class=True,
font_scale=0.8,
)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步