From cbd44ba3d7be64fdfdfaaacecd4b3b46928098d9 Mon Sep 17 00:00:00 2001 From: Ashley Scillitoe Date: Wed, 25 Jan 2023 14:38:52 +0000 Subject: [PATCH 1/3] Set x_ref_preprocessed=True during legacy loading --- alibi_detect/saving/tensorflow/_loading.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/alibi_detect/saving/tensorflow/_loading.py b/alibi_detect/saving/tensorflow/_loading.py index c102b5449..4f87e8147 100644 --- a/alibi_detect/saving/tensorflow/_loading.py +++ b/alibi_detect/saving/tensorflow/_loading.py @@ -233,6 +233,10 @@ def load_detector_legacy(filepath: Union[str, os.PathLike], suffix: str, **kwarg # load outlier detector specific parameters state_dict = dill.load(open(filepath.joinpath(detector_name + suffix), 'rb')) + # Set `x_ref_preprocessed=True` if it doesn't exist in `state_dict` (old `alibi-detect` versions did not write this) + if 'kwargs' in state_dict and 'x_ref_preprocessed' not in state_dict['kwargs']: + state_dict['kwargs']['x_ref_preprocessed'] = True + # initialize detector model_dir = filepath.joinpath('model') detector: Optional[Detector] = None # to avoid mypy errors From f481681887e23d2678f584612fd59bf8ea39e167 Mon Sep 17 00:00:00 2001 From: Ashley Scillitoe Date: Wed, 25 Jan 2023 15:25:36 +0000 Subject: [PATCH 2/3] Ensure preprocess_x_ref setting is retained --- alibi_detect/saving/tensorflow/_loading.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/alibi_detect/saving/tensorflow/_loading.py b/alibi_detect/saving/tensorflow/_loading.py index 4f87e8147..213402c0c 100644 --- a/alibi_detect/saving/tensorflow/_loading.py +++ b/alibi_detect/saving/tensorflow/_loading.py @@ -233,9 +233,14 @@ def load_detector_legacy(filepath: Union[str, os.PathLike], suffix: str, **kwarg # load outlier detector specific parameters state_dict = dill.load(open(filepath.joinpath(detector_name + suffix), 'rb')) - # Set `x_ref_preprocessed=True` if it doesn't exist in `state_dict` (old `alibi-detect` versions did not write this) - if 'kwargs' in state_dict and 'x_ref_preprocessed' not in state_dict['kwargs']: - state_dict['kwargs']['x_ref_preprocessed'] = True + # Update the drift detector preprocess kwargs if state_dict is from an old alibi-detect version (=v0.10 + # Set x_ref_preprocessed to True + state_dict['kwargs']['x_ref_preprocessed'] = True + # Move `preprocess_x_ref` from `other` to `kwargs` + state_dict['kwargs']['preprocess_x_ref'] = state_dict['other']['preprocess_x_ref'] # initialize detector model_dir = filepath.joinpath('model') From 2a7b9f00c270afcd6c7c344f1c1a7cc0fe149fe7 Mon Sep 17 00:00:00 2001 From: Ashley Scillitoe Date: Wed, 25 Jan 2023 16:46:14 +0000 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6f334b1..6f4c1840e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,9 @@ [Full Changelog](https://github.com/SeldonIO/alibi-detect/compare/v0.10.4...v0.10.5) ### Fixed -- Fixed a bug preventing backward compatibility when loading detectors (containing TensorFlow models) saved with `=v0.10.0` did not properly obey the legacy file format. The `config.toml` file format used by -default in `>=v0.10.0` is not affected. +- Fixed two bugs preventing backward compatibility when loading detectors saved with `=v0.10.0` did not properly obey the legacy file format. The `config.toml` file format used by default in `>=v0.10.0` is unaffected. ## v0.10.4 ## [v0.10.4](https://github.com/SeldonIO/alibi-detect/tree/v0.10.4) (2022-10-21)