def Assign(i,lhs,rhs): ## Preprocessing: ll = base.load('assign.ll') ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${memlhs}',lhs) code = code.replace('${memrhs}',rhs) return code
def If(i,cond,if_body,else_body): ## Preprocessing: ll = base.load('If.ll') ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${cond}',cond) code = code.replace('${if_body}',if_body) code = code.replace('${else_body}',else_body) return code
def Num(i, Num, begin_annotation=";START"): ## Preprocessing: ll = base.load("Num.ll", begin_annotation) ## Processing: # ------------------------------------------------------------------- code = "".join(ll) code = code.replace("<i>", "%s" % i) code = code.replace("${Num}", str(Num)) out = "memz_%s" % i return out, code
def corr(self): self.set_subset('silhouette') df = self.acc_single() df['dataset'] = 'silhouette' human = base.load(pref='preds', exp=self.exp, suffix='human') df['human_accuracy'] = np.nan n = len(df.dataset.unique()) mean_acc = human[human.kind == 'silhouette'].groupby('no').acc.mean() df.loc[:, 'human_accuracy'] = mean_acc.tolist() * n df = df[df.sel] df.model_accuracy = df.model_accuracy.astype(int) sns.set_palette(sns.color_palette('Set2')[1:]) self._corr(df, 'all')
def While(i,cond,test_body,body): ## Preprocessing: ll = base.load('while.ll') ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${cond}',cond) code = code.replace('${test_body}',test_body) code = code.replace('${body}',body) return code
def Module(i,modName,body,begin_annotation = ';START'): ## Preprocessing: ll = base.load('module.ll',begin_annotation) ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${modname}',modName) code = code.replace('${body}',body) return code
def corr(self): self.set_subset('silhouette') df = self.acc_single() df['dataset'] = 'silhouette' human = base.load(pref='preds', exp=self.exp, suffix='human') df['human_accuracy'] = np.nan n = len(df.dataset.unique()) mean_acc = human[human.kind=='silhouette'].groupby('no').acc.mean() df.loc[:,'human_accuracy'] = mean_acc.tolist() * n df = df[df.sel] df.model_accuracy = df.model_accuracy.astype(int) sns.set_palette(sns.color_palette('Set2')[1:]) self._corr(df, 'all')
def logicNot(i,x,begin_annotation = ';START'): ## Preprocessing: ll = base.load('logicNot.ll',begin_annotation) ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${memx}',x) out = 'memz_%s'%i return out,code
def pred_corr(self, value='accuracy', method='corr'): human = base.load(pref='preds', exp=self.exp, suffix='human') human = human.groupby(['kind', 'no']).acc.mean() dfs = [] for subset in ORDER: self.set_subset(subset) df = self._pred_corr(human.loc[subset], value=value, method=method) df['dataset'] = subset dfs.append(df) df = pandas.concat(dfs, ignore_index=True) print(df.groupby('dataset').mean()) if self.task == 'run': self.plot_single(df, 'pred_corr') return df
def logical(i,x,y,op,begin_annotation = ';START'): ## Preprocessing: ll = base.load('logical.ll',begin_annotation) ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${memx}',x) code = code.replace('${memy}',y) code = code.replace('${op}', opMap[op]) out = 'memz_%s'%i return out,code
def compare(i,x,y,op,begin_annotation = ';START'): ## Preprocessing: ll = base.load('comp.ll',begin_annotation) ## Processing: #------------------------------------------------------------------- code = ''.join(ll) code = code.replace('<i>','%s'%i) code = code.replace('${memx}',x) code = code.replace('${memy}',y) code = code.replace('${opi}', opMap[op][0]) code = code.replace('${opf}', opMap[op][1]) out = 'memz_%s'%i return out,code
def behav(self): self.model_name = 'behav' human = base.load(pref='preds', exp=self.exp, suffix='human') sil = pandas.read_csv('snodgrass/data/sil_human_acc.csv', header=None) / 100. sil2 = human.groupby(['kind', 'no']).acc.mean() corr = np.corrcoef(sil.values.ravel(), sil2['silhouette'].values)[0,1] cons = 1 - scipy.spatial.distance.sqeuclidean(sil.values.ravel(), sil2['silhouette'].values) / 260 sel, _ = self.filter_synset_ids() human = human[human.synset_id.isin(sel)] if self.task == 'run': sns.factorplot('kind', 'acc', data=human, units='subjid', kind='bar', color=self.colors['shape']) self.show(pref='acc') self.html.writetable(human.groupby('kind').acc.mean()) self.html.write('<p>Correlation old-new: {:.2f}</p>'.format(corr)) self.html.write('<p>Consistency old-new: {:.2f}</p>'.format(cons)) return human
def cprint(i,args): ## Preprocessing: ll = base.load('print.ll') ## Processing: #------------------------------------------------------------------- code = ''.join(ll) arglist = '' loader = '' for j,arg in enumerate(args): loader += '%%arg%s_%s.TYPE = load i32* %%%s.TYPE'%(j+1,i,arg) loader += '%%arg%s_%s.n = load i64* %%%s.n'%(j+1,i,arg) arglist+=',i32 %%arg%s_%s.TYPE'%(j+1,i) arglist+=',i64 %%arg%s_%s.n'%(j+1,i) print len(args) code = loader + code.replace('${args}','i32 %s %s'%(len(args),arglist)) return code
def behav(self): self.model_name = 'behav' human = base.load(pref='preds', exp=self.exp, suffix='human') sil = pandas.read_csv('snodgrass/data/sil_human_acc.csv', header=None) / 100. sil2 = human.groupby(['kind', 'no']).acc.mean() corr = np.corrcoef(sil.values.ravel(), sil2['silhouette'].values)[0, 1] cons = 1 - scipy.spatial.distance.sqeuclidean( sil.values.ravel(), sil2['silhouette'].values) / 260 sel, _ = self.filter_synset_ids() human = human[human.synset_id.isin(sel)] if self.task == 'run': sns.factorplot('kind', 'acc', data=human, units='subjid', kind='bar', color=self.colors['shape']) self.show(pref='acc') self.html.writetable(human.groupby('kind').acc.mean()) self.html.write('<p>Correlation old-new: {:.2f}</p>'.format(corr)) self.html.write('<p>Consistency old-new: {:.2f}</p>'.format(cons)) return human
import sys import base for k, v in base.load().iteritems(): setattr(sys.modules[__name__], k, v)
import cv2 from segmentation import kmeans from models import Image from segmentation import remove_red_cells from segmentation import background_removal from base import load from segmentation import otsu from matplotlib import pyplot as plt import numpy as np from math import sqrt path = 'bases/ALL_IDB1/' images = load(path) #images = [images[3]] for image in images: lab_image = cv2.cvtColor(image.image, cv2.COLOR_BGR2LAB) hsv_image = cv2.cvtColor(image.image, cv2.COLOR_BGR2HSV) yuv_image = cv2.cvtColor(image.image, cv2.COLOR_BGR2YUV) gray_image = cv2.cvtColor(image.image, cv2.COLOR_BGR2GRAY) blue, green, red = cv2.split(image.image) hue, saturation, value = cv2.split(hsv_image) l, a, b = cv2.split(lab_image) y, u, v = cv2.split(yuv_image) ''' #cv2.imwrite('temp/temp/blue_' + image.name, blue) cv2.imwrite('temp/temp/green_' + image.name, green) #cv2.imwrite('temp/temp/red_' + image.name, red) cv2.imwrite('temp/temp/hue_' + image.name, hue) cv2.imwrite('temp/temp/saturation_' + image.name, saturation) #cv2.imwrite('temp/temp/value_' + image.name, value)
def _makeobj(self, key): obj = self._model() r = redis_connection() res = r.get(key) if res: obj.__dict__.update( load(res)) return obj