def test_save_load_model():
    """Test the routine to store and load 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])

    # Store the file
    filename = os.path.join(currdir, 'data', 'model.npy')
    stn.save_model(filename)

    # Load the model in another object
    stn2 = StandardTimeNormalization(dce_mod)
    stn2.load_model(filename)

    # Check the different variable
    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_)
Ejemplo n.º 2
0
                   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)