04-accuracyscore.py 2.1 KB
# coding: utf-8

# In[2]:

# Import
import gensim
from scipy import sparse
import numpy as np
import itertools
from sklearn import preprocessing
from keras.models import Sequential
from keras.optimizers import SGD,Adam
from keras.layers.advanced_activations import ELU,PReLU
from keras.callbacks import ModelCheckpoint
from mlp import *
from  sklearn import metrics
from sklearn.preprocessing import LabelBinarizer
import shelve
import pickle
from utils import *
import sys
import os
import json

# In[4]:

in_dir = sys.argv[1]
#['ASR', 'TRS', 'LABEL']
# In[6]:
json_conf =json.load(open(sys.argv[2]))

name = json_conf["name"]

db = shelve.open("{}/{}/labels.shelve".format(in_dir,name))
#
keys = sorted(db.keys())
keys.remove("IDS")
keys.remove("transfert")
keys.remove("LABEL")
mods = ["ASR", "TRS"]
ref_train = db["LABEL"]["ASR"]["TRAIN"]
ref_dev = db["LABEL"]["ASR"]["DEV"]
ref_test = db["LABEL"]["ASR"]["TEST"]

print "name,MOD,level,train,dev,test"
for mod in mods : 
    for lvl in keys :
        if "TEST" in db[lvl][mod] :
            train_score = metrics.accuracy_score(np.argmax(ref_train,axis=1),db[lvl][mod]["TRAIN"])
            dev_score = metrics.accuracy_score(np.argmax(ref_dev,axis=1),db[lvl][mod]["DEV"])
            test_score = metrics.accuracy_score(np.argmax(ref_test,axis=1),db[lvl][mod]["TEST"])
        else :
            train_score = "ERROR"
            dev_score = "ERROR"
            test_score = "ERROR"
        print ",".join([name,mod, lvl, str(train_score), str(dev_score) , str(test_score)])

for level in db["transfert"].keys() :
    for layer in  db["transfert"][level].keys():
        if "TRAIN" in db["transfert"][level][layer].keys():

            train_score = metrics.accuracy_score(np.argmax(ref_train,axis=1),db["transfert"][level][layer]["TRAIN"])
            dev_score = metrics.accuracy_score(np.argmax(ref_dev,axis=1),db["transfert"][level][layer]["DEV"])
            test_score = metrics.accuracy_score(np.argmax(ref_test,axis=1),db["transfert"][level][layer]["TEST"])
            print ",".join([name,"transfert",level+"/"+layer, str(train_score), str(dev_score) , str(test_score)])

db.close()