-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_floats.py
47 lines (40 loc) · 1.41 KB
/
extract_floats.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
38
39
40
41
42
43
44
45
46
47
'''
Created on 27 sep. 2016
@author: Robert-Jan
'''
import os, sys;
import pickle;
from tools.file import load_from_pickle_with_filename
from tools.model import constructModels;
import theano;
if __name__ == '__main__':
theano.config.floatX = 'float32';
name = sys.argv[1];
filepath = "./saved_models/%s.model" % name;
if (os.path.isfile(filepath)):
modelName = name;
result = load_from_pickle_with_filename(filepath);
if (result is not False):
savedVars, settings = result;
dataset, rnn = constructModels(settings, 0, None);
modelSet = rnn.loadVars(dict(savedVars));
if (modelSet):
modelInfo = settings;
floats = {}
for key in sorted(rnn.vars.keys()):
floats[key] = rnn.vars[key].get_value().astype('float32');
f_model = open(filepath);
_ = f_model.readline();
settingsLine = f_model.readline();
f_model.close();
f = open('./saved_models/%s.floats' % name, 'wb');
f.writelines(['###\n',settingsLine]);
pickle.dump(floats.items(),f);
f.close();
print("Success!");
else:
print("Error (3)");
else:
print("Error (2)");
else:
print("Error (1)");