Skip to content

Commit

Permalink
Add custom unpickler to fix issue with missing module
Browse files Browse the repository at this point in the history
  • Loading branch information
ncguilbeault committed Jan 20, 2025
1 parent 4d86dd9 commit 5fa19f4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Bonsai.ML.HiddenMarkovModels/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

npr.seed(0)

class CustomUnpickler(pickle.Unpickler):
def find_class(self, module, name):
if module == 'main' and name == 'HiddenMarkovModel':
return HiddenMarkovModel
return super().find_class(module, name)

class HiddenMarkovModel(HMM):

Expand Down Expand Up @@ -158,7 +163,7 @@ def save_model(self, path: str):
@classmethod
def load_model(cls, path: str):
with open(path, 'rb') as f:
return pickle.load(f)
return CustomUnpickler(f).load()

def fit_async(self,
observation: list[float],
Expand Down

0 comments on commit 5fa19f4

Please sign in to comment.