예제 #1
0
def run(args):
    _info(args.roi_name)

    param_grid = {'k_hidden':args.k_hidden,'k_layers':args.k_layers}
    param_grid = [comb for comb in ParameterGrid(param_grid)]
    
    print(len(param_grid))
    print(len(args.k_layers))


    if len(param_grid) == 1:
        res_path = (RES_DIR + 
                    '/%s_%d_net_%d' %(args.roi_name, args.roi, args.net) +
                    '_trainsize_%d' %(args.train_size) +
                    '_k_hidden_%d' %(args.k_hidden[0]) +
                    '_k_layers_%d_batch_size_%d' %(args.k_layers[0], args.batch_size) +
                    '_num_epochs_%d_z_%d.pkl' %(args.num_epochs, args.zscore))

        mod_path = res_path.replace('results','models')
        mod_path = mod_path.replace('pkl','h5')

    elif len(param_grid) > 1:
        res_path = (RES_DIR + 
                    '/%s_%d_net_%d' %(args.roi_name, args.roi, args.net) +
                    '_trainsize_%d' %(args.train_size) +
                    '_kfold_%d' %(args.k_fold) +
                    '_batch_size_%d' %(args.batch_size) +
                    '_num_epochs_%d_z_%d_GSCV.pkl' %(args.num_epochs, args.zscore))
        
    '''
    get dataframe
    '''
    if not os.path.isfile(res_path):
        start = time.time()
        df = _clip_class_df(args)
        print('data loading time: %.2f seconds' %(time.time()-start))
        if len(param_grid) == 1:
            results, results_prob, model = _test(df,args,param_grid[0])
            # save results
            with open(res_path, 'wb') as f:
                pickle.dump([results, results_prob], f)
                # save model
            
            if not os.path.exists(os.path.dirname(mod_path)):
                os.makedirs(os.path.dirname(mod_path),exist_ok=True)

            model.save(mod_path)

        elif len(param_grid) > 1:
            results = {}
            for mm, params in enumerate(param_grid):
                print('---')
                print('model{:02d}'.format(mm) + ': ')
                print(params)
                print('---')
                results['model{:02d}'.format(mm)] = _train(df, args, params)
            # save grid-search CV results
            with open(res_path, 'wb') as f:
                pickle.dump([results, param_grid], f)
예제 #2
0
def run(args):
    _info(args.subnet)
    '''
    get dataframe
    '''
    # all-but-subnetwork (invert_flag)
    if 'minus' in args.subnet:
        args.invert_flag = True

    res_path = (RES_DIR + '/%s_%d_net_%d' %
                (args.roi_name, args.roi, args.net) + '_nw_%s' %
                (args.subnet) + '_trainsize_%d' % (args.train_size) +
                '_kdim_%d_batch_size_%d' % (args.k_dim, args.batch_size) +
                '_num_epochs_%d_z_%d.pkl' % (args.num_epochs, args.zscore))
    if not os.path.isfile(res_path):
        df = _clip_class_df(args)
        results = _test(df, args)
        with open(res_path, 'wb') as f:
            pickle.dump(results, f)
