[tests] - fix CuPy display in test_learn_encoded_labels; enable model.load in test_linear
test_learn_encoded_labels: add .get() for cupy→numpy conversion before imshow; reduce num_epochs 10000→1000. test_linear: uncomment model.load() to resume from saved weights. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ from rbm.matrix import Mat, np
|
|||||||
class LabelLearner(Model):
|
class LabelLearner(Model):
|
||||||
def __init__(self, name: str, dim, work_dir: str = '.'):
|
def __init__(self, name: str, dim, work_dir: str = '.'):
|
||||||
super().__init__(name, work_dir)
|
super().__init__(name, work_dir)
|
||||||
self.unit1 = Entity(dim, EntityParams(do_gaussian_hidden=False), TrainingParams(learning_rate=0.01, momentum=0.9, do_rao_blackwell=True, num_epochs=10000))
|
self.unit1 = Entity(dim, EntityParams(do_gaussian_hidden=False), TrainingParams(learning_rate=0.01, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
|
||||||
|
|
||||||
def forward(self, x: Mat):
|
def forward(self, x: Mat):
|
||||||
x = self.unit1.forward(x)
|
x = self.unit1.forward(x)
|
||||||
@@ -66,13 +66,13 @@ if __name__ == "__main__":
|
|||||||
recon = model.backward(hidden)
|
recon = model.backward(hidden)
|
||||||
img_hidden = np.reshape(hidden, (4, 4))
|
img_hidden = np.reshape(hidden, (4, 4))
|
||||||
img_recon = np.reshape(recon, (label_w, label_h))
|
img_recon = np.reshape(recon, (label_w, label_h))
|
||||||
axes[0][index].imshow(img_hidden, cmap=cmap)
|
axes[0][index].imshow(img_hidden.get(), cmap=cmap)
|
||||||
axes[0][index].axis('off')
|
axes[0][index].axis('off')
|
||||||
axes[0][index].set_title(f'{test_labels[index]}')
|
axes[0][index].set_title(f'{test_labels[index]}')
|
||||||
axes[1][index].imshow(img_recon, cmap=cmap)
|
axes[1][index].imshow(img_recon.get(), cmap=cmap)
|
||||||
axes[1][index].axis('off')
|
axes[1][index].axis('off')
|
||||||
axes[1][index].set_title(f'{test_labels[index]}')
|
axes[1][index].set_title(f'{test_labels[index]}')
|
||||||
axes[2][index].imshow(np.reshape(inp, (label_w, label_h)), cmap=cmap)
|
axes[2][index].imshow(np.reshape(inp.get(), (label_w, label_h)), cmap=cmap)
|
||||||
axes[2][index].axis('off')
|
axes[2][index].axis('off')
|
||||||
axes[2][index].set_title(f'{test_labels[index]}')
|
axes[2][index].set_title(f'{test_labels[index]}')
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def linear():
|
|||||||
model.init(0.1)
|
model.init(0.1)
|
||||||
|
|
||||||
# Load weights (if exists)
|
# Load weights (if exists)
|
||||||
# model.load()
|
model.load()
|
||||||
|
|
||||||
# Prepare training data
|
# Prepare training data
|
||||||
training_batch = np.random.randn(N_CASES, N_VIS, dtype=np.float64)
|
training_batch = np.random.randn(N_CASES, N_VIS, dtype=np.float64)
|
||||||
|
|||||||
Reference in New Issue
Block a user