示例#1
0
def prepare_patient_images(patient_id, intermediate_crop=0):
    file_lst = []
    prefix = str(patient_id).rjust(4, '0')
    src_files = helpers.get_files(settings.BASE_PREPROCESSEDIMAGES_DIR, prefix + "*.png")

    patient_dir = helpers.get_pred_patient_dir(patient_id)
    helpers.create_dir_if_not_exists(patient_dir)
    patient_img_dir = helpers.get_pred_patient_img_dir(patient_id)
    helpers.create_dir_if_not_exists(patient_img_dir)
    helpers.delete_files(patient_img_dir, "*.png")

    dummy = numpy.zeros((settings.TARGET_SIZE, settings.TARGET_SIZE))
    cv2.imwrite(patient_img_dir + "dummy_overlay.png", dummy)

    for src_path in src_files:
        file_name = ntpath.basename(src_path)
        org_img = cv2.imread(src_path, cv2.IMREAD_GRAYSCALE)
        cropped_img = helpers.prepare_cropped_sax_image(org_img, clahe=True, intermediate_crop=intermediate_crop, rotate=0)
        if SCALE_SIZE is not None:
            cropped_img = cv2.resize(cropped_img, (SCALE_SIZE, SCALE_SIZE), interpolation=cv2.INTER_AREA)

        cv2.imwrite(patient_img_dir + file_name, cropped_img)
        file_lst.append([file_name, "dummy_overlay.png"])

    with open(patient_img_dir + "pred.lst", "wb") as f:
        writer = csv.writer(f, delimiter='\t')
        writer.writerows(file_lst)
        dia_line = [str(patient_id) + "_Diastole"] + map(str, pred_row_dia)
        sys_line = [str(patient_id) + "_Systole"] + map(str, pred_row_sys)
        #sys_line = "501_Systole" ",".join(map(str,pred_row_sys))
        pred_lines.append(dia_line)
        pred_lines.append(sys_line)

    crps_dia = sum(agg_crps_dia) / len(agg_crps_dia)
    crps_sys = sum(agg_crps_sys) / len(agg_crps_sys)

    print "Crps dia = " + str(crps_dia)
    print "Crps sys = " + str(crps_sys)
    print "Crps agg = " + str((crps_dia + crps_sys) / 2)

    if submission_file != "":
        with open(submission_file, "wb") as f:
            writer = csv.writer(f)
            writer.writerows(pred_lines)


if __name__ == "__main__":
    helpers.create_dir_if_not_exists(settings.BASE_DIR + "submission_files\\")
    stdevs = generate_stdevs(1, 590, 600, 700, window_size=60)  # patient 595 and 599 are corrupt
    make_predictions(PREDICT_FILE_PATH, 1, 500, stdevs)
    make_predictions(PREDICT_FILE_PATH, 501, 700, stdevs)
    make_predictions(PREDICT_FILE_PATH, 1, 700, stdevs)
    make_predictions(PREDICT_FILE_PATH, 701, 1140, stdevs, submission_file=settings.BASE_DIR + "submission_files\\submission" + MODEL_NAME + ".csv")
    print "Done , submission written to : " + settings.BASE_DIR + "submission_files\\submission" + MODEL_NAME + ".csv"
    # make_predictions("G:\\werkdata\\kaggle\\ndsb2\\prediction_data_allscale.csv", 250, 700)

示例#3
0
    crps_dia = sum(agg_crps_dia) / len(agg_crps_dia)
    crps_sys = sum(agg_crps_sys) / len(agg_crps_sys)

    print("Crps dia = " + str(crps_dia))
    print("Crps sys = " + str(crps_sys))
    print("Crps agg = " + str((crps_dia + crps_sys) / 2))

    if submission_file != "":
        with open(submission_file, "wb") as f:
            writer = csv.writer(f)
            writer.writerows(pred_lines)


if __name__ == "__main__":
    helpers.create_dir_if_not_exists(settings.BASE_DIR + "submission_files\\")
    stdevs = generate_stdevs(1, 590, 600, 700,
                             window_size=60)  # patient 595 and 599 are corrupt
    make_predictions(PREDICT_FILE_PATH, 1, 500, stdevs)
    make_predictions(PREDICT_FILE_PATH, 501, 700, stdevs)
    make_predictions(PREDICT_FILE_PATH, 1, 700, stdevs)
    make_predictions(PREDICT_FILE_PATH,
                     701,
                     1140,
                     stdevs,
                     submission_file=settings.BASE_DIR +
                     "submission_files\\submission" + MODEL_NAME + ".csv")
    print("Done , submission written to : " + settings.BASE_DIR +
          "submission_files\\submission" + MODEL_NAME + ".csv")
    # make_predictions("G:\\werkdata\\kaggle\\ndsb2\\prediction_data_allscale.csv", 250, 700)