YOLO vid_stride parameter is incorrectly cutting processing the video

116 views Asked by At

I aim to make predictions at 30-second intervals within my video. How can I optimize the vid_stride parameter for this purpose? The video has a frame rate of 25 fps, consisting of a total of 7478 frames (approximately a 5-minute duration). However, setting the vid_stride value to 750 resulted in a video clip lasting less than a second, containing only around 9 frames. What adjustments should be made to achieve the desired 30-second prediction intervals?"

from ultralytics import YOLO

model_path = "/content/best.pt"
model = YOLO(model_path)

for r in model.predict(source="/content/myvideo.mp4", save=True, stream=True,vid_stride=1):
    pass
1

There are 1 answers

0
Ricardo Gellman On

frames to skip = video fps × interval in seconds

So, for a 30-second interval with 25 fps:

frames to skip =25×30=750

You have correctly set vid_stride to 750, but as you are getting only 9 frames, this might be because your video has 7478 frames, and a stride of 750 is causing it to go beyond the total number of frames.

I would set it to total frames and test it.

from ultralytics import YOLO

model_path = "/content/best.pt"
model = YOLO(model_path)

for r in model.predict(source="/content/myvideo.mp4", save=True, stream=True, vid_stride=7478):
    pass