예제 #1
0
def evaluate_uats(model_dir, model_name, val_x, val_y, mc=False):
    csvName = model_dir + model_name + '.csv'

    if mc:
        from dataset_specific.prostate.model.uats_mc_dropout import weighted_model
        wm = weighted_model()
        model = wm.build_model(trained_model=model_dir + model_name)[0]
        model.load_weights(model_dir + model_name)
        prediction_arr = predict_for_uats_mc(val_x, val_y, model, mc=True)

    else:
        from dataset_specific.prostate.model.uats_scaled import weighted_model
        wm = weighted_model()
        model = wm.build_model(trained_model=model_dir + model_name, temp=1.0)
        model.load_weights(model_dir + model_name)
        prediction_arr = predict_for_uats_mc(val_x, val_y, model, mc=False)

    postprocesAndEvaluateFiles(model_dir, prediction_arr, val_y, eval=True, csvName=csvName,
                               prediction_arr_exists=False, model_name=model_name)
예제 #2
0
def evaluate_supervised(model_dir, model_name, val_x, val_y, eval=True):
    csvName = model_dir + model_name + '.csv'

    from dataset_specific.prostate.model.baseline import weighted_model
    wm = weighted_model()
    model = wm.build_model()
    model.load_weights(model_dir + model_name + '.h5')
    out = model.predict(val_x, batch_size=1, verbose=1)
    output_arr = np.zeros((out[0].shape[0], 32, 168, 168, 5))
    output_arr[:, :, :, :, 0] = out[0]
    output_arr[:, :, :, :, 1] = out[1]
    output_arr[:, :, :, :, 2] = out[2]
    output_arr[:, :, :, :, 3] = out[3]
    output_arr[:, :, :, :, 4] = out[4]
    print(output_arr.shape)
    return postprocesAndEvaluateFiles(model_dir, output_arr, val_y, eval=eval, csvName=csvName,
                               prediction_arr_exists=False, model_name=model_name)
예제 #3
0
def generate_predictions(model_dir, model_name, ul_imgs):
    csvName = model_dir + model_name + '.csv'
    from dataset_specific.prostate.model.baseline import weighted_model
    wm = weighted_model()
    model = wm.build_model()
    model.load_weights(os.path.join(model_dir , model_name + '.h5'))
    out = model.predict(ul_imgs, batch_size=1, verbose=1)
    output_arr = np.zeros((out[0].shape[0], 32, 168, 168, 5))
    output_arr[:, :, :, :, 0] = out[0]
    output_arr[:, :, :, :, 1] = out[1]
    output_arr[:, :, :, :, 2] = out[2]
    output_arr[:, :, :, :, 3] = out[3]
    output_arr[:, :, :, :, 4] = out[4]
    print(output_arr.shape)

    return postprocesAndEvaluateFiles(model_dir, output_arr, None, eval=False, csvName=csvName, prediction_arr_exists=False,
                               model_name=model_name)
예제 #4
0
                    type=float,
                    default=1.0,
                    help='Percentage of labelled data used')  #0.1 0.25 0.5 1.0
parser.add_argument('-d',
                    '--ds',
                    type=str,
                    default=PROSTATE_DATASET_NAME,
                    help='dataset name')

config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
config.allow_soft_placement = True
args = parser.parse_args()
try:
    gpu_num = args.gpu_num
    fold_num = args.fold_num
    perc = args.perc
    os.environ["CUDA_VISIBLE_DEVICES"] = gpu_num
    metadata = get_metadata(args.ds)
    # Build Model
    wm = weighted_model()
    train(None,
          None,
          dataset_name=args.ds,
          labelled_perc=perc,
          fold_num=fold_num,
          model_type=wm)

finally:
    print('clean up done!')
예제 #5
0
import dataset_specific.prostate.model.uats_scaled as uats
import dataset_specific.prostate.model.baseline as sup
from old.utils.preprocess_images import get_complete_array
import nrrd
import itk
import math

#MODEL_NAME = '/data/suhita/experiments/model/uats/prostate/uats_softmax_F2_Perct_Labelled_1.0.h5'
MODEL_NAME = '/data/suhita/experiments/model/supervised/prostate/supervised_F2_P0.5.h5'
VAL_IMGS_PATH = '/cache/suhita/data/prostate/final_test_array_imgs.npy'
VAL_GT_PATH = '/cache/suhita/data/prostate/final_test_array_GT.npy'

os.environ["CUDA_VISIBLE_DEVICES"] = '0'

w = sup.weighted_model()
#w= uats.weighted_model()
model = w.build_model(trained_model=MODEL_NAME)
print('load_weights')
val_x_arr = np.load(VAL_IMGS_PATH)
val_y_arr = np.load(VAL_GT_PATH)

val_supervised_flag = np.ones((val_x_arr.shape[0], 32, 168, 168), dtype='int8')

pz = val_y_arr[:, :, :, :, 0]
cz = val_y_arr[:, :, :, :, 1]
us = val_y_arr[:, :, :, :, 2]
afs = val_y_arr[:, :, :, :, 3]
bg = val_y_arr[:, :, :, :, 4]

y_val = [pz, cz, us, afs, bg]