- Removed specific version constraint for `supervision` package in installation command. - Updated references from `sv.BoundingBoxAnnotator` to `sv.BoxAnnotator` for consistency with the latest library changes. - Removed asset extension of package installation because it is has been included into main package Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
532 KiB
Vendored
532 KiB
Vendored
In [1]:
!nvidia-smiFri Feb 23 03:18:02 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 Tesla V100-SXM2-16GB Off | 00000000:00:04.0 Off | 0 |
| N/A 33C P0 24W / 300W | 0MiB / 16384MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+---------------------------------------------------------------------------------------+
In [ ]:
!pip install -q inference-gpu "supervision"In [ ]:
from supervision.assets import download_assets, VideoAssets
# Download a supervision video asset
path_to_video = download_assets(VideoAssets.PEOPLE_WALKING)In [4]:
import supervision as sv
from inference.models.utils import get_roboflow_model
# Load a pre trained yolov8 nano model from Roboflow Inference.
model = get_roboflow_model('yolov8n-640')
# Create a video info object from the video path.
video_info = sv.VideoInfo.from_video_path(path_to_video)
# Create a label annotator for labeling detections with our tracker_id.
label = sv.LabelAnnotator()
# Create a ByteTrack object to track detections.
byte_tracker = sv.ByteTrack(frame_rate=video_info.fps)
# Create a frame generator from video path for iteration of frames.
frame_generator = sv.get_video_frames_generator(path_to_video)
# Grab a frame from the frame_generator.
frame = next(frame_generator)
# Run inference on the frame by passing it to our model.
result = model.infer(frame)[0]
# Convert model results to a supervision detection object.
detections = sv.Detections.from_inference(result)
# Update detections with tracker ids fro byte_tracker.
tracked_detections = byte_tracker.update_with_detections(detections)
# Create labels with tracker_id for label annotator.
labels = [ f"{tracker_id}" for tracker_id in tracked_detections.tracker_id ]
# Apply label annotator to frame.
annotated_frame = label.annotate(scene=frame.copy(), detections=tracked_detections, labels=labels)
# Display the frame.
sv.plot_image(annotated_frame)In [ ]:
from tqdm import tqdm
# Load a pre trained yolov8 nano model from Roboflow Inference.
model = get_roboflow_model('yolov8n-640')
# Create a video info object from the video path.
video_info = sv.VideoInfo.from_video_path(path_to_video)
# Create a label annotator for labeling detections with our tracker_id.
label = sv.LabelAnnotator()
# Create a ByteTrack object to track detections.
byte_tracker = sv.ByteTrack(frame_rate=video_info.fps)
# Create a frame generator from video path for iteration of frames.
frame_generator = sv.get_video_frames_generator(path_to_video)
# Create a video sink context manager to save resulting video.
with sv.VideoSink(target_path="output.mp4", video_info=video_info) as sink:
# Iterate through frames yielded from the frame_generator.
for frame in tqdm(frame_generator, total=video_info.total_frames):
# Run inference on the frame by passing it to our model.
result = model.infer(frame)[0]
# Convert model results to a supervision detection object.
detections = sv.Detections.from_inference(result)
# Update detections with tracker ids fro byte_tracker.
tracked_detections = byte_tracker.update_with_detections(detections)
# Create labels with tracker_id for label annotator.
labels = [ f"{tracker_id}" for tracker_id in tracked_detections.tracker_id ]
# Apply label annotator to frame.
annotated_frame = label.annotate(scene=frame.copy(), detections=tracked_detections, labels=labels)
# Save the annotated frame to an output video.
sink.write_frame(frame=annotated_frame)