def multip_grabCut(): raw_example_list = _load_grabcut_unary_pairwise_cliques() parser = BatchExamplesParser() selected_num = 50 examples_list_all = parser.parse_grabcut_pickle(raw_example_list) options = Options() batches_num = len(examples_list_all) inf_latent_method = '' init_method = 'clique_by_clique' Tasks = list() for i in range(selected_num): examples_list = examples_list_all[:i] + examples_list_all[i + 1:] Tasks.append((calcGrabCut, (examples_list, examples_list_all[i].name, inf_latent_method, init_method, options))) process_num = min(selected_num, 20) pool = multiprocessing.Pool(process_num) r = pool.map(calcFun, Tasks) pool.close() pool.join() print(r) print('finished')
def laipi_grabCut(): raw_example_list = _load_grabcut_unary_pairwise_cliques() parser = BatchExamplesParser() selected_num = 50 examples_list_all = parser.parse_grabcut_pickle(raw_example_list) options = Options() batches_num = len(examples_list_all) inf_latent_method = 'remove_redundancy' init_method = 'exlarge' laipi_name = [ 'tennis', 'person6', 'cross', '65019', 'elefant', 'bool', '37073', 'banana1', '153077', 'book', '153093', '24077', '189080', '69020' ] Tasks = list() for i in range(selected_num): ex_test = examples_list_all[i] if ex_test.name.split('.')[0] in laipi_name: examples_list = examples_list_all[:i] + examples_list_all[i + 1:] Tasks.append( (laipiDog, (examples_list, examples_list_all[i].name, inf_latent_method, init_method, options, ex_test))) if len(Tasks) != len(laipi_name): raise ValueError('Laipi doesn\'t match!') pool = multiprocessing.Pool(len(laipi_name)) r = pool.map(calcFun, Tasks) pool.close() pool.join() print(r) print('laipi_finished')
print('converge at iter: %d' % t) print('classification error: %d' % total_error) break return outer_history if __name__ == "__main__": init_method = 'clique_by_clique' inf_latent_method = 'remove_redund' options = Options() instance = Instance() from Utils.IOhelpers import _load_grabcut_unary_pairwise_cliques from MrfTypes import Example, BatchExamplesParser parser = BatchExamplesParser() examples_list = parser.parse_grabcut_pickle( _load_grabcut_unary_pairwise_cliques()) example = examples_list[0] # type: Example options.H = example.rows # rows image height options.W = example.cols # cols image width options.numCliques = example.numCliques # number of clique_indexes options.rowsPairwise = example.rowsPairwise instance.clique_indexes = example.clique_indexes instance.pairwise = example.pairwise instance.unary_observed = example.unary_observed instance.y = example.y # Image Configs options.gridStep = np.inf # grid size for defining clique_indexes options.numVariables = example.numVariables
__author__ = 'spacegoing' path = './expData/batchResult/temp/bush.pickle_outer_iter0.pickle' theta_list = list() loss_list = list() with open(path, 'rb') as f: data = pickle.load(f) inner_history = data[-1]['inner_history'] for i in inner_history: theta_list.append(i['theta']) loss_list.append(i['loss_aug']) batches_num = 25 raw_example_list = _load_grabcut_unary_pairwise_cliques() parser = BatchExamplesParser() examples_list_all = parser.parse_grabcut_pickle(raw_example_list) options = Options() inf_latent_method = '' init_method = 'clique_by_clique' Tasks = list() # for i in range(batches_num): i = 25 examples_list = examples_list_all[:i] + examples_list_all[i + 1:] y_hat_loss = list() for theta in theta_list: error = 0 for ex in examples_list:
import numpy as np from Batch_CCCP import cccp_outer_loop from Checkboard import Instance from MrfTypes import Example, Options, BatchExamplesParser from Utils.IOhelpers import _load_grabcut_unary_pairwise_cliques from Batch_MRF_Helpers import inf_label_latent_helper import multiprocessing import sys import pickle __author__ = 'spacegoing' inf_latent_method = '' init_method = 'clique_by_clique' parser = BatchExamplesParser() root = './expData/unbalaced_portions/' def calcFun(args): func, arg = args result = func(*arg) return result def calcCheckboard(prefix_str, miu): instance = Instance('gaussian_portions', portion_miu=miu, is_gaussian=False) examples_list = parser.parse_checkboard(instance)
break eng.exit() return outer_history if __name__ == '__main__': from MrfTypes import BatchExamplesParser from Utils.IOhelpers import _load_grabcut_unary_pairwise_cliques import time time_list = list() raw_example_list = _load_grabcut_unary_pairwise_cliques() parser = BatchExamplesParser() examples_list_all = parser.parse_grabcut_pickle(raw_example_list) options = Options() inf_latent_method = 'remove_redundancy' init_method = 'clique_by_clique' for i in range(50): time_list.append(time.time()) examples_list = examples_list_all[:i] + examples_list_all[i + 1:] outer_history = cccp_outer_loop(examples_list, options, inf_latent_method, init_method) with open('./expData/batchResult/training_result/' 'image_%d_%s_outer_history.pickle' % (i, examples_list_all[i].name), 'wb') as f: pickle.dump([examples_list, outer_history, examples_list_all[i].name, time_list], f)