Skip to content

Commit

Permalink
Merge pull request #31 from MortenTabaka/Experiment_with_SuperPixels_…
Browse files Browse the repository at this point in the history
…and_update_README

Experiment with super pixels and slightly improve output folder structure
  • Loading branch information
MortenTabaka committed May 7, 2023
2 parents 3cdf429 + beab3e0 commit b8556aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion models/scripts/run_prediction_on_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main(
50, min=0, help="Will be multiplied by number of borders in single strip"
),
border_compactness: float = typer.Option(10, min=0),
border_sp_thresh: float = typer.Option(0.3, min=0, max=1),
border_sp_thresh: float = typer.Option(0.5, min=0, max=1),
border_sp_class_balance: bool = typer.Option(False),
border_sp_pixel_range: int = typer.Option(
50,
Expand Down
52 changes: 39 additions & 13 deletions src/pipelines/prediction_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import tensorflow as tf
from cv2 import addWeighted, imread, imwrite
from datetime import datetime
from tensorflow.compat.v1 import ConfigProto, InteractiveSession
from tensorflow_addons.image import blend
from tqdm import tqdm
Expand Down Expand Up @@ -96,19 +97,36 @@ def __init__(
self.border_sp_class_balance = border_sp_class_balance
self.border_sp_pixel_range = border_sp_pixel_range

current_datetime = datetime.now().strftime("%Y-%m-%d--%H:%M:%S")
self.output_folder_image_mask_overlays = (
self.output_folder / "prediction_image_mask_overlays"
self.output_folder
/ model_revision
/ current_datetime
/ "overlays_mask_image"
)
self.output_folder_image_mask_overlays_with_marked_SP = (
self.output_folder
/ "prediction_image_mask_overlays_with_marked_SuperPixels"
/ model_revision
/ current_datetime
/ "overlays_mask_image_with_marked_SuperPixels"
)
self.output_folder_prediction_masks = (
self.output_folder
/ model_revision
/ current_datetime
/ "prediction_masks_no_borders_post_processed"
)
self.output_folder_prediction_masks = self.output_folder / "prediction_masks"
self.output_folder_superpixels_prediction_masks = (
self.output_folder / "prediction_masks_SuperPixels_postprocessing"
self.output_folder
/ model_revision
/ current_datetime
/ "prediction_masks_borders_post_processed"
)
self.output_folder_raw_image_marked_borders = (
self.output_folder / "raw_images_marked_borders"
self.output_folder
/ model_revision
/ current_datetime
/ "images_marked_borders_SuperPixels"
)
os.makedirs(self.output_folder_image_mask_overlays, exist_ok=True)
os.makedirs(
Expand Down Expand Up @@ -174,17 +192,25 @@ def __postprocess_tiles_boundaries_in_concatenated_image(self):
DataMode.NUMPY_TENSOR,
).concatenate_all_tiles()

all_input_images = self.__get_full_size_raw_images
all_numpy_tensors = sorted(
glob(path.join(self.output_folder_superpixels_prediction_masks, "*.npy"))
)
all_numpy_tensors = [
item
for item in all_numpy_tensors
if any(
f"{os.path.splitext(os.path.basename(filepath))[0]}.npy" in item
for filepath in all_input_images
)
]

for raw_image_filepath, raw_mask_filepath in zip(
self.__get_full_size_raw_images,
sorted(
glob(
path.join(self.output_folder_superpixels_prediction_masks, "*.npy")
)
),
all_input_images, all_numpy_tensors
):
raw_image = imread(raw_image_filepath)
raw_mask = np.load(raw_mask_filepath)
base_name = os.path.basename(raw_image_filepath)
base_name = os.path.splitext(os.path.basename(raw_image_filepath))[0]
(
raw_processed_mask,
raw_image_with_boundaries,
Expand Down Expand Up @@ -218,7 +244,7 @@ def __postprocess_tiles_boundaries_in_concatenated_image(self):
imwrite(
os.path.join(
self.output_folder_image_mask_overlays_with_marked_SP,
f"{filename}.tiff",
f"{filename}.jpg",
),
blended_img_with_marked_borders,
)
Expand Down

0 comments on commit b8556aa

Please sign in to comment.