libreyolo.LIBREYOLO

libreyolo.LIBREYOLO(model_path, size=None, reg_max=16, nb_classes=80, save_feature_maps=False, save_eigen_cam=False, cam_method='eigencam', cam_layer=None, device='auto', tiling=False)[source]

Unified Libre YOLO factory that automatically detects model version (8 or 11) from the weights file and returns the appropriate model instance.

Parameters:
  • model_path (str) – Path to model weights file (.pt) or ONNX file (.onnx)

  • size (str) – Model size variant. Required for .pt files (“n”, “s”, “m”, “l”, “x”), ignored for .onnx

  • reg_max (int) – Regression max value for DFL (default: 16)

  • nb_classes (int) – Number of classes (default: 80 for COCO)

  • save_feature_maps (bool) – If True, saves backbone feature map visualizations on each inference (default: False)

  • save_eigen_cam (bool) – If True, saves EigenCAM heatmap visualizations on each inference (default: False)

  • cam_method (str) – Default CAM method for explain(). Options: “eigencam”, “gradcam”, “gradcam++”, “xgradcam”, “hirescam”, “layercam”, “eigengradcam” (default: “eigencam”)

  • cam_layer (str) – Target layer for CAM computation (default: “neck_c2f22”)

  • device (str) – Device for inference. “auto” (default) uses CUDA if available, else MPS, else CPU.

  • tiling (bool) – Enable tiling for large images (default: False). When enabled, images larger than 640x640 are split into overlapping tiles for inference.

Returns:

Instance of LIBREYOLO8, LIBREYOLO11, or LIBREYOLOOnnx

Example

>>> model = LIBREYOLO("yolo11n.pt", size="n", cam_method="gradcam")
>>> result = model.explain("image.jpg", save=True)