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

Add the option to exclude raw data from the saved model #1126

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion umap/parametric_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def __getstate__(self):
and k not in ("optimizer", "encoder", "decoder", "parametric_model")
)

def save(self, save_location, verbose=True):
def save(self, save_location, verbose=True, exclude_raw_data=False):

# save encoder
if self.encoder is not None:
Expand All @@ -486,6 +486,18 @@ def save(self, save_location, verbose=True):
if verbose:
print("Keras full model saved to {}".format(parametric_model_output))

# Temporarily delete the raw data in the object, before saving it,
# backing it up in raw_data
raw_data = {}
if exclude_raw_data:
if hasattr(self, "_raw_data"):
raw_data['root'] = self._raw_data
del self._raw_data
if hasattr(self, "knn_search_index") and hasattr(self.knn_search_index,
"_raw_data"):
raw_data['knn'] = self.knn_search_index._raw_data
del self.knn_search_index._raw_data

# # save model.pkl (ignoring unpickleable warnings)
with catch_warnings():
filterwarnings("ignore")
Expand All @@ -495,6 +507,13 @@ def save(self, save_location, verbose=True):
if verbose:
print("Pickle of ParametricUMAP model saved to {}".format(model_output))

# Restore the original raw data to the object in memory
if exclude_raw_data:
if 'root' in raw_data:
self._raw_data = raw_data['root']
if 'knn' in raw_data:
self.knn_search_index._raw_data = raw_data['knn']

def add_landmarks(
self,
X,
Expand Down
Loading