Skip to content

Add Optuna-weighted SSIM loss and align validation selection#32

Open
MattsonCam wants to merge 13 commits into
ssim_aux_lossfrom
review_ssim_aux_loss
Open

Add Optuna-weighted SSIM loss and align validation selection#32
MattsonCam wants to merge 13 commits into
ssim_aux_lossfrom
review_ssim_aux_loss

Conversation

@MattsonCam

Copy link
Copy Markdown
Member

Adds a mixed L1 plus auxiliary SSIM training objective, with the SSIM contribution tuned per trial by Optuna. The branch also logs batch-level L1, SSIM, and total losses during training, and aligns validation-based checkpoint selection and patience tracking with the same z-score-space total loss used for optimization, while keeping the existing denormalized image-quality metrics unchanged.

@MattsonCam
MattsonCam requested a review from wli51 July 15, 2026 19:12
Cameron Mattson added 7 commits July 15, 2026 16:05
Run ID:5cbf036ef8284509850ab17794c3271a
Run Name:amusing-fly-350

Optimization of a DAPI-to-Gold image-to-image translation model with:
**Note**: This run may have included uncentered cached crops once transformed

- ConvNeXtUNet Generator
- Single 2D crop input and single 2D crop target
- Cache-backed filtered nucleus crops generated from the configured data directory
- Train-split z-score normalization for inputs and targets
- L1 plus Optuna-weighted SSIM optimization objective in z-score space with denormalized L2, PSNR, SSIM, and Pearson correlation metric logging
- Resampling of dataset w/o anti-aliasing -> dtype clipping (to stay within the correct range) -> z-score normalization
- Means and stds from the training set were stored for z-scoring of the validation set
- No final activation function after the model output (such as sigmoid)
Experiment ID:3
Run ID:fcb64e1219794669a6ee40f27e88dea9
Run Name:wistful-kite-582

- ConvNeXtUNet Generator
- Single 2D crop input and single 2D crop target
- Cache-backed filtered nucleus crops generated from the configured data directory
- Train-split z-score normalization for inputs and targets
- L1 plus Optuna-weighted SSIM optimization objective in z-score space with denormalized L2, PSNR, SSIM, and Pearson correlation metric logging
- Resampling of dataset w/o anti-aliasing -> dtype clipping (to stay within the correct range) -> z-score normalization
- Means and stds from the training set were stored for z-scoring of the validation set
- No final activation function after the model output (such as sigmoid)
- Effectively removed patience

@wli51 wli51 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Several nitpicks

Comment thread losses/l1_ssim.py
raise ValueError("The generated predictions and targets must be the same shape.")


def resolve_ssim_data_range(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be unecessary as the torchmetrics.functional.image.structural_similarity_index_measure be default does the same min max operation on incoming data if data_range is set as None

Comment thread losses/l1_ssim.py
from typing import Optional

import torch
from torchmetrics.functional.image import structural_similarity_index_measure

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the functional API may not be the most efficient to use as training objectives, consider switching to torchmetrics.image.StructuralSimilarityIndexMeasure

Comment thread losses/l1_ssim.py
def compute_l1_ssim_mean_components(
generated_predictions: torch.Tensor,
targets: torch.Tensor,
ssim_weight: float,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking, might want to add guard rails to prevent this term from being negative so that the negative applied on SSIM cannot be undone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants