added model
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from sympy.codegen.ast import float64
|
||||
|
||||
from rbm.model import Model
|
||||
from rbm.entity import Entity, EntityParams
|
||||
from rbm.matrix import Mat, np
|
||||
from rbm.train import TrainingParams
|
||||
|
||||
class DeepStack(Model):
|
||||
def __init__(self, name: str = "myStack"):
|
||||
super().__init__(name)
|
||||
self.unit1 = Entity((32*32*3, 256), EntityParams(do_gaussian_visible=True))
|
||||
# self.unit2 = Entity((16, 24), EntityParams())
|
||||
# self.unit3 = Entity((24, 10), EntityParams())
|
||||
|
||||
def forward(self, x: Mat):
|
||||
x = self.unit1(x)
|
||||
# x = self.unit2(x)
|
||||
# x = self.unit3(x)
|
||||
return x
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create model
|
||||
model = DeepStack("myStack")
|
||||
|
||||
# load state
|
||||
model.load()
|
||||
|
||||
# create batch
|
||||
batch = (np.random.rand(16, 32*32*3) > 0.5).astype(np.float64)
|
||||
|
||||
# Train
|
||||
model.train(batch, TrainingParams(learning_rate=0.1, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
|
||||
|
||||
# save state
|
||||
model.save()
|
||||
|
||||
for pat in batch:
|
||||
model.forward(pat)
|
||||
|
||||
Reference in New Issue
Block a user