forked from yuvraj108c/ComfyUI-Rife-Tensorrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_trt.py
More file actions
44 lines (36 loc) · 1.31 KB
/
export_trt.py
File metadata and controls
44 lines (36 loc) · 1.31 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
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import torch
import time
from trt_utilities import Engine
import tensorrt
print("Tensorrt version: ", tensorrt.__version__)
def export_trt(trt_path=None, onnx_path=None, use_fp16=True):
if trt_path is None:
trt_path = input(
"Enter the path to save the TensorRT engine (e.g ./realesrgan.engine): ")
if onnx_path is None:
onnx_path = input(
"Enter the path to the ONNX model (e.g ./realesrgan.onnx): ")
engine = Engine(trt_path)
torch.cuda.empty_cache()
s = time.time()
ret = engine.build(
onnx_path,
use_fp16,
enable_preview=True,
input_profile=[
# any sizes from 256x256 to 3840x3840, batch size 1
{
"img0": [(1, 3, 256, 256), (1, 3, 512, 512), (1, 3, 3840, 3840)],
"img1": [(1, 3, 256, 256), (1, 3, 512, 512), (1, 3, 3840, 3840)],
},
],
)
e = time.time()
print(f"Time taken to build: {(e-s)} seconds")
print(f"Tensorrt engine saved at: {trt_path}")
return ret
export_trt(trt_path="./models/rife49_ensemble_True_scale_1_sim.engine",
onnx_path="./models/rife49_ensemble_True_scale_1_sim.onnx", use_fp16=True)