gpt-4o-2024-08-06· OpenAI WildChat-4.8M (AI2)
Fix errors and bugs in the given code, without changing its intended functionality. ONLY…
- User
Fix errors and bugs in the given code, without changing its intended functionality. ONLY return the fixed code and nothing else. Enclose the entire code in a single code block.
from ultralytics import YOLO import torch import cv2
Check if GPU is available
device = "mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu" print(f"Using device: {device}")
Load the pre-trained YOLO model with GPU support
model = YOLO("best_v8n.pt").to(device)
Open the live streaming feed
stream_url = "hama.jpg"
Run inference on the live stream
results = model(stream_url, stream=True)
for result in results: i wanna print object name class prediction # boxes = result.boxes # probs = result.probs # obb = result.obb
# Display the annotated frame cv2.imshow("Detection", result.plot()) if cv2.waitKey(1) == ord('q'): breakcv2.destroyAllWindows()
- Assistant
from ultralytics import YOLO import torch import cv2 # Check if GPU is available device = "mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu" print(f"Using device: {device}") # Load the pre-trained YOLO model with GPU support model = YOLO("best_v8n.pt").to(device) # Open the static image image_path = "hama.jpg" # Run inference on the image results = model(image_path) for result in results: # Print object names (class predictions) for detected objects for obj in result.names: print(f"Detected object: {result.names[obj]}") # Display the annotated frame cv2.imshow("Detection", result.plot()) if cv2.waitKey(1) == ord('q'): break cv2.destroyAllWindows()