- state load/save revised
- num gibbs samples is also part of entity - working 3-layer deep test model
This commit is contained in:
+7
-7
@@ -5,13 +5,13 @@ from .entity import Entity
|
||||
from .train import train, TrainingParams, cd_jens
|
||||
from .matrix import Mat, np
|
||||
from .status import Status
|
||||
from .state import RbmState
|
||||
|
||||
class Model(ABC):
|
||||
known_classes = [Entity]
|
||||
def __init__(self, name: str = "myStack", work_dir: str = "."):
|
||||
self.name = name
|
||||
self.work_dir = work_dir
|
||||
os.makedirs(self.work_dir, exist_ok=True)
|
||||
|
||||
def objects(self, obj_type: type = Entity) -> list[Entity]:
|
||||
obj_list: list[type[obj_type]] = []
|
||||
@@ -24,7 +24,7 @@ class Model(ABC):
|
||||
_batch = np.copy(batch)
|
||||
for entity in self.objects(Entity):
|
||||
train(entity, _batch, params, Status(), cd_jens)
|
||||
_batch = entity(_batch)
|
||||
_batch = entity.forward(_batch, num_gibbs=params.num_gibbs_samples)
|
||||
|
||||
@abstractmethod
|
||||
def forward(self, x: Mat) -> Mat:
|
||||
@@ -33,13 +33,13 @@ class Model(ABC):
|
||||
def save(self):
|
||||
for index, entity in enumerate(self.objects(Entity)):
|
||||
filepath = os.path.join(self.work_dir, f"{self.name}-{index}-state.npz")
|
||||
entity.state.to_file(filepath)
|
||||
entity.state.save(filepath)
|
||||
|
||||
def load(self):
|
||||
for index, entity in enumerate(self.objects(Entity)):
|
||||
filepath = os.path.join(self.work_dir, f"{self.name}-{index}-state.npz")
|
||||
state = RbmState.from_file(filepath)
|
||||
if state is not None:
|
||||
entity.state = state
|
||||
|
||||
entity.state.load(filepath)
|
||||
|
||||
def init(self, std: float):
|
||||
for index, entity in enumerate(self.objects(Entity)):
|
||||
entity.state.init(std=std)
|
||||
|
||||
Reference in New Issue
Block a user