""" Maritime_Custom - Example Inference Script Repository: MuayThaiLegz/Maritime_Custom """ from ultralytics import YOLO import cv2 # ============================================ # 1. BASIC INFERENCE # ============================================ # Load model model = YOLO('MuayThaiLegz/Maritime_Custom') # Single image results = model.predict( source='maritime_image.jpg', conf=0.25, save=True ) # ============================================ # 2. VIDEO PROCESSING # ============================================ # Process video with streaming results = model.predict( source='port_surveillance.mp4', conf=0.25, stream=True, save=True ) for i, result in enumerate(results): print(f"Frame {i}: {len(result.boxes)} vessels detected") # ============================================ # 3. REAL-TIME WEBCAM # ============================================ # Live detection results = model.predict( source=0, # Webcam conf=0.25, show=True, stream=True ) # ============================================ # 4. BATCH PROCESSING # ============================================ # Process directory results = model.predict( source='maritime_images/', conf=0.25, save=True, project='detections', name='batch_run' ) # ============================================ # 5. CUSTOM POST-PROCESSING # ============================================ # Advanced detection with custom handling results = model.predict('image.jpg', conf=0.25) for result in results: boxes = result.boxes img = result.orig_img for box in boxes: # Extract info x1, y1, x2, y2 = box.xyxy[0].cpu().numpy() conf = float(box.conf[0]) # Draw custom annotations cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2) cv2.putText(img, f'Vessel: {conf:.2%}', (int(x1), int(y1)-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) cv2.imwrite('annotated.jpg', img) # ============================================ # 6. EXPORT FOR PRODUCTION # ============================================ # Export to ONNX model.export(format='onnx', dynamic=True) # Export to TensorRT (NVIDIA) model.export(format='engine', device=0, half=True) print("✅ Inference examples complete!")