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
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()
def test_compile(self): preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X, PATH_READ_y, DIR_EDA)
def test_normalize(self): preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X, PATH_READ_y, DIR_EDA) preprocessor.run(normalize=True)
def test_one_hot_encoding(self): preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X, PATH_READ_y, DIR_EDA) preprocessor.run(hot_encode=True)
def test_run(self): preprocessor = Preprocessor(COLS_NUM, ["merchantZip"], PATH_READ_X, PATH_READ_y, DIR_EDA) preprocessor.run(hot_encode=False, normalize=False)
"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