Spaces:
Running
Running
Create debug_detections.py
Browse files- debug_detections.py +83 -0
debug_detections.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Quick debug script to test model locally and inspect detections
|
| 4 |
+
Run this in your container or locally to see what the model returns
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 9 |
+
|
| 10 |
+
from PIL import Image
|
| 11 |
+
import numpy as np
|
| 12 |
+
from rfdetr import RFDETRSegPreview
|
| 13 |
+
import supervision as sv
|
| 14 |
+
|
| 15 |
+
# Path to your checkpoint
|
| 16 |
+
CHECKPOINT_PATH = "/tmp/checkpoint_best_total.pth"
|
| 17 |
+
|
| 18 |
+
print("Loading model...")
|
| 19 |
+
model = RFDETRSegPreview(pretrain_weights=CHECKPOINT_PATH)
|
| 20 |
+
print("Model loaded!")
|
| 21 |
+
|
| 22 |
+
# Create a test image (or load your own)
|
| 23 |
+
test_img = Image.new("RGB", (640, 480), color=(73, 109, 137))
|
| 24 |
+
print(f"Test image size: {test_img.size}")
|
| 25 |
+
|
| 26 |
+
# Run prediction
|
| 27 |
+
print("\nRunning prediction with threshold=0.25...")
|
| 28 |
+
detections = model.predict(test_img, threshold=0.25)
|
| 29 |
+
|
| 30 |
+
print("\n" + "="*60)
|
| 31 |
+
print("DETECTION RESULTS:")
|
| 32 |
+
print("="*60)
|
| 33 |
+
print(f"Type: {type(detections)}")
|
| 34 |
+
print(f"Length: {len(detections)}")
|
| 35 |
+
|
| 36 |
+
# Check attributes
|
| 37 |
+
attrs = dir(detections)
|
| 38 |
+
print(f"\nAvailable attributes: {[a for a in attrs if not a.startswith('_')]}")
|
| 39 |
+
|
| 40 |
+
if hasattr(detections, 'confidence'):
|
| 41 |
+
print(f"\nConfidence scores: {detections.confidence}")
|
| 42 |
+
print(f"Confidence count: {len(detections.confidence)}")
|
| 43 |
+
print(f"Confidence type: {type(detections.confidence)}")
|
| 44 |
+
|
| 45 |
+
if hasattr(detections, 'class_id'):
|
| 46 |
+
print(f"\nClass IDs: {detections.class_id}")
|
| 47 |
+
print(f"Class count: {len(detections.class_id)}")
|
| 48 |
+
|
| 49 |
+
if hasattr(detections, 'masks'):
|
| 50 |
+
masks = detections.masks
|
| 51 |
+
print(f"\nMasks present: {masks is not None}")
|
| 52 |
+
if masks is not None:
|
| 53 |
+
print(f"Masks type: {type(masks)}")
|
| 54 |
+
if hasattr(masks, 'shape'):
|
| 55 |
+
print(f"Masks shape: {masks.shape}")
|
| 56 |
+
elif hasattr(masks, '__len__'):
|
| 57 |
+
print(f"Masks length: {len(masks)}")
|
| 58 |
+
if len(masks) > 0:
|
| 59 |
+
print(f"First mask type: {type(masks[0])}")
|
| 60 |
+
if hasattr(masks[0], 'shape'):
|
| 61 |
+
print(f"First mask shape: {masks[0].shape}")
|
| 62 |
+
else:
|
| 63 |
+
print("\nNO MASKS ATTRIBUTE FOUND!")
|
| 64 |
+
|
| 65 |
+
# Try to annotate
|
| 66 |
+
if len(detections) > 0:
|
| 67 |
+
print("\n" + "="*60)
|
| 68 |
+
print("Testing annotation...")
|
| 69 |
+
print("="*60)
|
| 70 |
+
try:
|
| 71 |
+
palette = sv.ColorPalette.from_hex(["#ffff00", "#ff9b00"])
|
| 72 |
+
mask_annotator = sv.MaskAnnotator(color=palette)
|
| 73 |
+
annotated = mask_annotator.annotate(test_img, detections)
|
| 74 |
+
print("✓ Mask annotation successful!")
|
| 75 |
+
print(f"Annotated image size: {annotated.size}")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"✗ Mask annotation failed: {e}")
|
| 78 |
+
import traceback
|
| 79 |
+
traceback.print_exc()
|
| 80 |
+
|
| 81 |
+
print("\n" + "="*60)
|
| 82 |
+
print("Debug complete!")
|
| 83 |
+
print("="*60)
|