-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconvert_model.py
37 lines (29 loc) · 1.31 KB
/
convert_model.py
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
# coding=utf-8
import logging
import torch
import utils
from models.reinvent import Vocabulary, Model
def main():
parser = utils.UnderscoreArgumentParser(
description="Converts the old model format with separate vocabulary file to the "
"new single file format")
parser.add_argument("--input-model", '-i', help='The model.ckpt to read',
type=str, required=True)
parser.add_argument("--vocabulary", "-v", help='The used vocabulary',
type=str, required=True)
parser.add_argument("--output-model", '-o', help='Path were to save the new model',
type=str, required=True)
args = parser.parse_args()
# setup the logger to get a nice output
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s: %(module)s.%(funcName)s +%(lineno)s: %(levelname)-8s %(message)s',
datefmt='%H:%M:%S'
)
voc = Vocabulary()
voc.init_from_voc_file(args.vocabulary)
initial_weights = torch.load(args.input_model)
model = Model(voc, initialweights=initial_weights)
model.save(args.output_model)
logging.info("Model saved. You can now remove the old model and vocabulary")
if __name__ == "__main__":
main()