예제 #3
0
def run(args):
    # Get all combinations of the parameter grid

    _info(args.roi_name)
    # Get all combinations of the parameter grid

    param_grid = {'k_hidden': args.k_hidden, 'k_layers': args.k_layers}
    param_grid = [comb for comb in ParameterGrid(param_grid)]

    print(len(param_grid))
    print(len(args.k_layers))

    _info('Number of hyperparameter combinations: ' + str(len(param_grid)))
    _info(args.roi_name)
    '''
    get dataframe
    '''
    if len(param_grid) == 1:
        res_path = (RES_DIR + '/%s_%d_net_%d' %
                    (args.roi_name, args.roi, args.net) + '_trainsize_%d' %
                    (args.train_size) + '_k_hidden_%d' % (args.k_hidden[0]) +
                    '_k_layers_%d_batch_size_%d' %
                    (args.k_layers[0], args.batch_size) +
                    '_num_epochs_%d_z_%d.pkl' % (args.num_epochs, args.zscore))

        gru_mod_path = res_path.replace('results', 'models')
        gru_mod_path = gru_mod_path.replace('pkl', 'h5')
        gru_model_path = gru_mod_path.replace('saliency', 'gru')
        args.gru_model_path = gru_model_path

    elif len(param_grid) > 1:
        res_path = (RES_DIR + '/%s_%d_net_%d' %
                    (args.roi_name, args.roi, args.net) + '_trainsize_%d' %
                    (args.train_size) + '_kfold_%d' % (args.k_fold) +
                    '_batch_size_%d' % (args.batch_size) +
                    '_num_epochs_%d_z_%d_GSCV.pkl' %
                    (args.num_epochs, args.zscore))

    if not os.path.isfile(res_path):
        start = time.clock()
        df = _clip_class_df(args)
        print('data loading time: %.2f seconds' % (time.clock() - start))

        if len(param_grid) == 1:
            sal_df = _saliency(df, args)

            # save results
            with open(res_path, 'wb') as f:
                pickle.dump(sal_df, f)

        elif len(param_grid) > 1:
            results = {}
            for mm, params in enumerate(param_grid):
                print('---')
                print('model{:02d}'.format(mm) + ': ')
                print(params)
                print('---')
                results['model{:02d}'.format(mm)] = _train(df, args, params)
            # save grid-search CV results
            with open(res_path, 'wb') as f:
                pickle.dump([results, param_grid], f)
예제 #4
0
def run(args):
    # Get all combinations of the parameter grid

    _info(args.roi_name)
    # Get all combinations of the parameter grid

    param_grid = {'k_hidden': args.k_hidden, 'k_layers': args.k_layers}
    param_grid = [comb for comb in ParameterGrid(param_grid)]

    print(len(param_grid))
    print(len(args.k_layers))

    _info('Number of hyperparameter combinations: ' + str(len(param_grid)))
    _info(args.roi_name)
    '''
    get dataframe
    '''
    if len(param_grid) == 1:
        res_path = (RES_DIR + '/%s_%d_net_%d' %
                    (args.roi_name, args.roi, args.net) + '_trainsize_%d' %
                    (args.train_size) + '_k_hidden_%d' % (args.k_hidden[0]) +
                    '_kdim_%d' % (args.k_dim) + '_k_layers_%d_batch_size_%d' %
                    (args.k_layers[0], args.batch_size) +
                    '_num_epochs_%d_z_%d.pkl' % (args.num_epochs, args.zscore))

        mod_path = res_path.replace('results', 'models')
        mod_path = mod_path.replace('pkl', 'h5')

        gru_model_path = mod_path.replace('gruencoder', 'gru')
        gru_model_path = gru_model_path.replace('_kdim_%d' % (args.k_dim), '')
        args.gru_model_path = gru_model_path

    elif len(param_grid) > 1:
        res_path = (RES_DIR + '/%s_%d_net_%d' %
                    (args.roi_name, args.roi, args.net) + '_trainsize_%d' %
                    (args.train_size) + '_kfold_%d' % (args.k_fold) +
                    '_batch_size_%d' % (args.batch_size) +
                    '_num_epochs_%d_z_%d_GSCV.pkl' %
                    (args.num_epochs, args.zscore))

    if not os.path.isfile(res_path):
        start = time.clock()
        df = _clip_class_df(args)
        print('data loading time: %.2f seconds' % (time.clock() - start))

        if len(param_grid) == 1:
            results, results_prob, model = _test(df, args, param_grid[0])
            print('TESTING DONE :)')
            # forward pass data and save encodings
            #traj_df = {}
            #for run in range(K_RUNS):
            #    df = _clip_class_rest_df(args, run)
            #    traj_df[run] = _get_trajectories(df, model, args)

            # save results
            with open(res_path, 'wb') as f:
                pickle.dump([results, results_prob], f)
            # save model
            #model.save(mod_path)

        elif len(param_grid) > 1:
            results = {}
            for mm, params in enumerate(param_grid):
                print('---')
                print('model{:02d}'.format(mm) + ': ')
                print(params)
                print('---')
                results['model{:02d}'.format(mm)] = _train(df, args, params)
            # save grid-search CV results
            with open(res_path, 'wb') as f:
                pickle.dump([results, param_grid], f)