这个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,
)