def eval_model(imgarray_evaldata, params):
    for i in range(params["image_nr"]):
        pc_utilities.process_messenger("EVALUATING IMAGE " + str(i))
        pc_config.eval_img_id = i

        # generate data set
        pc_dataset.slice_image_hdf5(imgarray_image=imgarray_evaldata, imgarray_labels="none", sampletype="fullimage")

        # segment the images
        # using the model and the probability calibration function, we evaluate the classifier on a real image with unknown labels
        y_truth, y_model = run_classifier(mode="probcalibratedregression", sampletype="fullimage")
        y_model = y_model.reshape(
            (len(y_model) ** (1.0 / 2), len(y_model) ** (1.0 / 2))
        )  # return a 2d map of the image
        prob_map = y_model
        print "prob map dimension", y_model.shape
        if pc_config.save_truth:
            y_truth = y_truth.reshape(
                (len(y_truth) ** (1.0 / 2), len(y_truth) ** (1.0 / 2))
            )  # return a 2d map of the image
            prob_map = np.concatenate([y_model, y_truth])  # save result and truth next to eachother

        # save numpy
        print "saving probability map to ", pc_config.fname_segmentation_pmap_npy
        np.save(pc_config.fname_segmentation_pmap_npy, prob_map)

        # postprocess the probability map to generate json and png data
        postprocess_image(params)

        # delete hdf5 samples that are no longer needed
        pc_dataset.delete_data_hdf5()

    pc_utilities.process_messenger("EVALUATION COMPLETE.")
def train_model(imgarray_traindata, imgarray_trainlabels, params):
    # training
    pc_dataset.slice_image_hdf5(imgarray_traindata, imgarray_trainlabels, sampletype="class01equal")
    pc_utilities.process_messenger("MODEL TRAINING.")
    training_loop()

    # calibration
    pc_utilities.process_messenger("MODEL TRAINING COMPLETE. NOW PROBABILITY CALIBRATION.")
    pc_dataset.slice_image_hdf5(imgarray_traindata, imgarray_trainlabels, sampletype="random")
    train_probability_calibration()
    pc_dataset.delete_data_hdf5()
    pc_utilities.process_messenger("PROBABILITY CALIBRATION COMPLETE. CLASSIFIER IS READY.")