forked from facebookresearch/denoiser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrt_optim.py
More file actions
31 lines (22 loc) · 666 Bytes
/
trt_optim.py
File metadata and controls
31 lines (22 loc) · 666 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
import argparse
import os
import torch
from torch2trt import torch2trt
from denoiser.pretrained import add_model_flags, get_model
def convert(args):
model = get_model(args)
model = model.cuda().eval().half()
print(model)
# dummy input
data = torch.zeros((1, 1, 256)).cuda().half()
# print(model(data))
print("Optimizing model...")
model_trt = torch2trt(model, [data], fp16_mode=True)
torch.save(model_trt.state_dict(), "trt-model.pth")
def parse_args():
parser = argparse.ArgumentParser()
add_model_flags(parser)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
convert(args)