Skip to content

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

test different clip batch size speeds

roryclear24e237bf5e05
diff --git a/test/run_clip.py b/test/run_clip.py
new file mode 100644
index 0000000..60faa7f
--- /dev/null
+++ b/test/run_clip.py
@@ -0,0 +1,18 @@
+from tinygrad import Tensor, TinyJit
+from objects import ObjectFinder, precompute_embeddings_jit, precompute_embedding_jit_bs1, preprocess
+import time
+import numpy as np
+import sys
+
+def teset_clip_jit(bs=1):
+ input1 = np.random.rand(bs, 3, 224, 224).astype(np.float32)
+ fun = precompute_embedding_jit_bs1 if bs == 1 else precompute_embeddings_jit
+ for _ in range(3): _ = fun(clip.model, Tensor(input1)).numpy()
+ ts = time.time()
+ _ = fun(clip.model, Tensor(input1)).numpy()
+ print(f"time (bs={bs}) =",round((time.time() - ts) / bs, 2), "seconds")
+
+if __name__ == "__main__":
+ clip = ObjectFinder(clip=True)
+ bs = int(sys.argv[1])
+ teset_clip_jit(bs=bs)
\ No newline at end of file
diff --git a/test/test_clip.py b/test/test_clip.py
index 25eef74..f222420 100644
--- a/test/test_clip.py
+++ b/test/test_clip.py
@@ -3,14 +3,8 @@ import numpy as np
from tinygrad import Tensor
import time
import cv2
-
-def teset_clip_jit(bs=1):
- input1 = np.random.rand(bs, 3, 224, 224).astype(np.float32)
- fun = precompute_embedding_jit_bs1 if bs == 1 else precompute_embeddings_jit
- for _ in range(3): _ = fun(clip.model, Tensor(input1)).numpy()
- ts = time.time()
- _ = fun(clip.model, Tensor(input1)).numpy()
- print(f"time (bs={bs}) =",round((time.time() - ts), 2), "seconds")
+import subprocess
+import sys
def test_clip_outputs():
img1 = cv2.imread("test/clip_images/f40.jpg")
@@ -21,9 +15,9 @@ def test_clip_outputs():
np.testing.assert_allclose(0.330654, sim, rtol=1e-6, atol=1e-6)
if __name__ == "__main__":
+ # todo sepatate test for egpu?
clip = ObjectFinder(clip=True)
test_clip_outputs()
- teset_clip_jit()
- teset_clip_jit(bs=16)
+ for i in range(8): subprocess.run([sys.executable, "test/run_clip.py", str(2**i)], check=True)