Using SAHI in my project

Hello, Im trying to use SAHI with my project which is parking managment the view of my camera is not 90, so my model cant detect mos tof the cars, so i tried using sahi alone as a detection it worked, but i dont know how to use it in my project, can anyone guide me? thank you

It’s tough to “help” without knowing what you need help with specifically. If you haven’t already, you should check out this guide SAHI Tiled Inference - Ultralytics YOLO Docs which should help a lot. Otherwise, you’ll need to provide more detail about your project and what you need help with for anyone to actually help out.

thank you for replying, i did read it but i didnt know how to output it while it includes the detection of parked cars in my code, im using (usb camera)

The issue you’re looking for help with is unclear. The statement

how to output it while it includes the detection of parked cars in my code

is very vague. Are you saying that you don’t understand what part of your code needs to be updated to include SAHI? If that’s the case, then it’s just a matter of updating the part where your model is loaded and where you make predictions with the model.

If you have something like:

from ultralytics import YOLO

model = YOLO("yolo11n.pt")

results = model.predict(0)  # assuming webcam is "0"

You would update it to something like this (might be different for your project):

  1. Use the AutoDetectionModel to load your model

    - from ultralytics import YOLO
    + from sahi import AutoDetectionModel
    + from sahi.predict import get_sliced_prediction
    
    - model = YOLO("yolo11n.pt")
    + detection_model = AutoDetectionModel.from_pretrained(
    +    model_type="ultralytics",
    +    model_path="yolo11n.pt",
    +    confidence_threshold=0.3,
    +    device="cpu",  # or 'cuda:0'
    +) 
    
  2. Use the SAHI for predictions

    - results = model.predict(0)
    + results = get_sliced_prediction(
    +     0,  # webcam source
    +     detection_model,
    +     slice_height=256,
    +     slice_width=256,
    +     overlap_height_ratio=0.2,
    +     overlap_width_ratio=0.2,
    + )