Blame view
LDA/05-getscore.py
3.29 KB
b6d0165d1 Initial commit |
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 |
import numpy as np import shelve import sys import glob from collections import defaultdict from tinydb import TinyDB, Query from mako.template import Template import time def get_best(x): argbest=np.argmax(x[1]) maxdev=x[1][argbest] maxtrain=np.max(x[0]) maxtest=np.max(x[2]) besttest=x[2][argbest] return ( maxtrain,maxdev,maxtest,besttest) template = ''' ${name} ======================== LDA likelihood : ${lb} ----------------------- MLP scores : ------------------- | LDA RAW | train | dev |max test| best test| | ASR | - | ${mlp_lda_asr[0]} | - | ${mlp_lda_asr[1]} | | TRS | - | ${mlp_lda_trs[0]} | - | ${mlp_lda_trs[1]} | | AE ASR | train | dev |max test| best test| % for cpt,line in enumerate(models["AE"]["ASR"]): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor | AE TRS | train | dev |max test| best test| % for cpt,line in enumerate(models["AE"]["TRS"]): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor | AE SPE | train | dev |max test| best test| % for cpt,line in enumerate(models["AE"]["SPE"]): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor | SAE ARS | train | dev |max test| best test| % for cpt,line in enumerate(models["SAE"]['ASR']): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor | SAE TRS | train | dev |max test| best test| % for cpt,line in enumerate(models["SAE"]["TRS"]): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor | SAE SPE | train | dev |max test| best test| % for cpt,line in enumerate(models["SAE"]["SPE"]): | ${cpt} | ${line[0]} | ${line[1]} |${line[2]} | ${line[3]} | % endfor ''' # ae_model.shelve def get_folder_file(x): folder=x.split("/")[1] shelve_file = ".".join(x.split(".")[:-1]) return(folder,shelve_file) in_folder = sys.argv[1] folder_list = [ x.strip() for x in open("{}/ordered_model.txt".format(in_folder)).readlines() ][0:51] models = defaultdict(dict) db = TinyDB("{}/t4.db".format(in_folder)) for folder in folder_list : try : q = Query() lb = db.search(q.name == folder)[0]["asr"] mlp_shelve = shelve.open("{}/{}/mlp_scores.shelve".format(in_folder,folder)) mlp_lda_asr=mlp_shelve["ASR"][1] mlp_lda_trs=mlp_shelve["TRS"][1] ae_model_list = glob.glob("{}/{}/*/ae_model.shelve.dir".format(in_folder,folder)) ae_model_list= map(get_folder_file,ae_model_list) for name , shelve_file in ae_model_list : opened_shelve = shelve.open(shelve_file) working_key = None if "AE" in opened_shelve.keys(): working_key = "AE" elif "SAE" in opened_shelve.keys(): working_key = "SAE" for key in opened_shelve[working_key].keys(): models[working_key][key] = [ get_best(x) for x in opened_shelve[working_key][key] ] print(Template(template).render(name=folder,lb=lb,mlp_lda_asr=mlp_lda_asr,mlp_lda_trs=mlp_lda_trs,models=models)) except : print >>sys.stderr, "Erreur model {} ".format(folder) |