too lazy to fix merge conflict, fix it if you need this later probably easier to just rewrite from scratch <<<<<<< HEAD import numpy as np x = raw_input('use esp game dataset?') if x == 'y': from galatea.esp import Im2Word dataset = Im2Word(start=99000, stop=100000 ) else: from galatea.esp import FinalIm2Word dataset = FinalIm2Word() x = raw_input('use people?') people_mask = np.zeros((dataset.y.shape[0],), dtype='bool') for word in ['face', 'person', 'people', 'man', 'men', 'woman', 'women', 'child', 'children', 'kid', 'kids', 'guy', 'boy', 'boys', 'girl', 'girls', 'infant', 'infants', 'baby', 'babies']: if word not in dataset.words: continue idx = dataset.words.index(word) mask = dataset.y[:,idx].astype('bool') people_mask = people_mask | mask if x == 'y': mask = people_mask
from galatea.esp import FinalIm2Word import numpy as np dataset = FinalIm2Word(start=0, stop=500 ) max_word = 50 dataset.y = dataset.y[:, 0:max_word] from pylearn2.utils import serial model = serial.load('rectifier_7.pkl') last_layer = model.layers[-1] last_layer.b.set_value(last_layer.b.get_value()[0:max_word]) W, = last_layer.transformer.get_params() W.set_value(W.get_value()[:,0:max_word]) import theano.tensor as T X = T.matrix() X.tag.test_value = dataset.X state = model.fprop(X) target = T.matrix() target.tag.test_value = dataset.y wrong_target = T.matrix() wrong_target.tag.test_value = dataset.y right_cost = model.layers[-1].kl(Y=target, Y_hat=state) wrong_cost = model.layers[-1].kl(Y=wrong_target, Y_hat=state)
from galatea.esp import FinalIm2Word valid = FinalIm2Word() from pylearn2.utils import serial model = serial.load('rectifier_7.pkl') import theano.tensor as T X = T.matrix() state = model.fprop(X) target = T.matrix() y_hat = state > 0.5 y = target > 0.5 y = T.cast(y, state.dtype) y_hat = T.cast(y_hat, state.dtype) tp = (y * y_hat).sum(axis=0) fp = ((1 - y) * y_hat).sum(axis=0) precision = tp / T.maximum(1., tp + fp) recall = tp / T.maximum(1., y.sum(axis=0)) f1 = 2. * precision * recall / T.maximum(1, precision + recall) from theano import function ttp = tp.sum() tpredp = y.sum()
from galatea.esp import FinalIm2Word import numpy as np dataset = FinalIm2Word(start=00, stop=1000) from pylearn2.utils import serial model = serial.load('rectifier_7_best.pkl') import theano.tensor as T X = T.matrix() state = model.fprop(X) target = T.matrix() wrong_target = T.matrix() right_cost = model.layers[-1].kl(Y=target, Y_hat=state) wrong_cost = model.layers[-1].kl(Y=wrong_target, Y_hat=state) acc = (wrong_cost > right_cost).mean() from theano import function f = function([X, target, wrong_target], acc) wrong_target = dataset.y.copy() used = np.zeros((dataset.y.shape[0], ), dtype='bool') minmin = np.inf for i in xrange(wrong_target.shape[0]): dists = np.square(dataset.y - dataset.y[i, :]).sum(axis=1) dists[i] = np.inf dists[used] = np.inf