Comments (3)
Hello!
Currently, Ultralytics YOLOv8 does not support setting a vid_stride
dynamically for different streams within a single tracking command. Each instance of model tracking would need to use the same vid_stride
.
However, you can achieve this functionality by running separate instances for each stream with the respective vid_stride
settings. Here's a simple way to manage this using threading:
import threading
from ultralytics import YOLO
def track_stream(source, vid_stride):
model = YOLO('yolov8s.pt', task='detect')
results = model.track(source, device=device, stream=True, classes=classes, verbose=False, stream_buffer=True, tracker=byte_track, vid_stride=vid_stride)
for pred in results:
print(pred)
# Define your streams and corresponding stride values
streams = {'rtsp1': 1, 'rtsp2': 1, 'rtsp3': 5, 'rtsp4': 5}
# Create and start a separate thread for each stream
threads = []
for stream, stride in streams.items():
t = threading.Thread(target=track_stream, args=(stream, stride))
t.start()
threads.append(t)
# Wait for all threads to finish
for t in threads:
t.join()
This script will allow each stream to process at its specific vid_stride
, running concurrently in separate threads. Let us know if you need further assistance! π
from ultralytics.
@glenn-jocher Thanks for your response :)
Can I use OpenCV to pre-process video streams and skip frames such that rtsp1 and rtsp2 skip every frame, and rtsp3 and rtsp4 skip every 5 frames before passing them to the YOLO model (set vid_stride=1), instead of using threading?
import cv2
from ultralytics import YOLO
def process_stream(stream_url, frame_skip, device):
cap = cv2.VideoCapture(stream_url)
model = YOLO('yolov8s.pt', task='detect')
frame_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
if frame_count % (frame_skip + 1) == 0: # frame_skip + 1 because we include the current frame in the count
results = model.track(frame, device=device, stream=False, classes=None, verbose=False, stream_buffer=False, tracker='byte_track', vid_stride=1)
for pred in results:
path = pred.path
print(f"Processed frame from {stream_url} saved to {path}")
frame_count += 1
cap.release()
# Device configuration
device = 'cuda' # or 'cpu'
# Define your streams and their respective frame skips (corresponding to vid_stride - 1)
streams = {
'rtsp1': 0, # Process every frame
'rtsp2': 0, # Process every frame
'rtsp3': 4, # Skip 4 frames
'rtsp4': 4, # Skip 4 frames
}
# Loop for processing each stream one at a time
for stream_url, skip in streams.items():
print(f"Starting processing for {stream_url}")
process_stream(stream_url, skip, device)
print(f"Finished processing for {stream_url}")
Can this approach simulate the effect of using different vid_stride values directly in the YOLO tracking function?
I am asking about this method because I am concerned about RAM usage when using threads.
from ultralytics.
@pornpra hi there! π
Yes, your approach of using OpenCV to pre-process and skip frames before feeding them into the YOLO model absolutely works as a good alternative to manage different frame skips without threading. By setting vid_stride=1
in the YOLO model and handling the frame skipping manually in your script as you've outlined, you effectively simulate various vid_stride
behaviors.
Your code example correctly adjusts the frequency of frames processed from each stream by changing the frame_skip
parameter. This will help control the RAM usage as you process one stream at a time, rather than handling multiple streams concurrently with threading. Just ensure your system is capable of handling the looped single-stream processing without lagging, especially when processing higher-resolution video streams.
Let us know how this works out, or if there's anything else you'd like to optimize! π
from ultralytics.
Related Issues (20)
- How to print the all the pedestrian trajectories within a period of time HOT 1
- editable mode installation problem with UNKNOWN built HOT 4
- YOLOv8 Weight Penalty HOT 3
- imgsz bug when using openvino HOT 8
- Yolov8 NotImplementedError with GPU HOT 4
- My YOLOv8 model is not uploaded to the hub even though it is trained HOT 8
- Giving class weight to Yolov8 HOT 4
- Not all dynamic dimensions are correctly set during model expert HOT 3
- AttributeError: module 'ultralytics.solutions' has no attribute 'SpeedEstimator' HOT 3
- nccl error when loading large data HOT 2
- Plan failed with a cudnnException HOT 2
- ## Area of Instance Segmented Object Using Yolov8 instance model HOT 1
- After the object detection model is trained, how to customize the criteria of βbest modelβ? HOT 4
- Model Training Resume with different Image size HOT 3
- YOLOv8 obb keypoint detection HOT 3
- How to insert a custom backbone in YOLOv8 ? HOT 4
- What parameters change with the train? HOT 7
- can i calculate the looses in the test dataset HOT 5
- Does YOLO perform object detection on jp2 image format? HOT 2
- Do "empty" background images help during model training? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralytics.