| """ |
| Maritime_Custom - Example Inference Script |
| Repository: MuayThaiLegz/Maritime_Custom |
| """ |
|
|
| from ultralytics import YOLO |
| import cv2 |
|
|
| |
| |
| |
|
|
| |
| model = YOLO('MuayThaiLegz/Maritime_Custom') |
|
|
| |
| results = model.predict( |
| source='maritime_image.jpg', |
| conf=0.25, |
| save=True |
| ) |
|
|
| |
| |
| |
|
|
| |
| 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") |
|
|
| |
| |
| |
|
|
| |
| results = model.predict( |
| source=0, |
| conf=0.25, |
| show=True, |
| stream=True |
| ) |
|
|
| |
| |
| |
|
|
| |
| results = model.predict( |
| source='maritime_images/', |
| conf=0.25, |
| save=True, |
| project='detections', |
| name='batch_run' |
| ) |
|
|
| |
| |
| |
|
|
| |
| results = model.predict('image.jpg', conf=0.25) |
|
|
| for result in results: |
| boxes = result.boxes |
| img = result.orig_img |
| |
| for box in boxes: |
| |
| x1, y1, x2, y2 = box.xyxy[0].cpu().numpy() |
| conf = float(box.conf[0]) |
| |
| |
| 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) |
|
|
| |
| |
| |
|
|
| |
| model.export(format='onnx', dynamic=True) |
|
|
| |
| model.export(format='engine', device=0, half=True) |
|
|
| print("✅ Inference examples complete!") |
|
|