def test_partial_fit_model_2(): """Test the routine to fit two models.""" # Load the data with only a single serie currdir = os.path.dirname(os.path.abspath(__file__)) path_data = os.path.join(currdir, 'data', 'full_dce') # Create an object to handle the data dce_mod = DCEModality() # Read the data dce_mod.read_data_from_path(path_data) # Load the GT data path_gt = [os.path.join(currdir, 'data', 'full_gt', 'prostate')] label_gt = ['prostate'] gt_mod = GTModality() gt_mod.read_data_from_path(label_gt, path_gt) # Create the object to make the normalization stn = StandardTimeNormalization(dce_mod) stn.partial_fit_model(dce_mod, gt_mod, label_gt[0]) stn.partial_fit_model(dce_mod, gt_mod, label_gt[0]) # Check the model computed model_gt = np.array([22.26479174, 22.51070962, 24.66027277, 23.43488237, 23.75601817, 22.56173871, 26.86244505, 45.06227804, 62.34273874, 71.35327656]) assert_array_almost_equal(stn.model_, model_gt, decimal=PRECISION_DECIMAL) assert_true(stn.is_model_fitted_)
def test_save_model_wrong_ext(): """Test either if an error is raised if the filename as a wrong extension while storing the model.""" # Load the data with only a single serie currdir = os.path.dirname(os.path.abspath(__file__)) path_data = os.path.join(currdir, 'data', 'full_dce') # Create an object to handle the data dce_mod = DCEModality() # Read the data dce_mod.read_data_from_path(path_data) # Load the GT data path_gt = [os.path.join(currdir, 'data', 'full_gt', 'prostate')] label_gt = ['prostate'] gt_mod = GTModality() gt_mod.read_data_from_path(label_gt, path_gt) # Create the object to make the normalization stn = StandardTimeNormalization(dce_mod) stn.partial_fit_model(dce_mod, gt_mod, label_gt[0]) # Try to store the file not with an npy file assert_raises(ValueError, stn.save_model, os.path.join(currdir, 'data', 'model.rnd'))
def test_partial_fit_without_gt(): """Test the partial routine without any gt provided.""" # Load the data with only a single serie currdir = os.path.dirname(os.path.abspath(__file__)) path_data = os.path.join(currdir, 'data', 'full_dce') # Create an object to handle the data dce_mod = DCEModality() # Read the data dce_mod.read_data_from_path(path_data) # Create the object to make the normalization stn = StandardTimeNormalization(dce_mod) stn.partial_fit_model(dce_mod) # Check the data of the model data = np.array([89.90, 90.78, 89.38, 90.45, 91.62, 90.51, 93.79, 98.52, 101.79, 103.56]) assert_array_almost_equal(stn.model_, data, decimal=PRECISION_DECIMAL) assert_true(stn.is_model_fitted_)
path_gt = ['/data/prostate/experiments/Patient 383/GT_inv/prostate'] # Define the associated list of label for the GT label_gt = ['prostate'] # Read the DCE dce_mod = DCEModality() dce_mod.read_data_from_path(path_dce) # Read the GT gt_mod = GTModality() gt_mod.read_data_from_path(label_gt, path_gt) # Create the object to normalize the DCE data dce_norm = StandardTimeNormalization(dce_mod) # Fit the data to get the normalization parameters dce_norm.partial_fit_model(dce_mod, ground_truth=gt_mod, cat='prostate') print dce_norm.model_ # Define the path for the DCE path_dce = '/data/prostate/experiments/Patient 387/DCE' # Define the list of path for the GT path_gt = ['/data/prostate/experiments/Patient 387/GT_inv/prostate'] # Define the associated list of label for the GT label_gt = ['prostate'] # Read the DCE dce_mod = DCEModality() dce_mod.read_data_from_path(path_dce)
if os.path.isdir(os.path.join(path_patients, name))) for id_patient in id_patient_list: # Append for the DCE data path_patients_list_dce.append(os.path.join(path_patients, id_patient, path_dce)) # Append for the GT data - Note that we need a list of gt path path_patients_list_gt.append([os.path.join(path_patients, id_patient, path_gt)]) # Create the model iteratively dce_norm = StandardTimeNormalization(DCEModality()) for pat_dce, pat_gt in zip(path_patients_list_dce, path_patients_list_gt): # Read the DCE dce_mod = DCEModality() dce_mod.read_data_from_path(pat_dce) # Read the GT gt_mod = GTModality() gt_mod.read_data_from_path(label_gt, pat_gt) # Fit the model dce_norm.partial_fit_model(dce_mod, ground_truth=gt_mod, cat=label_gt[0]) # Define the path where to store the model path_store_model = '/data/prostate/pre-processing/lemaitre-2016-nov/model' filename_model = os.path.join(path_store_model, 'model_stn.npy') # Save the model dce_norm.save_model(filename_model)