forked from Attn-to-FC/Attn-to-FC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_get_activations.py
549 lines (445 loc) · 24.3 KB
/
my_get_activations.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
from keras import models
import numpy as np
import keras.backend as K
import pickle
import random
import argparse
import os
import sys
from myutils import prep, drop, statusout, batch_gen, seq2sent, index2word, init_tf
from timeit import default_timer as timer
import tensorflow as tf
import keras
from custom.graphlayers import OurCustomGraphLayer
# get_activations and display activations based on functions from
# https://github.com/philipperemy/keras-visualize-activations
def gendescr_2inp(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, coms = list(zip(*data.values()))
tdats = np.array(tdats)
coms = np.array(coms)
for i in range(1, stopword):
results = model.predict([tdats, coms], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, coms], layer_name='activation_1')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
act1_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_3inp(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, coms, smls = list(zip(*data.values()))
tdats = np.array(tdats)
coms = np.array(coms)
smls = np.array(smls)
for i in range(1, stopword):
results = model.predict([tdats, coms, smls], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, coms, smls], layer_name='activation_1')
act2 = get_activations(model, [tdats, coms, smls], layer_name='activation_2')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'ast_activation', fid, act2_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_4inp(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, sdats, coms, smls = zip(*data.values())
tdats = np.array(tdats)
sdats = np.array(sdats)
coms = np.array(coms)
smls = np.array(smls)
for i in range(1, stopword):
results = model.predict([tdats, sdats, coms, smls], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, sdats, coms, smls], layer_name='activation_1')
act2 = get_activations(model, [tdats, sdats, coms, smls], layer_name='activation_2')
act3 = get_activations(model, [tdats, sdats, coms, smls], layer_name='activation_3')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act3_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act3-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
act3_prob_file = open(act3_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'ast_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'tdats_activation', fid, act2_prob_file, outfile, stopword)
for j in act3:
display_activations(j, 'sattn_activation', fid, act3_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
act3_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_5inp(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, sdats, coms, wsmlnodes, wsmledges = zip(*data.values())
tdats = np.array(tdats)
sdats = np.array(sdats)
coms = np.array(coms)
wsmlnodes = np.array(wsmlnodes)
wsmledges = np.array(wsmledges)
for i in range(1, stopword):
results = model.predict([tdats, sdats, coms, wsmlnodes, wsmledges], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, sdats, coms, wsmlnodes, wsmledges], layer_name='activation_1')
act2 = get_activations(model, [tdats, sdats, coms, wsmlnodes, wsmledges], layer_name='activation_2')
act3 = get_activations(model, [tdats, sdats, coms, wsmlnodes, wsmledges], layer_name='activation_3')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act3_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act3-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
act3_prob_file = open(act3_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'sdats_activation', fid, act2_prob_file, outfile, stopword)
for j in act3:
display_activations(j, 'ast_activation', fid, act3_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
act3_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_graphast(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, coms, wsmlnodes, wsmledges = zip(*data.values())
tdats = np.array(tdats)
coms = np.array(coms)
wsmlnodes = np.array(wsmlnodes)
wsmledges = np.array(wsmledges)
for i in range(1, stopword):
results = model.predict([tdats, coms, wsmlnodes, wsmledges], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, coms, smls], layer_name='activation_1')
act2 = get_activations(model, [tdats, coms, smls], layer_name='activation_2')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'ast_activation', fid, act2_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_pathast(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, sdats, coms, wsmlpaths = zip(*data.values())
tdats = np.array(tdats)
coms = np.array(coms)
sdats = np.array(sdats)
wsmlpaths = np.array(wsmlpaths)
#print(sdats)
for i in range(1, stopword):
if(config['use_sdats']):
results = model.predict([tdats, sdats, coms, wsmlpaths], batch_size=batchsize)
else:
results = model.predict([tdats, coms, wsmlpaths], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
if (config['use_sdats']):
act1 = get_activations(model, [tdats, sdats, coms, wsmlpaths], layer_name='activation_1')
act2 = get_activations(model, [tdats, sdats, coms, wsmlpaths], layer_name='activation_2')
act3 = get_activations(model, [tdats, sdats, coms, wsmlpaths], layer_name='activation_3')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act3_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act3-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
act3_prob_file = open(act3_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'sdats_activation', fid, act2_prob_file, outfile, stopword)
for j in act3:
display_activations(j, 'ast_activation', fid, act3_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
act3_prob_file.close()
else:
act1 = get_activations(model, [tdats, coms, wsmlpaths], layer_name='activation_1')
act2 = get_activations(model, [tdats, coms, wsmlpaths], layer_name='activation_2')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'ast_activation', fid, act2_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def gendescr_threed(model, data, comstok, comlen, batchsize, config, strat, beamwidth, outfile, stopword):
# right now, only greedy search is supported...
fid = [*data.keys()]
tdats, sdats, coms = zip(*data.values())
tdats = np.array(tdats)
sdats = np.array(sdats)
coms = np.array(coms)
for i in range(1, stopword):
results = model.predict([tdats, sdats, coms], batch_size=batchsize)
for c, s in enumerate(results):
coms[c][i] = np.argmax(s)
act1 = get_activations(model, [tdats, sdats, coms], layer_name='activation_1')
act2 = get_activations(model, [tdats, sdats, coms], layer_name='activation_2')
act1_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act1-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act2_softmax_val_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-act2-stopword-{}.txt'.format(fid[0], outfile.split('.')[0], stopword)
act1_prob_file = open(act1_softmax_val_path, 'w')
act2_prob_file = open(act2_softmax_val_path, 'w')
for j in act1:
display_activations(j, 'tdats_activation', fid, act1_prob_file, outfile, stopword)
for j in act2:
display_activations(j, 'sdats_activation', fid, act2_prob_file, outfile, stopword)
act1_prob_file.close()
act2_prob_file.close()
final_data = {}
for fid, com in zip(data.keys(), coms):
final_data[fid] = seq2sent(com, comstok)
return final_data
def get_activations(model, model_inputs, print_shape_only=True, layer_name=None):
print('----- activations -----')
activations = []
inp = model.input
model_multi_inputs_cond = True
if not isinstance(inp, list):
# only one input! let's wrap it in a list.
inp = [inp]
model_multi_inputs_cond = False
outputs = [layer.output for layer in model.layers if layer.name == layer_name or layer_name is None] # all layer outputs
funcs = [K.function(inp + [K.learning_phase()], [out]) for out in outputs] # evaluation functions
if model_multi_inputs_cond:
list_inputs = []
list_inputs.extend(model_inputs)
list_inputs.append(0.)
else:
list_inputs = [model_inputs, 0.]
layer_outputs = [func(list_inputs)[0] for func in funcs]
for layer_activations in layer_outputs:
activations.append(layer_activations)
if print_shape_only:
print(layer_activations.shape)
else:
print(layer_activations)
return activations
def display_activations(activation_maps, title, fid_list, act_prob_file, outfile, stopword):
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (80, 12)
for i, activation_map in enumerate(activation_maps):
fid = fid_list[i]
img_path = '/nfs/projects/attn-to-fc/data/outdir/viz/{}-{}-{}-stopword-{}.pdf'.format(fid, outfile.split('.')[0], title, stopword)
act_prob_file.write(str(fid)+'\t'+str(activation_map)+'\n')
activation_map = np.expand_dims(activation_map, axis=0)
batch_size = activation_map.shape[0]
assert batch_size == 1, 'One image at a time to visualize.'
print('Displaying activation map {}'.format(i))
shape = activation_map.shape
plt.imshow(activation_map[0], interpolation='nearest')
plt.title(title)
plt.savefig(img_path)
cmd = "xpdf {} &".format(img_path)
os.system(cmd)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='')
parser.add_argument('modelfilewsdats', type=str, default=None)
parser.add_argument('modelfilewosdats', type=str, default=None)
parser.add_argument('--fid', type=int, default=None)
parser.add_argument('--stopword', type=int, default=None)
parser.add_argument('--num-procs', dest='numprocs', type=int, default='4')
parser.add_argument('--gpu', dest='gpu', type=str, default='')
parser.add_argument('--data1', dest='dataprep', type=str, default='/nfs/projects/attn-to-fc/data/standard')
parser.add_argument('--data2', dest='dataprep2', type=str, default='/nfs/projects/attn-to-fc/data/standard')
parser.add_argument('--outdir', dest='outdir', type=str, default='/nfs/projects/attn-to-fc/data/outdir')
parser.add_argument('--batch-size', dest='batchsize', type=int, default=200)
parser.add_argument('--num-inputs', dest='numinputs', type=int, default=3)
parser.add_argument('--model-type', dest='modeltype', type=str, default=None)
parser.add_argument('--strat', dest='strat', type=str, default='greedy')
parser.add_argument('--beam-width', dest='beamwidth', type=int, default=1)
parser.add_argument('--zero-dats', dest='zerodats', action='store_true', default=False)
parser.add_argument('--dtype', dest='dtype', type=str, default='float32')
parser.add_argument('--tf-loglevel', dest='tf_loglevel', type=str, default='3')
args = parser.parse_args()
outdir = args.outdir
dataprep = args.dataprep
dataprep2 = args.dataprep2
modelfilewsdats = args.modelfilewsdats
modelfilewosdats = args.modelfilewosdats
fid = args.fid
stopword = args.stopword
numprocs = args.numprocs
gpu = args.gpu
batchsize = args.batchsize
num_inputs = args.numinputs
modeltype = args.modeltype
strat = args.strat
beamwidth = args.beamwidth
zerodats = args.zerodats
outfilewsdats = modelfilewsdats.split('/')[-1]
outfilewosdats = modelfilewosdats.split('/')[-1]
K.set_floatx(args.dtype)
os.environ['CUDA_VISIBLE_DEVICES'] = gpu
os.environ['TF_CPP_MIN_LOG_LEVEL'] = args.tf_loglevel
sys.path.append(dataprep)
import tokenizer
prep('loading tokenizers... ')
tdatstok = pickle.load(open('%s/tdats.tok' % (dataprep), 'rb'), encoding='UTF-8')
comstok = pickle.load(open('%s/coms.tok' % (dataprep), 'rb'), encoding='UTF-8')
smltok = pickle.load(open('%s/smls.tok' % (dataprep), 'rb'), encoding='UTF-8')
drop()
prep('loading sequences... ')
seqdata = pickle.load(open('%s/dataset.pkl' % (dataprep), 'rb'))
drop()
if zerodats:
v = np.zeros(100)
for key, val in seqdata['dttrain'].items():
seqdata['dttrain'][key] = v
for key, val in seqdata['dtval'].items():
seqdata['dtval'][key] = v
for key, val in seqdata['dttest'].items():
seqdata['dttest'][key] = v
allfids = list(seqdata['ctest'].keys())
datvocabsize = tdatstok.vocab_size
comvocabsize = comstok.vocab_size
smlvocabsize = smltok.vocab_size
datlen = len(seqdata['dttest'][list(seqdata['dttest'].keys())[0]])
comlen = len(seqdata['ctest'][list(seqdata['ctest'].keys())[0]])
#smllen = len(seqdata['stest'][list(seqdata['stest'].keys())[0]])
if stopword is None:
stopword=comlen
prep('loading config... ')
(modeltypewsdats, mwsdatsid, timestartwsdats) = modelfilewsdats.split('_')
(timestartwsdats, extwsdats) = timestartwsdats.split('.')
modeltypewsdats = modeltypewsdats.split('/')[-1]
configwsdats = pickle.load(open('/nfs/projects/attn-to-fc/data/outdir/histories/'+modeltypewsdats+'_conf_'+timestartwsdats+'.pkl', 'rb'))
num_inputswsdats = configwsdats['num_input']
(modeltypewosdats, mwosdatsid, timestartwosdats) = modelfilewosdats.split('_')
(timestartwosdats, extwosdats) = timestartwosdats.split('.')
modeltypewosdats = modeltypewosdats.split('/')[-1]
configwosdats = pickle.load(open('/nfs/projects/attn-to-fc/data/outdir/histories/'+modeltypewosdats+'_conf_'+timestartwosdats+'.pkl', 'rb'))
num_inputswosdats = configwosdats['num_input']
drop()
prep('loading model... ')
modelwsdats = keras.models.load_model(modelfilewsdats, custom_objects={"tf":tf, "keras":keras, "OurCustomGraphLayer":OurCustomGraphLayer})
modelwosdats = keras.models.load_model(modelfilewosdats, custom_objects={"tf":tf, "keras":keras, "OurCustomGraphLayer":OurCustomGraphLayer})
print(modelwsdats.summary())
print(modelwosdats.summary())
drop()
comstart = np.zeros(comlen)
stk = comstok.w2i['<s>']
comstart[0] = stk
batch_sets=[[fid]]
# cmd = "grep {} /nfs/projects/attn-to-fc/data/outdir/viz/diff_exp_sys2.txt".format(fid)
# os.system(cmd)
# print()
# cmd = "grep {} /nfs/projects/attn-to-fc/data/standard/output/coms.test".format(fid)
# print('coms for {}'.format(fid))
# os.system(cmd)
# print()
# cmd = "grep {} /nfs/projects/attn-to-fc/data/standard/output/tdats.test".format(fid)
# print('tdats for {}'.format(fid))
# os.system(cmd)
# print()
# cmd = "grep {} /nfs/projects/attn-to-fc/data/standard/output/sdats.test".format(fid)
# print('sdats for {}'.format(fid))
# os.system(cmd)
# print()
prep("computing predictions...\n")
for c, fid_set in enumerate(batch_sets):
st = timer()
for fid in fid_set:
seqdata['ctest'][fid] = comstart #np.asarray([stk])
bg = batch_gen(seqdata, 'test', configwsdats, training=False)
batch = bg.make_batch(fid_set)
if configwsdats['batch_maker'] == 'datsonly':
batch_resultswsdats = gendescr_2inp(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif configwsdats['batch_maker'] == 'ast':
batch_resultswsdats = gendescr_3inp(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif configwsdats['batch_maker'] == 'ast_threed':
batch_resultswsdats = gendescr_4inp(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif configwsdats['batch_maker'] == 'threed':
batch_resultswsdats = gendescr_threed(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif configwsdats['batch_maker'] == 'graphast':
batch_resultswsdats = gendescr_graphast(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif configwsdats['batch_maker'] == 'graphast_threed':
batch_resultswsdats = gendescr_5inp(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
elif config['batch_maker'] == 'pathast_threed':
batch_results = gendescr_pathast(modelwsdats, batch, comstok, comlen, batchsize, configwsdats, strat, beamwidth, outfilewsdats, stopword)
else:
print('error: invalid batch maker')
sys.exit()
for key, val in batch_resultswsdats.items():
print("{}\t{}\n".format(key, val))
end = timer ()
print("{} processed, {} per second this batch".format((c+1)*batchsize, batchsize/(end-st)))
prep('loading sequences... ')
seqdata = pickle.load(open('%s/dataset.pkl' % (dataprep2), 'rb'))
drop()
prep("computing predictions...\n")
for c, fid_set in enumerate(batch_sets):
st = timer()
for fid in fid_set:
seqdata['ctest'][fid] = comstart #np.asarray([stk])
bg = batch_gen(seqdata, 'test', configwosdats, training=False)
batch = bg.make_batch(fid_set)
if configwosdats['batch_maker'] == 'datsonly':
batch_resultswosdats = gendescr_2inp(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif configwosdats['batch_maker'] == 'ast':
batch_resultswosdats = gendescr_3inp(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif configwosdats['batch_maker'] == 'ast_threed':
batch_resultswosdats = gendescr_4inp(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif configwosdats['batch_maker'] == 'threed':
batch_resultswosdats = gendescr_threed(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif configwosdats['batch_maker'] == 'graphast':
batch_resultswosdats = gendescr_graphast(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif configwosdats['batch_maker'] == 'graphast_threed':
batch_resultswosdats = gendescr_5inp(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
elif config['batch_maker'] == 'pathast_threed':
batch_results = gendescr_pathast(modelwosdats, batch, comstok, comlen, batchsize, configwosdats, strat, beamwidth, outfilewosdats, stopword)
else:
print('error: invalid batch maker')
sys.exit()
for key, val in batch_resultswosdats.items():
print("{}\t{}\n".format(key, val))
end = timer ()
print("{} processed, {} per second this batch".format((c+1)*batchsize, batchsize/(end-st)))
drop()