forked from nikopueringer/CorridorKey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_vram.py
More file actions
38 lines (26 loc) · 987 Bytes
/
test_vram.py
File metadata and controls
38 lines (26 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import timeit
import numpy as np
import torch
from CorridorKeyModule.inference_engine import CorridorKeyEngine
def process_frame(engine):
img = np.random.randint(0, 255, (2160, 3840, 3), dtype=np.uint8)
mask = np.random.randint(0, 255, (2160, 3840), dtype=np.uint8)
engine.process_frame(img, mask)
def test_vram():
print("Loading engine...")
engine = CorridorKeyEngine(
checkpoint_path="CorridorKeyModule/checkpoints/CorridorKey_v1.0.pth",
img_size=2048,
device="cuda",
model_precision=torch.float16,
)
# Reset stats
torch.cuda.reset_peak_memory_stats()
iterations = 24
print(f"Running {iterations} inference passes...")
time = timeit.timeit(lambda: process_frame(engine), number=iterations)
print(f"Seconds per frame: {time / iterations}")
peak_vram = torch.cuda.max_memory_allocated() / (1024**3)
print(f"Peak VRAM used: {peak_vram:.2f} GB")
if __name__ == "__main__":
test_vram()