Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

fix inference loop and return all embeddings

roryclear20e4abda234c
diff --git a/clearcam.py b/clearcam.py
index a10f378..089fef0 100644
--- a/clearcam.py
+++ b/clearcam.py
@@ -467,22 +467,25 @@ class VideoCapture:
# todo, capture loop has to run fast, cannot be slown down by inference, it needs to "catch up" with latest frames
def inference_loop(self):
+ prev_time = time.time()
while self.running:
- prev_time = time.time()
+ time.sleep(1/30) # todo
if not any(counter.is_active() for _, counter in self.alert_counters.items()): # don't run inference when no active scheds
+ time.sleep(1)
with self.lock: self.last_preds = [] # to remove annotation when no alerts active
- else:
+ continue
+ with self.lock:
+ frame = self.raw_frame.copy() if self.raw_frame is not None else None
+ if frame is not None:
+ preds, frame = self.run_inference(frame, cam_name=self.cam_name)
with self.lock:
- frame = self.raw_frame.copy() if self.raw_frame is not None else None
- if frame is not None:
- preds, frame = self.run_inference(frame, cam_name=cam_name)
- with self.lock:
- self.last_preds = preds.copy()
- self.last_frame[self.cam_name] = frame.numpy().copy()
- curr_time = time.time()
- fps = 1 / (curr_time - prev_time)
- prev_time = curr_time
- print(f"\rFPS: {fps:.2f}", end="", flush=True)
+ self.last_preds = preds.copy()
+ self.last_frame[self.cam_name] = frame.numpy().copy()
+
+ curr_time = time.time()
+ fps = 1 / (curr_time - prev_time)
+ prev_time = curr_time
+ print(f"\rFPS: {fps:.2f}", end="", flush=True)
def reset_vod(self):
self.cap[self.cam_name] = cv2.VideoCapture(self.src[self.cam_name]) # reset video on settings change
diff --git a/objects.py b/objects.py
index bf2bb74..47706da 100644
--- a/objects.py
+++ b/objects.py
@@ -220,6 +220,8 @@ class ObjectFinder:
folder_paths_face[path] = path
save_embeddings(folder_path.replace("objects", "faces"), "embeddings.pkl", folder_embeddings_face, folder_paths_face)
if not self.clip: return [], []
+ emb_ret = []
+ path_ret = []
for i in range(len(new_image_list)):
img_path = new_image_list[i]
@@ -231,10 +233,12 @@ class ObjectFinder:
emb = precompute_embedding_jit_bs1(self.model, Tensor([img])).numpy()
folder_embeddings[img_path] = emb
folder_paths[img_path] = img_path
+ emb_ret.append(emb)
+ path_ret.append(img_path)
if vod: database.run_put("analysis_prog", cam_name, {"Processing":((i + 1)/len(new_image_list))*100})
print(f"Processed {len(new_image_list)} new images...")
save_embeddings(folder_path, "embeddings.pkl", folder_embeddings, folder_paths)
- return [emb], [img_path]
+ return emb_ret, path_ret
def precompute_embedding_bs1_np(self, img): return precompute_embedding_jit_bs1(self.model, Tensor(img)).numpy() # todo remove