yolov8带overlap和NMS的切块推理库

点击查看代码
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,
)
> > https://github.com/Koldim2001/YOLO-Patch-Based-Inference
posted @ 2024-05-16 15:25  阳光天气  阅读(59)  评论(0)    收藏  举报