建筑分解:AI能记得它所见吗??

2026年8月25日2 次浏览来源:Dev.to阅读原文

正文保留英文原文(机翻易破坏代码与排版),标题/摘要已提供中文

python BEFORE: OOM in 11 seconds queue = asyncio.Queue() # No maxsize → infinite growth until death python AFTER: Hardware-bounded, fails fast on overflow self.queue = asyncio.Queue(maxsize=100) # ~1.5 MB at 224x224x3 uint8 python BGR to RGB as a zero-copy VIEW (NumPy slicing, no data movement): frame_rgb = frame[:, :, ::-1] resized = cv2.resize(frame_rgb, (224, 224), interpolation=cv2.INTER_LANCZOS4) python from concurrent.futures import ThreadPoolExecutor class AsyncExtractor: def init(self): self.executor = ThreadPoolExecutor(max_workers=2) # Hard-bound threads self.model = load_quantized_model() # 6.5 MB in uint8 quantization python import h5py from datasketch import MinHashLSH LSH index: ~100 MB RAM for 1 million embeddings lsh = MinHashLSH(threshold=0.5, num_perm=128) with h5py.File("embeddings.h5", "r") as f: for vec in f["vectors"]: lsh.insert(f"frame_{ts}", vec) python def query(timestamp, window_sec=10): """Return similar frames within a ±window around the target timestamp.""" start = timestamp - window_sec end = timestamp + window_sec # Filter HDF5 entries by time range first, then run LSH search python from collections import deque import random buffer = deque(maxlen=10_000) # Fixed size: ~150 MB at 224x224x3 uint8 for new_frame in stream: buffer.append(new_frame) if random.random() < 0.1: # 10 percent replay rate frame = buffer[random.randint(0, len(buffer) - 1)] else: frame = new_frame train_step(frame)

分享