forked from tensorpack/tensorpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckpoint-manipulate.py
More file actions
executable file
·36 lines (29 loc) · 1.09 KB
/
Copy pathcheckpoint-manipulate.py
File metadata and controls
executable file
·36 lines (29 loc) · 1.09 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: checkpoint-manipulate.py
# Author: Yuxin Wu <[email protected]>
import numpy as np
from tensorpack.tfutils.varmanip import dump_chkpt_vars
from tensorpack.utils import logger
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('model')
parser.add_argument('--dump', help='dump to an npz file')
parser.add_argument('--shell', action='store_true', help='start a shell with the params')
args = parser.parse_args()
if args.model.endswith('.npy'):
params = np.load(args.model, encoding='latin1').item()
elif args.model.endswith('.npz'):
params = dict(np.load(args.model))
else:
params = dump_chkpt_vars(args.model)
logger.info("Variables in the model:")
logger.info(str(params.keys()))
if args.dump:
assert args.dump.endswith('.npz'), args.dump
np.save(args.dump, **params)
if args.shell:
# params is a dict. play with it
import IPython as IP
IP.embed(config=IP.terminal.ipapp.load_default_config())