def evaluate(): name = "final" locations = ['bag', 'hand', 'hips', 'torso'] datasets = ['train', 'validation'] for dset in datasets: for loc in locations: params = get_params(name=name, FX_sel='basic', location=loc, dset_L='validation', dset_U='test', dset_V=dset, ratio_L=1.0, ratio_U=1.0, ratio_V=1.0, prediction=False, evaluate=True, pretrain='pretrain', runs=10, epochs=50, save_step=2, oversampling=True, G_label_sample=True, G_label_factor=1, C_basic_train=True, R_active=False, G_no=1, D_no=1, C_no=1, log_name='log') train(params=params)
def basic(): name = "final" params = get_params(name=name, FX_sel='basic', location='hips', dset_L='validation', dset_U='test', dset_V='validation', ratio_L=1.0, ratio_U=1.0, ratio_V=1.0, prediction=True, pretrain='pretrain', runs=20, epochs=50, save_step=2, oversampling=True, G_label_sample=True, G_label_factor=1, C_basic_train=True, R_active=False, G_no=1, D_no=1, C_no=1, log_name='log') train(params=params)
def test(): name = "test" network.clear(name) params = get_params(name=name, FX_sel='basic', location='hips', dset_L='train', dset_U='validation', dset_V='validation', ratio_L=1, ratio_U=1, ratio_V=1, prediction=True, pretrain='final', runs=1, epochs=10, save_step=2, oversampling=True, G_label_sample=True, G_label_factor=1, C_basic_train=True, R_active=True, G_no=1, D_no=1, C_no=1, log_name='log') train(params=params) GAN.get_prediction_accuracy(params)
def load_FX(FX_sel): from GAN import get_params params = get_params(FX_sel=FX_sel) params['location'] = 'all' data, label = load_data(params, 'validation') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("Label:", label.shape) print("----------------------") params['location'] = 'bag' data, label = load_data(params, 'train') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("Label:", label.shape) print("----------------------") params['location'] = 'hand' data, label = load_data(params, 'train') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("Label:", label.shape) print("----------------------") params['location'] = 'hips' data, label = load_data(params, 'train') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("Label:", label.shape) print("----------------------") params['location'] = 'torso' data, label = load_data(params, 'train') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("Label:", label.shape) print("----------------------") params['location'] = 'test' data, label = load_data(params, 'test') print('Loaded!') print(" Data:", data.shape) print(" NaN:", np.count_nonzero(np.isnan(data))) print("----------------------")
def cross_train(def_params, param_1, param_1_lst, param_2, param_2_lst, last_bmark=0): clear('results') results = np.zeros((len(param_1_lst), len(param_2_lst), 3)) count = 1 for x, p1 in enumerate(param_1_lst): for y, p2 in enumerate(param_2_lst): c_name = def_params['name'] + '_' + str(count).zfill(3) params = network.load_Parameter(c_name) if params is None: params = def_params.copy() params['name'] = c_name params[param_1] = p1 params[param_2] = p2 else: params = get_params(**params) # Continue at the last benchmark if count > last_bmark: log('Benchmark %s: %s = %s | %s = %s' % (c_name, param_1, str(p1), param_2, str(p2)), name='results') train(params) mat_accuracy_G, mat_accuracy_D, mat_accuracy_C = network.load_Acc( params) acc_G = np.mean(mat_accuracy_G, axis=0) acc_D = np.mean(mat_accuracy_D, axis=0) acc_C = np.mean(mat_accuracy_C, axis=0) results[x, y, 1] = acc_G[-1] results[x, y, 2] = acc_D[-1] results[x, y, 0] = acc_C[-1] count += 1 excel.save(def_params, param_1, param_1_lst, param_2, param_2_lst, results)
def pretrain(): name = 'pretrain' params = get_params(name=name, FX_sel='basic', location='hips', dset_L='train', dset_V='validation', ratio_L=1.00, ratio_V=1.00, runs=20, epochs=25, save_step=5, oversampling=True, C_no=1, log_name='log') train_C(params=params)
def cross_params(net, lst_1, lst_2, last_bmark=0): name = 'cross_' + net params = get_params(name=name, FX_sel='basic', location='hips', dset_L='validation', dset_U='validation', dset_V=None, ratio_L=0.5, ratio_U=0.5, runs=5, epochs=150, save_step=15, oversampling=True, G_label_sample=True, G_label_factor=1, C_basic_train=True, R_active=False, G_no=1, D_no=1, C_no=1, log_name='log') network.save_Parameter(params) param_1 = net + 'LR' param_1_lst = lst_1 param_2 = net + 'B1' param_2_lst = lst_2 log('Crosstrain param %s against param %s.' % (param_1, param_2), name=params['log_name']) log('List 1: [%s]' % (' '.join(str(v) for v in param_1_lst)), name=params['log_name']) log('List 2: [%s]' % (' '.join(str(v) for v in param_2_lst)), name=params['log_name']) log('Total runs: %d' % (len(param_1_lst) * len(param_2_lst)), name=params['log_name']) cross_train(params, param_1, param_1_lst, param_2, param_2_lst, last_bmark)
def test_cross(): name = 'test_cross' params = get_params(name=name, FX_sel='basic', location='hips', dset_L='validation', dset_U='validation', runs=3, epochs=6, save_step=3, oversampling=False, G_label_sample=True, G_label_factor=1, C_basic_train=True, R_active=False, G_no=1, D_no=1, C_no=1, ratio_L=0.05, ratio_U=0.33, log_name='log') network.save_Parameter(params) param_1 = 'GLR' param_1_lst = [0.0005, 0.001, 0.0015] param_2 = 'GB1' param_2_lst = [0.3, 0.7, 0.9, 0.99] log('Crosstrain param %s against param %s.' % (param_1, param_2), name=params['log_name']) log('List 1: [%s]' % (' '.join(str(v) for v in param_1_lst)), name=params['log_name']) log('List 2: [%s]' % (' '.join(str(v) for v in param_2_lst)), name=params['log_name']) log('Total runs: %d' % (len(param_1_lst) * len(param_2_lst)), name=params['log_name']) cross_train(params, param_1, param_1_lst, param_2, param_2_lst, 0)
def rerun(): train(params=get_params(name="final")) train(params=get_params(name="Val_Val")) train(params=get_params(name="Val_Train"))