refactor: remove YOLO processor and dependencies
- Delete YOLO processor implementation (src/core/processor/yolo.rs) - Remove YOLO from processing pipeline and worker - Clean up YOLO-related code across multiple modules - Add migration 033_remove_yolo.sql YOLO functionality removed as part of architecture simplification
This commit is contained in:
@@ -1,137 +0,0 @@
|
||||
#!/opt/homebrew/bin/python3.11
|
||||
"""
|
||||
Add YOLO metadata to chunks
|
||||
"""
|
||||
|
||||
import json
|
||||
import psycopg2
|
||||
|
||||
|
||||
YOLO_FILE = "/Users/accusys/test_video/Old_Time_Movie_Show_-_Charade_1963.HD.yolo.json"
|
||||
VIDEO_UUID = "39567a0eb16f39fd"
|
||||
FPS = 24.0
|
||||
|
||||
POSTGRES_CONFIG = {
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"user": "accusys",
|
||||
"password": "Test3200",
|
||||
"database": "momentry",
|
||||
}
|
||||
|
||||
|
||||
def load_yolo_data():
|
||||
"""Load YOLO JSON data"""
|
||||
print(f"Loading YOLO data from {YOLO_FILE}...")
|
||||
with open(YOLO_FILE) as f:
|
||||
data = json.load(f)
|
||||
print(f"Loaded {len(data['frames'])} frames")
|
||||
return data
|
||||
|
||||
|
||||
def get_chunk_yolo_metadata(yolo_data, start_time, end_time):
|
||||
"""Get YOLO objects that appear in a time range"""
|
||||
start_frame = int(start_time * FPS)
|
||||
end_frame = int(end_time * FPS)
|
||||
|
||||
objects = set()
|
||||
detections = []
|
||||
|
||||
for frame_num in range(start_frame, end_frame + 1):
|
||||
frame_str = str(frame_num)
|
||||
if frame_str in yolo_data["frames"]:
|
||||
frame_data = yolo_data["frames"][frame_str]
|
||||
for det in frame_data.get("detections", []):
|
||||
if det["confidence"] >= 0.3:
|
||||
objects.add(det["class_name"])
|
||||
detections.append(
|
||||
{
|
||||
"class_name": det["class_name"],
|
||||
"confidence": det["confidence"],
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
"objects": list(objects),
|
||||
"detection_count": len(detections),
|
||||
}
|
||||
|
||||
|
||||
def add_yolo_metadata_to_chunks():
|
||||
"""Add YOLO metadata to all chunks"""
|
||||
yolo_data = load_yolo_data()
|
||||
|
||||
conn = psycopg2.connect(**POSTGRES_CONFIG)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Get all sentence chunks for this video
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT chunk_id, start_time, end_time
|
||||
FROM chunks
|
||||
WHERE uuid = %s AND chunk_type = 'sentence'
|
||||
ORDER BY chunk_index
|
||||
""",
|
||||
(VIDEO_UUID,),
|
||||
)
|
||||
|
||||
chunks = cur.fetchall()
|
||||
print(f"Processing {len(chunks)} chunks...")
|
||||
|
||||
for i, (chunk_id, start_time, end_time) in enumerate(chunks):
|
||||
# Get YOLO metadata for this chunk
|
||||
yolo_meta = get_chunk_yolo_metadata(yolo_data, start_time, end_time)
|
||||
|
||||
if yolo_meta["objects"]:
|
||||
# Update chunk with YOLO metadata
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE chunks
|
||||
SET metadata = COALESCE(metadata, '{}'::jsonb) || %s
|
||||
WHERE chunk_id = %s
|
||||
""",
|
||||
(json.dumps({"yolo": yolo_meta}), chunk_id),
|
||||
)
|
||||
|
||||
if (i + 1) % 100 == 0:
|
||||
print(f"Processed {i + 1}/{len(chunks)} chunks...")
|
||||
conn.commit()
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
print("Done!")
|
||||
|
||||
|
||||
def test_object_search():
|
||||
"""Test object search"""
|
||||
_ = load_yolo_data()
|
||||
|
||||
conn = psycopg2.connect(**POSTGRES_CONFIG)
|
||||
cur = conn.cursor()
|
||||
|
||||
test_objects = ["person", "car", "clock", "tie", "chair", "bottle"]
|
||||
|
||||
for obj in test_objects:
|
||||
# Count chunks with this object
|
||||
query = """
|
||||
SELECT COUNT(*)
|
||||
FROM chunks
|
||||
WHERE uuid = %s
|
||||
AND chunk_type = 'sentence'
|
||||
AND metadata IS NOT NULL
|
||||
AND metadata->'yolo'->'objects' ? %s
|
||||
"""
|
||||
cur.execute(query, (VIDEO_UUID, obj))
|
||||
count = cur.fetchone()[0]
|
||||
print(f"Object '{obj}': {count} chunks")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_yolo_metadata_to_chunks()
|
||||
print("\nTesting object search:")
|
||||
test_object_search()
|
||||
@@ -1,62 +0,0 @@
|
||||
"""YOLO judge: object detection matching against expected objects"""
|
||||
import cv2, numpy as np, re
|
||||
from ultralytics import YOLO
|
||||
|
||||
MODEL_PATH = "/Users/accusys/momentry_core_0.1/yolov8s.mlpackage"
|
||||
COCO = [
|
||||
"person","bicycle","car","motorbike","aeroplane","bus","train","truck","boat",
|
||||
"traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog",
|
||||
"horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella",
|
||||
"handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite",
|
||||
"baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle",
|
||||
"wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange",
|
||||
"broccoli","carrot","hot dog","pizza","donut","cake","chair","sofa","pottedplant",
|
||||
"bed","diningtable","toilet","tvmonitor","laptop","mouse","remote","keyboard",
|
||||
"cell phone","microwave","oven","toaster","sink","refrigerator","book","clock",
|
||||
"vase","scissors","teddy bear","hair drier","toothbrush",
|
||||
]
|
||||
|
||||
_model = None
|
||||
|
||||
def load():
|
||||
global _model
|
||||
if _model is None:
|
||||
try:
|
||||
_model = YOLO(MODEL_PATH, task="detect", verbose=False)
|
||||
except:
|
||||
_model = YOLO("yolov8s.pt")
|
||||
|
||||
def score(frames, prompt):
|
||||
load()
|
||||
prompt_lower = prompt.lower()
|
||||
|
||||
# Extract expected objects from prompt: check each COCO class (word boundary)
|
||||
expected = [c for c in COCO if re.search(r'\b' + re.escape(c) + r'\b', prompt_lower)]
|
||||
if not expected:
|
||||
expected = ["person"] # default fallback
|
||||
|
||||
results = []
|
||||
for img in frames:
|
||||
# Convert PIL to numpy
|
||||
arr = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
||||
dets = _model(arr, verbose=False, imgsz=640)
|
||||
|
||||
found = []
|
||||
if dets and len(dets) > 0 and dets[0].boxes is not None:
|
||||
for cls_id in dets[0].boxes.cls.int().tolist():
|
||||
cls_name = COCO[cls_id] if cls_id < len(COCO) else f"cls_{cls_id}"
|
||||
found.append(cls_name)
|
||||
|
||||
match = sum(1 for e in expected if e in found)
|
||||
results.append({"expected": expected, "found": found, "match_count": match, "total": len(expected)})
|
||||
|
||||
total_match = sum(r["match_count"] for r in results)
|
||||
total_expected = sum(r["total"] for r in results) or 1
|
||||
score_val = int(100 * total_match / total_expected)
|
||||
|
||||
return {
|
||||
"agent": "YOLO",
|
||||
"score": score_val,
|
||||
"reasoning": f"Found {total_match}/{total_expected} expected objects: {expected}",
|
||||
"details": {"frames": results}
|
||||
}
|
||||
Reference in New Issue
Block a user