def evaluateFile(args): hdf5_gt_file,hdf5_pred_file,threshes,funcs,save_segs,out = args hdf5_gt = h5py.File(hdf5_gt_file, 'r') hdf5_aff = h5py.File(hdf5_pred_file, 'r') gt = np.asarray(hdf5_gt[hdf5_gt.keys()[0]],dtype='uint32') aff = np.asarray(hdf5_aff[hdf5_aff.keys()[0]],dtype='float32') aff = np.transpose(aff,(1,2,3,0)) dims = np.array(aff.shape,dtype='uint32') print 'dims:',aff.shape # trim gt data - only works for perfect cubes gt_data_dimension = gt.shape[0] data_dimension = aff.shape[1] if gt_data_dimension != data_dimension: print("Data dimension do not match. Clip the GT borders.") padding = (gt_data_dimension - data_dimension) / 2 gt = gt[padding:(-1*padding),padding:(-1*padding),padding:(-1*padding)] print"New GT data shape :",gt.shape # change both to fortran order gt = np.array(gt,order='F') aff = np.array(aff,order='F') # evaluate call print "gt shape:",gt.shape print "aff shape:",aff.shape if not os.path.exists(out): os.makedirs(out) f = open(out+'info.txt', 'w') f.write('gt: '+hdf5_gt_file+'\n') f.write('pred: '+hdf5_pred_file+'\n') f.write('pred_dims: '+np.array_str(dims)) f.close() eval(gt,aff,threshes,funcs,save_segs,out)
threshes = [100+i*100 for i in range(0,10)]+[i*1000 for i in range(2,11)]+[i*10000 for i in range(2,11)] # 100...1,000...100,000 # threshes = [100+i*300 for i in range(0,4)]+[i*3000 for i in range(1,4)]+[i*30000 for i in range(2,4)] # 100...1,000...100,000 small # threshes = [i*10 for i in range(0,21)]+ [i*25000 for i in range(1,11)] print threshes save_segs = False # output folder out = 'out/test_paper/' # funcs #funcs = ['square','linear','fel','threshold','watershed','lowhigh'] funcs = ['linear','square','threshold'] # eval call gt = np.frombuffer(gt,dtype='uint32').reshape(dims[0:3]) affs = np.frombuffer(aff,dtype='float32').reshape(dims) start = time.clock() map = eval(gt,affs,threshes,funcs,save_segs,out) print "time",(time.clock()-start) # saving ''' for i in range(funcs): str = funcs[i] newFileByteArray = bytearray(map[str]) #newFile.write(newFileByteArray) '''