Skip to content

Commit eb2ed28

Browse files
committed
BaseModelConfigs now also serializes class variables and not just instance variables to ensure proper restoration.
1 parent 6d5b14a commit eb2ed28

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Tutorials/05_sound_to_text/configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from mltu.configs import BaseModelConfigs
55

6+
67
class ModelConfigs(BaseModelConfigs):
78
def __init__(self):
89
super().__init__()

mltu/configs.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import os
22
import yaml
33

4+
45
class BaseModelConfigs:
56
def __init__(self):
67
self.model_path = None
78

89
def serialize(self):
9-
# get object attributes
10-
return self.__dict__
10+
class_attributes = {key: value
11+
for (key, value)
12+
in type(self).__dict__.items()
13+
if key not in ['__module__', '__init__', '__doc__', '__annotations__']}
14+
instance_attributes = self.__dict__
15+
16+
# first init with class attributes then apply instance attributes, overwriting any existing duplicate attributes
17+
all_attributes = class_attributes.copy()
18+
all_attributes.update(instance_attributes)
19+
20+
return all_attributes
1121

12-
def save(self, name: str="configs.yaml"):
22+
def save(self, name: str = "configs.yaml"):
1323
if self.model_path is None:
1424
raise Exception("Model path is not specified")
1525

0 commit comments

Comments
 (0)