perf(simulation): cache SAM3 text and retain exact perception evidence
This commit is contained in:
@@ -15,6 +15,7 @@ from pathlib import Path
|
||||
|
||||
from navigation_client import NavigationClient
|
||||
from realtime_ai import EvidenceWriter
|
||||
from k1link.simulation.ai_polygon.perception_evidence import archive_perception
|
||||
|
||||
|
||||
class ContinuousPipeline:
|
||||
@@ -187,6 +188,7 @@ class ContinuousPipeline:
|
||||
if extra is not None:
|
||||
Image.fromarray(extra["rgb"]).save(
|
||||
self.directory/f"{frame:08d}.supplement.jpg", quality=90)
|
||||
exact_evidence = archive_perception(self.directory, result)
|
||||
journal.write(json.dumps(dict(frame_id=frame, captured_at=observation["captured_at"],
|
||||
completed_at=result["completed_at"], started_at=started,
|
||||
module_ms=result["module_ms"], semantic_observations=result["semantic_observations"],
|
||||
@@ -196,7 +198,8 @@ class ContinuousPipeline:
|
||||
for view in result.get("detection_views", [])],
|
||||
sensor_timing_ms=observation.get("sensor_timing_ms"),
|
||||
acquisition_age_ms=(started-observation["captured_at"])*1000,
|
||||
archive_ms=(self.clock()-now)*1000, view="body-forward"))+"\n")
|
||||
archive_ms=(self.clock()-now)*1000, view="body-forward",
|
||||
exact_evidence=exact_evidence))+"\n")
|
||||
journal.flush()
|
||||
self.writer.submit(frame, archive)
|
||||
# The writer owns this stream until the final outstanding packet.
|
||||
|
||||
@@ -11,7 +11,9 @@ from PIL import Image
|
||||
import sam3.model_builder as builder
|
||||
from sam3.model.sam3_image_processor import Sam3Processor
|
||||
|
||||
from k1link.simulation.ai_polygon.concept_surfaces import PROMPTS, concept_rasters
|
||||
from k1link.simulation.ai_polygon.concept_surfaces import (
|
||||
PROMPTS, FixedConceptTextEncoder, concept_rasters,
|
||||
)
|
||||
|
||||
|
||||
def load_exact(model, path):
|
||||
@@ -51,6 +53,10 @@ def main():
|
||||
or any(type(x) not in (int, float) or not 0 < x < 1
|
||||
for x in thresholds.values())):
|
||||
raise ValueError("Invalid concept confidence thresholds")
|
||||
# Encoding depends only on these fixed prompts and the immutable weights.
|
||||
# Warmup below populates the bounded cache under the same inference/autocast
|
||||
# context as live frames. Image features and masks are never cached.
|
||||
model.backbone.forward_text = FixedConceptTextEncoder(model.backbone.forward_text, "cuda")
|
||||
processor = Sam3Processor(model, device="cuda", confidence_threshold=min(thresholds.values()))
|
||||
|
||||
def infer(rgb):
|
||||
|
||||
Reference in New Issue
Block a user