forked from rhasspy/piper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_generator.py
More file actions
56 lines (37 loc) · 1.37 KB
/
export_generator.py
File metadata and controls
56 lines (37 loc) · 1.37 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
#!/usr/bin/env python3
import argparse
import logging
from pathlib import Path
import torch
from .vits.lightning import VitsModel
_LOGGER = logging.getLogger("piper_train.export_generator")
def main():
"""Main entry point"""
parser = argparse.ArgumentParser()
parser.add_argument("checkpoint", help="Path to model checkpoint (.ckpt)")
parser.add_argument("output", help="Path to output model (.pt)")
parser.add_argument(
"--debug", action="store_true", help="Print DEBUG messages to the console"
)
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
_LOGGER.debug(args)
# -------------------------------------------------------------------------
args.checkpoint = Path(args.checkpoint)
args.output = Path(args.output)
args.output.parent.mkdir(parents=True, exist_ok=True)
model = VitsModel.load_from_checkpoint(args.checkpoint, dataset=None)
model_g = model.model_g
# Inference only
model_g.eval()
with torch.no_grad():
model_g.dec.remove_weight_norm()
model_g.forward = model_g.infer
torch.save(model_g, args.output)
_LOGGER.info("Exported model to %s", args.output)
# -----------------------------------------------------------------------------
if __name__ == "__main__":
main()