Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables legacy unets to run #1042

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions topostats/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from topostats.logs.logs import LOGGER_NAME
from topostats.thresholds import threshold
from topostats.unet_masking import (
iou_loss,
make_bounding_box_square,
mean_iou,
pad_bounding_box,
predict_unet,
)
Expand Down Expand Up @@ -658,11 +660,13 @@ def improve_grain_segmentation_unet(
# I haven't tested it yet.

try:
unet_model = keras.models.load_model(unet_config["model_path"], compile=False)
unet_model = keras.models.load_model(
unet_config["model_path"], custom_objects={"mean_iou": mean_iou, "iou_loss": iou_loss}, compile=False
)
except Exception as e:
LOGGER.info(f"Python executable: {sys.executable}")
LOGGER.info(f"Keras version: {keras.__version__}")
LOGGER.info(f"Model path: {unet_config['model_path']}")
LOGGER.debug(f"Python executable: {sys.executable}")
LOGGER.debug(f"Keras version: {keras.__version__}")
LOGGER.debug(f"Model path: {unet_config['model_path']}")
raise e

# unet_model = keras.models.load_model(unet_config["model_path"], custom_objects={"mean_iou": mean_iou})
Expand Down
1 change: 0 additions & 1 deletion topostats/unet_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# pylint: disable=too-many-locals


# DICE Loss
def dice_loss(y_true: npt.NDArray[np.float32], y_pred: npt.NDArray[np.float32], smooth: float = 1e-5) -> tf.Tensor:
"""
DICE loss function.
Expand Down
Loading