i am using this code for infrencing that is available on ultralyics site:
import contextlib
import tritonclient.http as httpclient #pip install if needed
from ultralytics import YOLO
import subprocess
import time
import cv2
from tritonclient.http import InferenceServerClient
import os
setup triton inference client
triton_client = InferenceServerClient(url=‘localhost:8000’, verbose=False, ssl=False)
Load the Triton Server model
model = YOLO(f’http://localhost:8000/yolov8n’, task=‘detect’)
directory=“pathtodirectory”
for filename in os.listdir(directory):
video_path=os.path.join(directory, filename)
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
if i export model in default settings i.e. (model.export(onnx)) than the infrencing works fine. i am getting results to any size of input .by default input is =640 (specified by ultraytics)
but i export model specifing size (model.export(onnx, imgsz=800)) and
than run on triton server it gives errors:
tritonclient.utils.InferenceServerException: [400] [request id: <id_unknown>] unexpected shape for input ‘images’ for model ‘yolov8n’. Expected [1,3,800,800], got [1,3,640,640]
for config.pbxt i am using:
name: “yolov8n”
platform: “tensorrt_plan”
max_batch_size: 0
input [
{
name: “images”
data_type: TYPE_FP32
dims: [1, 3, 800,800]
}
]
output [
{
name: “output0”
data_type: TYPE_FP32
dims: [1, 84, 13125]
}
]
instance_group [
{
kind: KIND_GPU,
count: 1
}
]
any solution of this problem?