def main(): ''' construct = True if construct == True: with open('./UHG_T2_data_mean.pkl', 'rb') as filep: image_dic = pickle.load(filep) construct_image_from_dic(image_dic) rotate_image() translate_image('/usr/share/fsl/5.0/data/standard/MNI152_T1_2mm_brain.nii.gz') sys.exit(0) ''' config = Config() parser = argparse.ArgumentParser(description="Visualize features") parser.add_argument("paramfile", type=str, help='Path to the parameter file') args = parser.parse_args() config.parse(path.abspath(args.paramfile)) params = config.config.get('parameters') file_path = params['file_path'] features_file = params['features_path'] features = pickle.load(open(features_file, 'rb')) out_path = params['out_path'] print(len(features)) IMG_SIZE = params['height'] * params['width'] * params['depth'] filter = np.zeros(IMG_SIZE) for index in features: filter[index] = 1 rec_image = reconstruct_image(file_path, filter) nb.save(rec_image, out_path)
def main(): config = Config() parser = argparse.ArgumentParser(description="Run SVM") parser.add_argument("paramfile", type=str, help='Path to the parameter file') args = parser.parse_args() config.parse(path.abspath(args.paramfile)) params = config.config.get('parameters') brain_mask_path = params['brain_mask'] fisher_scores_all = params['fisher_score_all'] print("Input fisher scores: ", fisher_scores_all) for percent in [0.1, 0.3, 0.5, 0.8, 1]: print("Percentage of features chosen: " + str(percent * 100)) features, scores = get_masked_features(brain_mask_path, fisher_scores_all, percent) print("Length of selected features: ", len(features)) mask_features_out = params['out']+'Top_'+\ str(percent*100)+'_features.pkl' mask_fisher_out = params['out']+'Top_'+\ str(percent*100)+'_scores.pkl' with open(mask_features_out, 'wb') as p_filep: pickle.dump(features, p_filep) with open(mask_fisher_out, 'wb') as p_filep: pickle.dump(scores, p_filep) svm = SVM(params) svm.train_and_predict(False, features)
import os import pickle import re import argparse import sys import nibabel as nb import subprocess import math from pathos.multiprocessing import ProcessPool from dementia_prediction.config_wrapper import Config from dementia_prediction.data_input import DataInput from dementia_prediction.cnn_baseline.ensemble_models import CNNEnsembleModels # Parse the parameter file config = Config() parser = argparse.ArgumentParser(description="Run the ADNI Ensemble model") parser.add_argument("paramfile", type=str, help='Path to the parameter file') args = parser.parse_args() config.parse(path.abspath(args.paramfile)) params = config.config.get('parameters') paths = config.config.get('data_paths') patients_dict = pickle.load(open(paths['class_labels'], 'rb')) train_patients = pickle.load(open(paths['train_data'], 'rb')) valid_patients = pickle.load(open(paths['valid_data'], 'rb')) print("Valid Patients:", len(valid_patients), "Train:", len(train_patients)) cad_patients = pickle.load(open(paths['cad_dict'], 'rb')) print("CAD:", len(cad_patients)) classes = params['cnn']['classes']