-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inference.py
More file actions
70 lines (52 loc) · 1.81 KB
/
test_inference.py
File metadata and controls
70 lines (52 loc) · 1.81 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import torch
import time
import os
import sys
os.add_dll_directory(r"C:\AI_model\lada\build\gtk\x64\release\bin")
from lada.lib.frame_restorer import load_models
from lada.basicvsrpp.inference import load_model, get_default_gan_inference_config
mosaic_restoration_model_path = "C:/AI_model/lada/lada/model_weights/lada_mosaic_restoration_model_generic_v1.2.pth"
#torch.backends.cudnn.enabled = False
print(f"cudnn: {torch.backends.cudnn.enabled}")
config = get_default_gan_inference_config()
mosaic_restoration_model = load_model(config, mosaic_restoration_model_path, "cuda:0")
model = mosaic_restoration_model
#print(model)
randn_input = []
for i in range(4):
randn_input.append(torch.randn(1, 180, 3, 256, 256))
for i in range(4):
randn_input[i] = randn_input[i].to("cuda")
print("Loaded input:", randn_input[0].shape)
model.eval()
batch_start = time.time()
print(randn_input[0].dtype)
for i in range(4):
start = time.time()
with torch.no_grad():
output = model(inputs=randn_input[i].to("cuda"))
torch.cuda.synchronize()
end = time.time()
print(f"{i+1} Round: {end-start} seconds")
#time.sleep(2)
print("Output shape:", output.shape)
end = time.time()
print(f"Batch Time: {end-batch_start} seconds")
half_model = model.to("cuda").eval().half()
half_radn_input = randn_input[0].to("cuda").half()
batch_start = time.time()
print(half_radn_input.dtype)
torch.cuda.synchronize()
for i in range(4):
start = time.time()
with torch.no_grad():
output = half_model(inputs=half_radn_input.to("cuda"))
torch.cuda.synchronize()
end = time.time()
print(f"{i+1} Round: {end-start} seconds")
print("Output shape:", output.shape)
end = time.time()
print(f"Batch Time: {end-batch_start} seconds")
del model
del mosaic_restoration_model
torch.cuda.empty_cache()