Example #1
0
def evaluate(auto: bool = False):
    """Evaluation function"""
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    print("Loading images... ", end="")
    # Load images
    images = load_images(range(1, 15))
    print("OK")

    # Preprocess images
    print("Preprocessing images... ", end="")
    preprocessing_pipeline: FunctionList = [
        (Preprocessor.bilateral, {
            "times": 2
        }),
        (Preprocessor.sobel, {
            "scale": 1,
            "delta": 0
        }),
    ]
    preprocessed_images = Preprocessor.apply(preprocessing_pipeline, images)

    print("OK")

    # Calculate asms for initialization
    print("Finding initial ASMs... ", end="")
    active_shape_models, expected_image_shapes = Incisors.active_shape_models(
        preprocessed_images)
    print("OK")
    # Initialization
    print("Initializing ", end="")
    initializator: Initializator
    if auto:
        print("(auto-initialization)... ", end="")
        initializator = AutoInitializator()
    else:
        print("(manual initialization)... ", end="")
        initializator = ManualInitializator()
    initial_image_shapes = initializator.initialize(active_shape_models,
                                                    preprocessed_images)
    print("OK")

    # Create image shapes with normal images for saving
    _, printable_image_shapes = Incisors.active_shape_models(images)

    # Evaluation
    print("Evaluating...")
    evaluator = Evaluator(initial_image_shapes, expected_image_shapes,
                          printable_image_shapes)
    mean_squared_errors = evaluator.quantitative_eval()
    print(mean_squared_errors)
    evaluator.qualitative_eval()

    return
def load_incisor(
    incisor=Incisors.UPPER_OUTER_LEFT, extra_text="", blur=False, sobel=False
) -> Tuple[ActiveShapeModel, List[ImageShape]]:
    """Loads asm and imgshapes for sample incisor"""
    images = load_images(range(1, 15))
    pipeline = [(Preprocessor.bilateral, {"times": 2})]
    blurred_images = Preprocessor.apply(pipeline, images)
    if blur:
        images = blurred_images
    sobel_images = apply_sobel(images)
    if sobel:
        images = sobel_images
    asms, imgshapes = Incisors.active_shape_models(images, [incisor])
    asm: ActiveShapeModel = asms[incisor]
    imgshape: List[ImageShape] = imgshapes[incisor]
    return asm, imgshape
Example #3
0
def preprocess():
    # Load images
    print("Loading images... ", end="")
    images = load_images(range(1, 15))
    print("OK")

    # Preprocess images
    print("Preprocessing images... ", end="")
    preprocessing_pipeline: FunctionList = [
        (Preprocessor.bilateral, {
            "times": 2
        }),
        (Preprocessor.sobel, {
            "scale": 1,
            "delta": 0
        }),
    ]
    preprocessed_images = Preprocessor.apply(preprocessing_pipeline, images)

    # Plot subplots
    f, (ax1, ax2) = plt.subplots(2, 1)
    ax1.imshow(images[3], cmap="gray")
    ax2.imshow(preprocessed_images[3], cmap="gray")
    plt.show()
Example #4
0
 def test_compile(self):
     preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X,
                                 PATH_READ_y, DIR_EDA)
Example #5
0
 def test_normalize(self):
     preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X,
                                 PATH_READ_y, DIR_EDA)
     preprocessor.run(normalize=True)
Example #6
0
 def test_one_hot_encoding(self):
     preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X,
                                 PATH_READ_y, DIR_EDA)
     preprocessor.run(hot_encode=True)
Example #7
0
 def test_run(self):
     preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X,
                                 PATH_READ_y, DIR_EDA)
     preprocessor.run(hot_encode=False, normalize=False)
Example #8
0
        "model_params": {
            "n_estimators": [100, 250],
            "max_depth": [5, 10, 15]
        },
        "preprocessing_params": {
            "label_encode": True,
            "hot_encode": False,
            "normalize": True,
            "save": False
        }
    },
}

if __name__ == "__main__":
    eda_runner = EDA(COLS_NUM, PATH_READ_X, PATH_READ_y, DIR_EDA)
    preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X,
                                PATH_READ_y, DIR_EDA)
    eda_runner.run()

    # Log results
    results = {
        "accuracy": [],
        "f1": [],
        "precision": [],
        "recall": [],
        "model": []
    }
    # Iterate over different models
    for model_name, model_dict in pipeline_dict.items():
        data = preprocessor.run(**model_dict["preprocessing_params"])

        # Define X and y