Skip to content

Conversation

@satwiksps
Copy link
Contributor

[MNT] Add missing load_model test for deep clusterers

Reference Issues/PRs

What does this implement/fix? Explain your changes.

This PR adds a missing unit test for the deep clustering autoencoder models (AEDRNNClusterer and AEDCNNClusterer) to ensure that the load_model functionality works as expected.

Issue #3080 identified that while deep clusterers support loading a pre-trained Keras model, this behavior was not covered by any tests. This lack of test coverage allowed a bug fixed in PR #3074 to remain undetected.

This PR introduces a new test file, test_deep_clusterer_io.py, which:

  • Trains each deep autoencoder clusterer on a tiny synthetic dataset.
  • Ensures that a .keras checkpoint is saved via save_best_model=True.
  • Calls load_model to load the saved model, including custom layers
    (_TensorDilation for AEDRNN and _WeightNormalization for AEDCNN).
  • Verifies that the loaded model is valid and assigned to model_.
  • Confirms that the load path added in PR [BUG] FIX DRNN load bug #3074 works without errors.

The test does not call predict() on the loaded estimator, because estimator state
is intentionally not restored by load_model and would correctly raise NotFittedError.
This matches the design of the deep clusterer classes.

This adds the required IO coverage to ensure regressions do not reoccur.

Does your contribution introduce a new dependency? If yes, which one?

No new dependencies are introduced.
The test is guarded by a TensorFlow soft dependency check.
It will be skipped if TensorFlow is not installed, consistent with other deep learning tests.

Any other comments?

  • The test is placed in a dedicated file (test_deep_clusterer_io.py) to keep IO-specific behavior separate from existing feature and base tests.
  • The test follows the same pattern as other deep learning tests within aeon.

PR checklist

For all contributions

  • I've added myself to the list of contributors.
  • The PR title starts with [MNT], matching aeon’s conventions.

For new estimators and functions

  • Not applicable.

For developers with write access

  • Not applicable.

@aeon-actions-bot aeon-actions-bot bot added clustering Clustering package maintenance Continuous integration, unit testing & package distribution labels Nov 16, 2025
@aeon-actions-bot
Copy link
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ maintenance ].
I have added the following labels to this PR based on the changes made: [ clustering ]. Feel free to change these if they do not properly represent the PR.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, any trivial fixes will automatically be pushed to your PR unless it is a draft.

Don't hesitate to ask questions on the aeon Slack channel if you have any.

PR CI actions

These checkboxes will add labels to enable/disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Stop automatic pre-commit fixes (always disabled for drafts)
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

Copy link
Member

@hadifawaz1999 hadifawaz1999 left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this issue. Two comments for now:

  • The test should be for all models under clustering/deep_learning
  • The test should use tempfile (see this for example)

Copy link
Member

@hadifawaz1999 hadifawaz1999 left a comment

Choose a reason for hiding this comment

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

You should be able to call predict because when "fit" is called on a deep clusterer, it creates an instance self._estimator for the clustering estimator that you can fetch after calling fit and give it to the load_model

@satwiksps
Copy link
Contributor Author

You should be able to call predict because when "fit" is called on a deep clusterer, it creates an instance self._estimator for the clustering estimator that you can fetch after calling fit and give it to the load_model

I've updated the test as suggested:

  • Now calling model.fit(X) first and retrieving model._estimator (so the test uses the actual trained estimator created during fit)
  • Passing the trained estimator to loaded.load_model(....)
  • Added a predict(X) check to ensure the restored estimator works end-to-end

All tests pass locally with TensorFlow enabled.

@hadifawaz1999
Copy link
Member

LGTM ! thanks

@hadifawaz1999 hadifawaz1999 merged commit a54d7e2 into aeon-toolkit:main Nov 23, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clustering Clustering package maintenance Continuous integration, unit testing & package distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNT] Add testing for loading/saving for deep clusterers

2 participants