ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
23.17k stars 4.62k forks source link

How to use tracks in the TensoRT framework #10137

Open JustChenk opened 2 weeks ago

JustChenk commented 2 weeks ago

Search before asking

Question

I want to use the track method, but it doesn't have in AutoBackend

from ultralytics.nn.autobackend import AutoBackend
def load_model(weights_path="best.onnx", device=torch.device(f"cuda:{gpu}")):
    model = AutoBackend(weights_path,
                        device=device,
                        dnn=False,
                        data=None,
                        fp16=False,
                        fuse=True,
                        verbose=False)

    # warm up
    return model

How can the track method be called, just like the code below `def person_infer(weight_path): model = YOLO(weight_path)

def process(frame):
    results = model.track(frame, verbose=False, conf=0.5)
    return results
return process`

Additional

No response

glenn-jocher commented 2 weeks ago

Hello! 👋

To utilize the tracking feature with a model loaded through AutoBackend, you can switch to using the YOLO class directly, as demonstrated in your second code snippet. The YOLO class integrates seamlessly with YOLO's tracking capabilities, enabling you to perform object tracking with any supported model, including those exported to TensorRT. Here's how you can adapt the tracking code snippet:

from ultralytics import YOLO

def person_infer(weight_path):
    # Load your model
    model = YOLO(weight_path)

    def process(frame):
        # Use the track method here
        results = model.track(frame, verbose=False, conf=0.5)
        return results

    return process

Just replace weight_path with your model's path, and ensure your environment is set up for TensorRT if you are using a TensorRT model. This approach gives you access to the tracking functionality directly.

Feel free to reach out if you have any more questions! 😊