[MNT] Add missing load_model test for deep clusterers (Fixes #3080)
[MNT] Add missing load_model test for deep clusterers
Reference Issues/PRs
- Fixes #3080
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
.kerascheckpoint is saved viasave_best_model=True. - Calls
load_modelto load the saved model, including custom layers (_TensorDilationfor AEDRNN and_WeightNormalizationfor AEDCNN). - Verifies that the loaded model is valid and assigned to
model_. - Confirms that the load path added in PR #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.
- [x] The PR title starts with
[MNT], matching aeon’s conventions.
For new estimators and functions
- Not applicable.
For developers with write access
- Not applicable.
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-commitchecks for all files - [ ] Run
mypytypecheck tests - [ ] Run all
pytesttests and configurations - [ ] Run all notebook example tests
- [ ] Run numba-disabled
codecovtests - [ ] Stop automatic
pre-commitfixes (always disabled for drafts) - [ ] Disable numba cache loading
- [ ] Regenerate expected results for testing
- [ ] Push an empty commit to re-run CI checks
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.
LGTM ! thanks