def save_quality_values(predict_path, gt_path, dense_gt_path, outpath, slices, minMemb=10, minSeg=10, sigMin=6, sigWeights=1, sigSmooth=0.1,edgeLengths=None, nodeFeatures=None, nodeSizes=None, nodeLabels=None, nodeNumStop=None, beta=0, metric='l1', wardness=0.2, out=None): """ """ #read predict and groundtruth data predict_data = read_h5(predict_path, "exported_data") gt_data = read_h5(gt_path) dense_gt_data = read_h5(dense_gt_path) nodes_in_dgt = np.unique(dense_gt_data) nodeNumStop = nodes_in_dgt print "nodeNumStop", nodeNumStop #all_quality_data = get_quality_values(predict_data, gt_data, dense_gt_data) #get quality values acc, prec, rec, auc_score, ri, voi, tp, fp, tn, fn, wsDt_data, agglCl_data = get_quality_values(predict_data, gt_data, dense_gt_data, minMemb, minSeg, sigMin, sigWeights, sigSmooth, edgeLengths, nodeFeatures, nodeSizes, nodeLabels, nodeNumStop, beta, metric, wardness, out) measurements = {"accuracy":acc, "precision":prec, "recall":rec, "auc score":auc_score, "rand index":ri, "variation of information":voi, "true positives":tp, "false positives":fp, "true negatives":tn, "false negatives":fn} # acc, prec, rec, auc_score, tp, fp, tn, fn, wsDt_data, agglCl_data = get_quality_values(predict_data, gt_data, dense_gt_data) # measurements = {"accuracy":acc, "precision":prec, "recall":rec, "auc score":auc_score, # "true positives":tp, "false positives":fp, "true negatives":tn, # "false negatives":fn} if not os.path.exists(outpath): print "Output h5 file did not exist." for measurement in measurements.iterkeys(): key = "quality/" + measurement data = np.zeros((1,)) data[0] = measurements[str(measurement)] save_h5(data, outpath, key, None) else: for measurement in measurements.iterkeys(): key = "quality/" + measurement data = read_h5(outpath, key) new_data = np.vstack((data, measurements[measurement])) save_h5(new_data, outpath, key, None) for slice in slices: im_outpath = outpath.split(".")[-2] predict_im_outpath = im_outpath + "_slice_" + str(slice) + ".png" gt_im_outpath = im_outpath + "_slice_" + str(slice) + "_gt.png" plt.imsave(predict_im_outpath, adjust_predict(predict_data)[slice]) plt.imsave(gt_im_outpath, gt_data[slice]) save_h5(wsDt_data, outpath, "segmentation/wsDt data", None) save_h5([agglCl_data], outpath, "segmentation/agglCl data", None) fpr, tpr, threshold = draw_roc_curve(predict_data, gt_data) plt.figure() plt.plot(fpr, tpr) plt.savefig(im_outpath + "roc_curve_test.png")
def make_seg_map(prob_map_path, dense_gt_path): prob_map = read_h5(prob_map_path) dense_gt = read_h5(dense_gt_path) nodes_in_dgt = len(np.unique(dense_gt)) print "nodes in dgt", nodes_in_dgt seed_map = wsDtSegmentation(prob_map, pmin=0.5, minMembraneSize=10, minSegmentSize=0, sigmaMinima=6, sigmaWeights=1, cleanCloseSeeds=True, returnSeedsOnly=True) seg_map, sup_map, wsDt_data, agglCl_data = get_segmentation(prob_map, pmin=0.5, minMemb=10, minSeg=10, sigMin=6, sigWeights=1, sigSmooth=0.1, cleanCloseSeeds=True, returnSeedsOnly=False, edgeLengths=None, nodeFeatures=None, nodeSizes=None, nodeLabels=None, nodeNumStop=nodes_in_dgt, beta=0, metric='l1', wardness=0.2, out=None) print "seeds", len(np.unique(seed_map)) print "seg", len(np.unique(seg_map)) #make folder for seeds seed_folder = prob_map_path.split("prob")[0] + "seeds/" if not os.path.exists(seed_folder): os.mkdir(seed_folder) seed_map_outpath = seed_folder + prob_map_path.split("/")[-1] #make folder for super pixels sup_folder = prob_map_path.split("prob")[0] + "sup_maps/" if not os.path.exists(sup_folder): os.mkdir(sup_folder) sup_map_outpath = sup_folder + prob_map_path.split("/")[-1] #make folder for segmentations seg_folder = prob_map_path.split("prob")[0] + "seg_maps/" if not os.path.exists(seg_folder): os.mkdir(seg_folder) seg_map_outpath = seg_folder + prob_map_path.split("/")[-1] #make folder for segmentation data data_folder = prob_map_path.split("prob")[0] + "seg_data/" if not os.path.exists(data_folder): os.mkdir(data_folder) data_outpath = data_folder + prob_map_path.split("/")[-1] #get segmentation data ri, voi = rand_index_variation_of_information(seg_map, dense_gt) print "ri, voi", ri , voi ri_data = np.array((ri)) voi_data = np.array((voi)) ri_voi_data = np.array((ri, voi)) #save seeds, superpixels and segmentations # save_h5(ri_voi_data, data_outpath, key) # save_h5(ri_data, data_outpath, "rand index", None) # save_h5(voi_data, data_outpath, "variation of information", None) # save_h5(seed_map, seed_map_outpath, "data", None) save_h5(sup_map,sup_map_outpath, "data", None) save_h5(seg_map,seg_map_outpath, "data", None)
def get_trimap_data(trimap_path): filename1 = trimap_path.split("/")[-1] filename2 = filename1.split("_")[0] + "_" + filename1.split("_")[1] outpath = "/mnt/CLAWS1/stamilev/volumes/groundtruth/dense_gt_data/" + filename2 + ".h5" print outpath trimap = read_h5(trimap_path) #dgt= dgt[25:725, 0:700, 0:700] unique = np.unique(trimap) unique_elements = [] unique_tuples = [] print "no of unique elements", len(unique) for i in unique: mask = trimap == i noe = np.sum(mask) print i, noe unique_elements.append(noe) unique_tuples.append((i, noe)) assert len(unique)==len(unique_elements) l = len(unique_elements) nodes_data = np.zeros((l,2), dtype=np.uint) for n in range(l): nodes_data[n,0] = unique_tuples[n][0] nodes_data[n,1] = unique_tuples[n][1] #outpath = "/home/stamylew/volumes/groundtruth/dense_gt_data/entire_usable_data.h5" save_h5(nodes_data, outpath, "labels and occurrence", None)
def redo_quality2(block_path, dense_gt_path, minMemb, minSeg, sigMin, sigWeights, sigSmooth, edgeLengths=None, nodeFeatures=None, nodeSizes=None, nodeLabels=None, nodeNumStop=None, beta=0, metric='l1', wardness=0.2, out=None): folder_list = [f for f in os.listdir(block_path) if not os.path.isfile(os.path.join(block_path,f)) and ("figure" not in f) and "redone" not in f] print "folder_list", folder_list outpath = block_path + "/redone_quality" if not os.path.exists(outpath): os.mkdir(outpath) dense_gt_data = read_h5(dense_gt_path) nodes_in_dgt = len(np.unique(dense_gt_data)) for f in folder_list: folder_path = os.path.join(block_path, f) prob_file = [h for h in os.listdir(folder_path) if "probs" in h] prob_file_path = os.path.join(folder_path,prob_file[0]) print print print prob_file_path predict_data = read_h5(prob_file_path) adjusted_predict_data = adjust_predict(predict_data) print "#nodes in dense gt", nodes_in_dgt pmin = 0.5 seg, sup, wsDt_data, agglCl_data = get_segmentation(adjusted_predict_data, pmin, minMemb, minSeg, sigMin, sigWeights, sigSmooth,True,False, edgeLengths,nodeFeatures, nodeSizes, nodeLabels, nodeNumStop,beta, metric, wardness, out) nodes_in_seg = len(np.unique(seg)) nodes_in_sup = len(np.unique(sup)) ri, voi = rand_index_variation_of_information(seg, dense_gt_data) new_folder_path = outpath + "/" + f if not os.path.exists(new_folder_path): os.mkdir(new_folder_path) key = "pmin_"+ str(pmin) + "_minMemb_" + str(minMemb)+ "_minSeg_"+ str(minSeg) +"_sigMin_" + str(sigMin) + "_sigWeights_" + str(sigWeights) \ + "_sigSmooth_" + str(sigSmooth) + "_nodeNumStop_" + str(nodeNumStop) save_h5(seg, new_folder_path + "/segmentation.h5", key) save_h5(sup, new_folder_path + "/super_pixels.h5", key) seg_data = np.zeros((2,3)) seg_data[0,0] = ri seg_data[0,1] = voi seg_data[1,0] = nodes_in_dgt seg_data[1,1] = nodes_in_sup seg_data[1,2] = nodes_in_seg save_h5(seg_data, new_folder_path + "/seg_data", key, None)
def test_wsDt_agglCl_configs(predict_path, dense_gt_path, pmin=0.5, minMemb=10, minSeg=10, sigMin=2, sigWeights=2, sigSmooth=0.1): """ :param predict_path: :param dense_gt_path: :param pmin: :param minMemb: :param minSeg: :param sigMin: :param sigWeights: :param sigSmooth: :return: """ #get rand index and variation of information predict_data = read_h5(predict_path) adjusted_predict_data = adjust_predict(predict_data) dense_gt_data = read_h5(dense_gt_path) seg, sup = get_segmentation(adjusted_predict_data,pmin,minMemb,minSeg,sigMin,sigWeights,sigSmooth) ri, voi = rand_index_variation_of_information(seg, dense_gt_data) print "ri, voi", ri, voi config = predict_path.split("/")[-2] filename = config + "_" + predict_path.split("/")[-1] outpath_folder = "/home/stamylew/test_folder/q_data/wsDt_agglCl_tests/" outpath = outpath_folder + filename key = "sigMin_" + str(sigMin) + "_sigWeights_" + str(sigWeights) + "_sigSmooth_" + str(sigSmooth) if not os.path.exists(outpath): print "Output h5 file did not exist." data = np.zeros((1,2)) data[0,0] = ri data[0,1] = voi save_h5(data, outpath, key, None) else: old_data = read_h5(outpath, key) data = np.zeros((1,2)) data[0,0] = ri data[0,1] = voi new_data = np.vstack((old_data, data)) save_h5(new_data, outpath, key, None)
def view_HDF5(inpaths): app = QApplication(sys.argv) v = Viewer() for inpath in inpaths: if "n_1_" in inpath: prefix = "n_1_" elif "n_2_" in inpath: prefix = "n_2_" else: prefix = "" if "h5" in inpath: #data = vigra.readHDF5(inpath, "data") print print "inpath", inpath data = read_h5(inpath) file = inpath.split("/")[-1] name = prefix + file.split(".")[0] if "prob_files" in inpath or "seeds" in inpath or "trimap" in inpath: data = binarize_predict(data) file = inpath.split("/")[-2] + "_" + inpath.split("/")[-1] name = prefix + file.split(".")[0] print "type", type(data) if "test_data" in inpath or "prob_files" in inpath or "seeds" in inpath or "trimap" in inpath: v.addGrayscaleLayer(data, name=name) # if "trimaps" in inpath or "dense" in inpath or "sup_maps" in inpath or "seg_maps" in inpath: # v.addRandomColorsLayer(255*data, name=name+"_color") else: v.addRandomColorsLayer(255*data, name=name+"_color") if "png" in inpath: img = vigra.impex.readImage(inpath) img = np.asarray(img) file = inpath.split("/")[-1] name = file.split(".")[0] print "type",type(img) v.addGrayscaleLayer(img, name=name) #v.addRandomColorsLayer(255*img, name=name+"color") v.showMaximized() app.exec_()
def redo_quality(block_path, dense_gt_path, minMemb, minSeg, sigMin, sigWeights, sigSmooth, edgeLengths=None, nodeFeatures=None, nodeSizes=None, nodeLabels=None, nodeNumStop=None, beta=0, metric='l1', wardness=0.2, out=None): #find all relevant folders in block path folder_list = [f for f in os.listdir(block_path) if not os.path.isfile(os.path.join(block_path,f)) and ("figure" not in f) and "redone" not in f] #create folder for redone quality outpath = block_path + "/redone_quality" if not os.path.exists(outpath): os.mkdir(outpath) dense_gt_data = read_h5(dense_gt_path) nodes_in_dgt = len(np.unique(dense_gt_data)) #use prob file in every folder to create new quality in data in corresponding new folder for f in folder_list: #find prob file paths folder_path = os.path.join(block_path, f) prob_file = [h for h in os.listdir(folder_path) if "probs" in h] prob_file_path = os.path.join(folder_path,prob_file[0]) #create new folders for new quality data config_name = prob_file_path.split("/")[-2] config_path = outpath +"/"+ config_name if not os.path.exists(config_path): os.mkdir(config_path) quality_data_path = config_path + "/" + config_name+".h5" #save new quality data in new folders save_quality_values(prob_file_path,gt_path, dense_gt_path, quality_data_path,slices,minMemb, minSeg, sigMin, sigWeights, sigSmooth, edgeLengths, nodeFeatures, nodeSizes, nodeLabels, nodeNumStop, beta, metric, wardness, out)
def test(ilp, files, gt_path, dense_gt_path, labels="", loops=3, weights="", repeats=1, outpath= "", t_cache = "", p_cache = ""): """ Run test :param: ilp : path to ilp project to use for training :param: files : path to file to do batch prediction on :param: gt_path : path to trimap groundtruth :param: dense_gt_path : path to dense groundtruth :param: labels : amount of labeled pixels to use in training :param: loops : amount of autocontext loops :param: weights : weighting of the labels over the autocontext loops :param: repeats : amount of repeat runs of the test :param: outpath : outpath for test outputs :param: t_cache : path to training data cache :param: p_cache : path to prediction data cache """ hostname = socket.gethostname() print "test information:" print print "hostname:", hostname print print "ilp_file:", ilp print print "files to predict:", files print print "groundtruth:", gt_path print print "dense groundtruth:", dense_gt_path print print "labels:", labels print print "loops:", loops print print "weights:", weights print print "repeats:", repeats # Collect the test specifications ilp_split = ilp.split(".")[-2] training_file = "training file: "+ilp_split.split("/")[-1] gt_split = gt_path.split(".")[-2] trimap_file = "trimap file: " + gt_split.split("/")[-1] # Assign paths filesplit = files.split(".")[-2] filename = filesplit.split("/")[-1] prediction_file = "prediction file: "+ filename test_folder_path = assign_path(hostname)[5] if t_cache == "": t_cache = test_folder_path + "/t_cache" if p_cache == "": p_cache = test_folder_path + "/p_cache/" + filename if not os.path.exists(p_cache): os.mkdir(p_cache) if outpath == "": output = test_folder_path + "/q_data" else: output = outpath print print "outpath:", outpath print print "t_cache:", t_cache print print "p_cache:", p_cache # Create file tags if labels == "": label_tag = "all" else: # assert labels == check_ilp_labels(ilp) true_labels = check_ilp_labels(ilp) label_tag = true_labels if weights == "": weight_tag = "none" else: weight_tag = str(weights) # Make folder for quality data if "manual" in ilp: filename += "_manual" if "hand_drawn" in ilp: filename += "_hand_drawn" if "clever" in ilp: filename += "_clever" if "less_feat" in ilp: filename += "_less_feat" #change labels for every test # if labels != "": # print # print "reducing labels to " + str(labels) # ilp = reduce_labels_in_ilp(ilp, labels) file_dir = output + "/" + filename if not os.path.exists(file_dir): os.mkdir(file_dir) # Overwrite folder directory # file_dir = "/mnt/CLAWS1/stamilev/delme" # Check if file directory exists, if not make such directory if not os.path.exists(file_dir): print print "Output folder did not exist." os.mkdir(file_dir) print print "New one named " + file_dir + " was created." q_outpath = file_dir + "/n_" + str(loops) + "_l_" + str(label_tag) + "_w_" + weight_tag prob_folder = q_outpath + "/prob_files" q_data_outpath = q_outpath + "/n_" + str(loops) + "_l_" + str(label_tag) + "_w_" + weight_tag + ".h5" # Check if test directory exists, if not make such directory if not os.path.exists(q_outpath): print print "Output h5 file did not exist" os.mkdir(q_outpath) os.mkdir(prob_folder) print print "New one named " + q_outpath + " was created." if not os.path.exists(prob_folder): os.mkdir(prob_folder) # Run the test for i in range(repeats): print print "round of repeats %d of %d" % (i+1, repeats) #train on ilp project ac_train(ilp, labels, loops, weights, t_cache, outpath) print print "training completed" #batch predict files ac_batch_predict(files, t_cache, p_cache, overwrite = "") print print "batch prediction completed" #save prob files and quality data prob_file = [x for x in os.listdir(p_cache) if ("probs" in x)] predict_path = p_cache + "/" + prob_file[0] predict_data = adjust_predict(read_h5(predict_path)) prob_path = prob_folder + "/prob_"+ str(i+1)+ ".h5" # if os.path.exists(prob_path): # # TODO:not working yet # prob_path = prob_path.split("/")[-2] + "/new_" + prob_path.split("/")[-1] # print prob_path save_h5(predict_data, prob_path, "data") save_quality_values(predict_path, gt_path, dense_gt_path, q_data_outpath, (0,49,99)) #save test specification data save_h5([training_file, prediction_file, trimap_file], q_data_outpath, "used files", None) save_h5([labels],q_data_outpath, "autocontext_parameters/#labels") save_h5([loops], q_data_outpath, "autocontext_parameters/#loops") save_h5([str(weight_tag)], q_data_outpath, "autocontext_parameters/weights") print print "quality data saved" #save configuration data # call(["cp", predict_path, q_outpath]) save_h5(["pmin", "minMemb", "minSeg", "sigMin", "sigWeights", "sigSmooth", "cleanCloseSeeds", "returnSeedsOnly"], q_data_outpath, "segmentation/wsDt parameters", None) save_h5(["edge_weights", "edgeLengths", "nodeFeatures", "nodeSizes", "nodeLabels", "nodeNumStop", "beta", "metric", "wardness", "out"], q_data_outpath, "segmentation/agglCl parameters", None) print print "quality data saved"
def compress(input, ouput): file = read_h5(input[0], input[1]) save_h5(file, output[0], output[1], "lzf")
# for l in range(t-1): # data[i+l,j,k] = 1 # if data[i,j,k] == 1 and data[i+t,j,k] == 0: # for l in range(t): # data[i+l,j,k] = 1 # return data def label_neurons(data, neuron_label): for i in range(data.shape[0]): for j in range(data.shape[1]): for k in range(data.shape[2]): if data[i,j,k] != 1 and data[i,j,k] != 0: data[i,j,k] = neuron_label return data def filter_membrane(dense_gt_data): prepared_data = prepare_data(dense_gt_data) print "prepared data unique", np.unique(prepared_data) memb = create_membrane(prepared_data) memb_data = label_neurons(memb, 0) return memb_data, dense_gt_data if __name__ == '__main__': data = read_h5("/home/stamylew/volumes/groundtruth/dense_groundtruth/100p_cube1_dense_gt.h5", "data") memb = filter_membrane(data) save_h5(memb, "/home/stamylew/volumes/groundtruth/memb/100p_cube1_memb.h5", "data", "lzf") print "done"
__author__ = 'stamylew' import numpy as np from python_functions.handle_h5.handle_h5 import read_h5, save_h5 data = read_h5("/home/stamylew/volumes/groundtruth/trimaps/500p_cube1_trimap_t_05.h5") perm = np.random.permutation(data) survivors = perm [:3] #save_h5(perm, "/home/stamylew/volumes/groundtruth/trimaps/test.h5") print data print "survivors" print survivors
#reduces number labeled pixels if limit < nol if limit < nol: percentage = limit / nol print "percentage", percentage limited_data = filter_all_labels(data, percentage) return limited_data else: print print "Limit exceeds amount of labeled pixels" return data if __name__ == '__main__': a = read_h5("/mnt/CLAWS1/stamilev/ilastik_projects/labels/100p_cube1_generated_labels.h5") b = read_h5("/mnt/CLAWS1/stamilev/ilastik_projects/labels/100p_cube2_generated_labels.h5") # b = read_h5("/mnt/CLAWS1/stamilev/ilastik_projects/labels/100p_cube2_hand_drawn_labels.h5") # print get_number_of_labels(b) #print "working file:", np.unique(b) # c = filter_all_labels(b, 0.5) # print get_number_of_labels(c) # d = limit_label(b, 10000) print "cube1" get_number_of_unique_labels(a) print print "cube2" get_number_of_unique_labels(b) # print "real number"
# -*- coding: utf-8 -*- """ Created on Tue Sep 22 14:31:38 2015 @author: stamylew """ import numpy as np from python_functions.handle_h5.handle_h5 import read_h5, save_h5 def threshold(data, threshold_membrane, threshold_neurons): bin_data = np.zeros(data.shape) for i in range(data.shape[0]): for j in range(data.shape[1]): for k in range(data.shape[2]): if data[i,j,k] <= threshold_membrane: bin_data[i,j,k] = 0 if data[i,j,k] > threshold_membrane and data[i,j,k] <= threshold_neurons: bin_data[i,j,k] = 0.5 if data[i,j,k] > threshold_neurons: bin_data[i,j,k] = 1 return bin_data if __name__ == '__main__': f = read_h5("/home/stamylew/volumes/100x100block_of_validation_sample_Probabilities.h5", "exported_data") data = threshold(f, 0.4, 0.6) save_h5(data, "/home/stamylew/volumes/100x100block_of_validation_sample_Probabilities.h5", "bin", None) print "done"
def delete_row(data_path, row_number): data = read_h5(data_path) print "data: ", data new_data = np.delete(data, row_number, axis=0) print "new data: ", new_data
#m = threshold(l, 0.2, 0.8) #save_h5(m, "/home/stamylew/volumes/test_data/150cube_loops.h5", "n4") #label number #labels = read_h5("/home/stamylew/75cube_Labels.h5", "exported_data") #nol = get_number_of_labels(labels) #print nol #limited = limit_label(labels, 499) #save_h5(limited, "/home/stamylew/75cube_Labels_rand_500.h5", "", None) #compare gt to predict ##for different number of loops gt = read_h5("/home/stamylew/volumes/test_data/150cube.h5", "tri") #n = read_h5("/home/stamylew/volumes/test_cube2.h5", "150cube_memb") #o = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n0") #o = np.squeeze(o) #o = o[:,:,:,0] #p = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n1") #q = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n2") #r = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n3") s = read_h5("/home/stamylew/volumes/test_data/150cube_loops.h5", "n4") #t = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n5") #u = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n6") #v = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n7") #w = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n8") #x = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n9") #y = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n10") #z = read_h5("/home/stamylew/volumes/test_cube2_loops.h5", "n11")
def sort_and_extract_quality_data(path, fixed_param, x_dim, measurements, median): """ :param path: :param fixed_param: :param measurements: :return: """ # Find all relevant data folders data_folders = [f for f in os.listdir(path) if (isdir(path)) and (fixed_param in f) and ("h5" not in f)] assert len(data_folders) > 0, "No folders fit the criteria" # print "data_folders", data_folders # Create labels for plot if "n_" in fixed_param: fixed_value = 'n = ' + fixed_param.split("_")[-2] elif "l_" in fixed_param: fixed_value = 'l = ' + fixed_param.split("_")[-2] elif "w_"in fixed_param: fixed_value = 'w = ' + fixed_param.split("_")[-2] else: raise Exception("Can't read fixed_parameter input") # Sort data folders sorting_list = [] for data_folder in data_folders: inpath = join(path, data_folder) h5file = [g for g in os.listdir(inpath) if (isfile(join(inpath, g))) and fixed_param in g and "h5" in g] h5file_path = join(inpath, h5file[0]) x_value = read_h5(h5file_path, "autocontext_parameters/"+x_dim) sorting_list.append((x_value, data_folder)) sorted_list = sorted(sorting_list, key=lambda tup: tup[0]) sorted_data_folders = [] for tuple in sorted_list: sorted_data_folders.append(tuple[1]) # Extract quality data data = [] for measurement in measurements: assert str(measurement) in ["accuracy", "precision", "recall", "auc_score", "rand index", "variation of information", "true positives", "false positives", "true negatives", "false negatives"], "Given Quality measurement %s not valid" % measurement x_values = [] mean = [] std = [] for data_folder in sorted_data_folders: inpath = join(path, data_folder) h5file = [g for g in os.listdir(inpath) if (isfile(join(inpath, g))) and fixed_param in g and "h5" in g] h5file_path = join(inpath, h5file[0]) #print datapath x_param = read_h5(h5file_path, "autocontext_parameters/"+x_dim) x_param = x_param[0] x_values.append(x_param) measurement_data = read_h5(h5file_path, "quality/"+str(measurement)) if median: mean.append(np.median(measurement_data)) std.append(mad(measurement_data)) else: mean.append(np.mean(measurement_data)) std.append((np.std(measurement_data))) data.append((str(measurement), x_values, mean, std)) print "mean", mean print "std", std print return x_dim, data, fixed_value,
#p = exclude_ignore_label(g, p) # #q = read_h5("/home/stamylew/src/autocontext/training/cache_mw/0000_smallcubes_probs.h5", "exported_data") #save_h5(q, "/home/stamylew/volumes/training_data/50cube3_bp.h5", "all_labels/n3/w_1_2_3") #q = adjust_predict_file(q) #q = exclude_ignore_label(g, q) # # # #c = config(p[0], p[1]) #c.show_quality() # #d = config(q[0], q[1]) #d.show_quality() I = read_h5("/home/stamylew/volumes/trimaps/50cube2_tri.h5", "50cube2_tri") II = read_h5("/home/stamylew/src/autocontext/prediction/cache/smallcubes_probs.h5", "exported_data") II = adjust_predict(II) q = exclude_ignore_label(I,II) c = predict_class(q[0], q[1]) c.show_quality() print c.return_quality() #III = read_h5("/home/stamylew/volumes/training_data/50cube3_bp.h5", "all_labels/n3/w_3_2_1") #III = adjust_predict_file(III) #plt.figure() #plt.imshow(I[11])
#create new blocks new_blocks = [] for block in blocks: new_block = np.zeros(block.shape, dtype=np.uint) new_blocks.append(new_block) # replace random block with labeled data new_labeled_block = new_blocks[random_block_no] new_labeled_block[:,:,smaller_slice_no:bigger_slice_no] = concentrated_data assert get_number_of_labels(new_labeled_block) == labels # replace old blocks with new blocks manipulate_me.replace_labels(0, new_blocks, block_slices, delete_old_blocks=True) print print "new_label_number", get_number_of_labels(new_block) return manipulate_me.project_filename if __name__ == '__main__': trimap_path = "/home/stamylew/volumes/groundtruth/trimaps/500p_cube2_trimap_t_05.h5" #trimap_path = "/home/stamylew/volumes/groundtruth/trimaps/100p_cube1_trimap_t_05.h5" trimap_data = read_h5(trimap_path, "data") print "trimap labeled pixel amount", get_number_of_labels(trimap_data) ilp_path = "/home/stamylew/ilastik_projects/100p_cube1.ilp" #ilp_path = "/home/stamylew/ilastik_projects/100p_cube1.ilp" # mod_ilp = modify_labels_of_ilp(ilp_path, 3000) # check_ilp_labels(mod_ilp) concentrated_data = concentrated_labels(ilp_path, 1000) # save_h5(concentrated_data, "/home/stamylew/delme/concentrated_ilp_labels.h5", "data", None) print "done"
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 15:27:41 2015 @author: stamylew """ import vigra as vg import numpy as np from python_functions.handle_h5.handle_h5 import read_h5 import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as cl def make_slice_image(data, slice=40, outpath = "/mnt/CLAWS1/stamilev/delme/delme.jpg", grey= True): image = data[:,:,slice] if grey: plt.imsave(outpath, image, cmap = cm.Greys_r) else: plt.imsave(outpath, image, cmap = cl.ListedColormap ( np.random.rand ( 256,3))) if __name__ == '__main__': data = read_h5("/mnt/CLAWS1/stamilev/volumes/groundtruth/dense_groundtruth/100p_cube2_dense_gt.h5") make_slice_image(data, 40, "/mnt/CLAWS1/stamilev/delme/100p_cube2_merge_dgt.png", False) print "done"
__author__ = 'stamylew' from python_functions.handle_h5.handle_h5 import read_h5 import numpy as np measurement1 = "rand index" measurement2 = "variation of information" measurement3 = "precision" measurement4 = "recall" measurement5 = "true positives" measurement6 = "false positives" measurement7 = "true negatives" measurement8 = "false negatives" path = "/mnt/CLAWS1/stamilev/test_folder/compare_labels/100p_cube1/100p_cube1_n_3_random/n_3_l_1000.0_w_none/n_3_l_1000.0_w_none.h5" key = "quality/" + measurement2 data = read_h5(path, key) print np.mean(data)